Skip to content

Commit 0447dda

Browse files
authored
Merge pull request #889 from launchableinc/commit-message
Add the option to collect commit messages
2 parents a8f189f + f771161 commit 0447dda

File tree

8 files changed

+69
-7
lines changed

8 files changed

+69
-7
lines changed

launchable/commands/record/commit.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
import click
88

9+
from launchable.utils.launchable_client import LaunchableClient
10+
from launchable.utils.tracking import Tracking, TrackingClient
11+
912
from ...app import Application
1013
from ...utils.commit_ingester import upload_commits
1114
from ...utils.env_keys import REPORT_ERROR_KEY
@@ -54,8 +57,25 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i
5457
_import_git_log(import_git_log_output, ctx.obj)
5558
return
5659

60+
tracking_client = TrackingClient(Tracking.Command.COMMIT, app=ctx.obj)
61+
client = LaunchableClient(tracking_client=tracking_client, app=ctx.obj)
62+
63+
# Commit messages are not collected in the default.
64+
is_collect_message = False
65+
try:
66+
res = client.request("get", "commits/collect/options")
67+
res.raise_for_status()
68+
is_collect_message = res.json().get("commitMessage", False)
69+
except Exception as e:
70+
tracking_client.send_error_event(
71+
event_name=Tracking.ErrorEvent.INTERNAL_CLI_ERROR,
72+
stack_trace=str(e),
73+
api="commits/options",
74+
)
75+
client.print_exception_and_recover(e)
76+
5777
try:
58-
exec_jar(os.path.abspath(source), max_days, ctx.obj)
78+
exec_jar(os.path.abspath(source), max_days, ctx.obj, is_collect_message)
5979
except Exception as e:
6080
if os.getenv(REPORT_ERROR_KEY):
6181
raise e
@@ -69,7 +89,7 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i
6989
print(e)
7090

7191

72-
def exec_jar(source: str, max_days: int, app: Application):
92+
def exec_jar(source: str, max_days: int, app: Application, is_collect_message: bool):
7393
java = get_java_command()
7494

7595
if not java:
@@ -89,7 +109,7 @@ def exec_jar(source: str, max_days: int, app: Application):
89109
"{}/intake/".format(base_url),
90110
"-max-days",
91111
str(max_days),
92-
"-scrub-pii",
112+
"-scrub-pii"
93113
])
94114

95115
if Logger().logger.isEnabledFor(LOG_LEVEL_AUDIT):
@@ -98,6 +118,8 @@ def exec_jar(source: str, max_days: int, app: Application):
98118
command.append("-dry-run")
99119
if app.skip_cert_verification:
100120
command.append("-skip-cert-verification")
121+
if is_collect_message:
122+
command.append("-commit-message")
101123
command.append(cygpath(source))
102124

