Skip to content

Commit b30d5a5

Browse files
authored
Merge pull request #1071 from launchableinc/AIENG-183
[AIENG-183] optional mode to collect file content, off by default
2 parents 3e92770 + 0f3adc1 commit b30d5a5

File tree

18 files changed

+589
-149
lines changed

18 files changed

+589
-149
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ charset=utf-8
88
indent_style=space
99

1010
[*.java]
11-
indent_size = 4
11+
indent_size = 2

WORKSPACE

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ http_archive(
99
)
1010

1111
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
12+
1213
rules_jvm_external_deps()
1314

1415
load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
16+
1517
rules_jvm_external_setup()
1618

1719
load("@rules_jvm_external//:defs.bzl", "maven_install")
@@ -25,6 +27,7 @@ maven_install(
2527
"com.fasterxml.jackson.core:jackson-core:2.18.2",
2628
"com.fasterxml.jackson.core:jackson-databind:2.18.2",
2729
"com.google.guava:guava:33.3.1-jre",
30+
"org.apache.commons:commons-compress:1.27.1",
2831
"org.apache.httpcomponents:httpclient:4.5.14",
2932
# This is the last release that produce Java 8 class files.
3033
"org.eclipse.jgit:org.eclipse.jgit:5.13.3.202401111512-r",
@@ -45,10 +48,10 @@ maven_install(
4548
version = "1.4.4",
4649
),
4750
],
51+
fetch_sources = True,
4852
maven_install_json = "//src:maven_install.json",
4953
repositories = ["https://repo1.maven.org/maven2"],
5054
version_conflict_policy = "pinned",
51-
fetch_sources = True,
5255
)
5356

5457
load("@maven//:defs.bzl", "pinned_maven_install")

launchable/commands/record/commit.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i
6565

6666
# Commit messages are not collected in the default.
6767
is_collect_message = False
68+
is_collect_files = False
6869
try:
6970
res = client.request("get", "commits/collect/options")
7071
res.raise_for_status()
7172
is_collect_message = res.json().get("commitMessage", False)
73+
is_collect_files = res.json().get("files", False)
7274
except Exception as e:
7375
tracking_client.send_error_event(
7476
event_name=Tracking.ErrorEvent.INTERNAL_CLI_ERROR,
@@ -79,7 +81,7 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i
7981

8082
cwd = os.path.abspath(source)
8183
try:
82-
exec_jar(cwd, max_days, ctx.obj, is_collect_message)
84+
exec_jar(cwd, max_days, ctx.obj, is_collect_message, is_collect_files)
8385
except Exception as e:
8486
if os.getenv(REPORT_ERROR_KEY):
8587
raise e
@@ -89,7 +91,7 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i
8991
"If not, please set a directory use by --source option.\nerror: {}".format(cwd, e))
9092

9193

92-
def exec_jar(source: str, max_days: int, app: Application, is_collect_message: bool):
94+
def exec_jar(source: str, max_days: int, app: Application, is_collect_message: bool, is_collect_files: bool):
9395
java = get_java_command()
9496

9597
if not java:
@@ -120,6 +122,8 @@ def exec_jar(source: str, max_days: int, app: Application, is_collect_message: b
120122
command.append("-skip-cert-verification")
121123
if is_collect_message:
122124
command.append("-commit-message")
125+
if is_collect_files:
126+
command.append("-files")
123127
if os.getenv(COMMIT_TIMEOUT):
124128
command.append("-enable-timeout")
125129
command.append(cygpath(source))

launchable/jar/exe_deploy.jar

2.19 MB
Binary file not shown.

src/main/java/com/launchableinc/ingest/commits/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package(
2-
default_visibility = ["//visibility:public"]
2+
default_visibility = ["//visibility:public"],
33
)
44

55
java_library(
@@ -11,6 +11,7 @@ java_library(
1111
"@maven//:com_fasterxml_jackson_core_jackson_core",
1212
"@maven//:com_fasterxml_jackson_core_jackson_databind",
1313
"@maven//:com_google_guava_guava",
14+
"@maven//:org_apache_commons_commons_compress",
1415
"@maven//:org_apache_httpcomponents_httpclient",
1516
"@maven//:org_apache_httpcomponents_httpcore",
1617
"@maven//:org_eclipse_jgit_org_eclipse_jgit",
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.launchableinc.ingest.commits;
2+
3+
import org.apache.http.entity.ContentProducer;
4+
5+
import java.io.Closeable;
6+
import java.io.IOException;
7+
import java.io.OutputStream;
8+
import java.io.UncheckedIOException;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.function.Consumer;
12+
13+
/**
14+
* Accepts T, buffers them, and writes them out as a batch.
15+
*/
16+
abstract class ChunkStreamer<T> implements Consumer<T>, Closeable {
17+
/**
18+
* Encapsulation of how batches are sent.
19+
*/
20+
private final IOConsumer<ContentProducer> sender;
21+
private final int chunkSize;
22+
private final List<T> spool = new ArrayList<>();
23+
24+
ChunkStreamer(IOConsumer<ContentProducer> sender, int chunkSize) {
25+
this.sender = sender;
26+
this.chunkSize = chunkSize;
27+
}
28+
29+
@Override
30+
public void accept(T f) {
31+
spool.add(f);
32+
if (spool.size() >= chunkSize) {
33+
try {
34+
flush();
35+
} catch (IOException e) {
36+
throw new UncheckedIOException(e);
37+
}
38+
}
39+
}
40+
41+
@Override
42+
public void close() throws IOException {
43+
flush();
44+
}
45+
46+
private void flush() throws IOException {
47+
if (spool.isEmpty()) {
48+
return;
49+
}
50+
51+
try {
52+
sender.accept(os -> writeTo(spool,os));
53+
} finally {
54+
spool.clear();
55+
}
56+
}
57+
58+
protected abstract void writeTo(List<T> spool, OutputStream os) throws IOException;
59+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.launchableinc.ingest.commits;
2+
3+
import com.fasterxml.jackson.core.JsonFactory;
4+
import com.fasterxml.jackson.core.JsonGenerator;
5+
import org.apache.http.entity.ContentProducer;
6+
import org.eclipse.jgit.revwalk.RevCommit;
7+
8+
import java.io.IOException;
9+
import java.io.OutputStream;
10+
import java.util.List;
11+
import java.util.function.Consumer;
12+
13+
/**
14+
* {@link Consumer} that groups commits into chunks and write them as JSON, using streams supplied
15+
* by the factory.
16+
*/
17+
final class CommitChunkStreamer extends ChunkStreamer<JSCommit> {
18+
CommitChunkStreamer(IOConsumer<ContentProducer> sender, int chunkSize) {
19+
super(sender, chunkSize);
20+
}
21+
22+
@Override
23+
protected void writeTo(List<JSCommit> spool, OutputStream os) throws IOException {
24+
JsonGenerator w = new JsonFactory().createGenerator(os).useDefaultPrettyPrinter();
25+
w.setCodec(CommitGraphCollector.objectMapper);
26+
w.writeStartObject();
27+
w.writeArrayFieldStart("commits");
28+
29+
for (JSCommit commit : spool) {
30+
w.writeObject(commit);
31+
}
32+
33+
w.writeEndArray();
34+
w.writeEndObject();
35+
w.close();
36+
}
37+
}

0 commit comments

Comments
 (0)