103125
subprocess.run(

launchable/jar/exe_deploy.jar

9.93 KB
Binary file not shown.

launchable/utils/tracking.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Command(Enum):
3232
RECORD_BUILD = 'RECORD_BUILD'
3333
RECORD_SESSION = 'RECORD_SESSION'
3434
SUBSET = 'SUBSET'
35+
COMMIT = 'COMMIT'
3536

3637

3738
class TrackingClient:

src/main/java/com/launchableinc/ingest/commits/CommitGraphCollector.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public class CommitGraphCollector {
7474

7575
private int commitsSent;
7676

77+
private boolean collectCommitMessage;
78+
7779
private int maxDays;
7880

7981
private boolean audit;
@@ -268,6 +270,10 @@ private CloseableHttpResponse handleError(URL url, CloseableHttpResponse respons
268270
return response;
269271
}
270272

273+
public void collectCommitMessage(boolean commitMessage) {
274+
this.collectCommitMessage = commitMessage;
275+
}
276+
271277
public void setMaxDays(int days) {
272278
this.maxDays = days;
273279
}
@@ -381,6 +387,7 @@ That is, find submodules that are available in the working tree (thus `!isBare()
381387
private JSCommit transform(RevCommit r) throws IOException {
382388
JSCommit c = new JSCommit();
383389
c.setCommitHash(r.name());
390+
c.setMessage(collectCommitMessage ? r.getFullMessage() : "");
384391

385392
PersonIdent author = r.getAuthorIdent();
386393
c.setAuthorEmailAddress(JSCommit.hashEmail(author.getEmailAddress()));

src/main/java/com/launchableinc/ingest/commits/CommitIngester.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ public class CommitIngester {
4747
@Option(name = "-scrub-pii", usage = "Scrub emails and names", hidden = true)
4848
public boolean scrubPii;
4949

50-
/**
51-
* @deprecated this is an old option and this is off always.
52-
*/
53-
@Deprecated
5450
@Option(name = "-commit-message", usage = "Collect commit messages")
5551
public boolean commitMessage;
5652

@@ -145,6 +141,7 @@ void run() throws CmdLineException, IOException {
145141
cgc.setMaxDays(maxDays);
146142
cgc.setAudit(audit);
147143
cgc.setDryRun(dryRun);
144+
cgc.collectCommitMessage(commitMessage);
148145
cgc.transfer(endpoint, authenticator);
149146
int numCommits = cgc.getCommitsSent();
150147
String suffix = "commit";

src/main/java/com/launchableinc/ingest/commits/JSCommit.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class JSCommit {
3131
/** Time zone offset in minutes. For example, JST is +9:00 so this field is 540. */
3232
private int committerTimezoneOffset;
3333

34+
/** Commit message. */
35+
private String message;
36+
3437
private Map<String, List<JSFileChange>> parentHashes = new HashMap<>();
3538

3639
public String getCommitHash() {
@@ -96,4 +99,12 @@ public Map<String, List<JSFileChange>> getParentHashes() {
9699
public static String hashEmail(String email) {
97100
return EMAIL_HASHER.newHasher().putString(email, StandardCharsets.UTF_8).hash().toString();
98101
}
102+
103+
public String getMessage() {
104+
return message;
105+
}
106+
107+
public void setMessage(String message) {
108+
this.message = message;
109+
}
99110
}

tests/cli_test_case.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ def setUp(self):
178178
self.workspace),
179179
json={'keys': ["GITHUB_ACTOR", "BRANCH_NAME"]},
180180
status=200)
181+
responses.add(
182+
responses.GET,
183+
"{}/intake/organizations/{}/workspaces/{}/commits/collect/options".format(
184+
get_base_url(),
185+
self.organization,
186+
self.workspace),
187+
json={'commitMessage': True},
188+
status=200)
181189

182190
def get_test_files_dir(self):
183191
file_name = Path(inspect.getfile(self.__class__)) # obtain the file of the concrete type

tests/commands/test_api_error.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ def test_record_build(self):
111111
host, port = success_server.server_address
112112
endpoint = "http://{}:{}".format(host, port)
113113
with mock.patch.dict(os.environ, {BASE_URL_KEY: endpoint}):
114+
responses.add(
115+
responses.GET,
116+
"{}/intake/organizations/{}/workspaces/{}/commits/collect/options".format(
117+
get_base_url(),
118+
self.organization,
119+
self.workspace),
120+
json={'commitMessage': True},
121+
status=200)
114122
responses.add(responses.POST, "{base}/intake/organizations/{org}/workspaces/{ws}/builds".format(
115123
base=get_base_url(), org=self.organization, ws=self.workspace), status=500)
116124
tracking = responses.add(
@@ -137,6 +145,14 @@ def test_record_build(self):
137145
endpoint = "http://{}:{}".format(host, port)
138146

139147
with mock.patch.dict(os.environ, {BASE_URL_KEY: endpoint}):
148+
responses.add(
149+
responses.GET,
150+
"{}/intake/organizations/{}/workspaces/{}/commits/collect/options".format(
151+
get_base_url(),
152+
self.organization,
153+
self.workspace),
154+
json={'commitMessage': True},
155+
status=200)
140156
responses.add(responses.POST, "{base}/intake/organizations/{org}/workspaces/{ws}/builds".format(
141157
base=get_base_url(), org=self.organization, ws=self.workspace), status=500)
142158
tracking = responses.add(

0 commit comments

Comments
 (0)