16
16
17
17
import org .gradle .api .Project ;
18
18
19
+ // TODO(yifany): Move to fireci and reuse the metrics uploading code there.
19
20
/** A helper class for uploading a metric report to the metrics service. */
20
21
public class MetricsReportUploader {
21
22
private static final String METRICS_SERVICE_URL = System .getenv ("METRICS_SERVICE_URL" );
@@ -36,11 +37,13 @@ public static void upload(Project project, String report) {
36
37
String repo = System .getenv ("REPO_NAME" );
37
38
String baseCommit = System .getenv ("PULL_BASE_SHA" );
38
39
String headCommit = System .getenv ("PULL_PULL_SHA" );
40
+ String baseRef = System .getenv ("PULL_BASE_REF" );
39
41
String pullRequest = System .getenv ("PULL_NUMBER" );
40
42
41
43
String commit = headCommit != null && !headCommit .isEmpty () ? headCommit : baseCommit ;
44
+ String branch = pullRequest != null && !pullRequest .isEmpty () ? "" : baseRef ;
42
45
43
- post (project , report , owner , repo , commit , baseCommit , pullRequest );
46
+ post (project , report , owner , repo , commit , branch , baseCommit , pullRequest );
44
47
}
45
48
46
49
private static void post (
@@ -49,17 +52,18 @@ private static void post(
49
52
String owner ,
50
53
String repo ,
51
54
String commit ,
55
+ String branch ,
52
56
String baseCommit ,
53
57
String pullRequest ) {
54
58
String post = "-X POST" ;
55
59
String headerAuth = "-H \" Authorization: Bearer $(gcloud auth print-identity-token)\" " ;
56
60
String headerContentType = "-H \" Content-Type: application/json\" " ;
57
61
String body = String .format ("-d @%s" , report );
58
62
59
- String template = "%s/repos/%s/%s/commits/%s/reports" ;
60
- String endpoint = String .format (template , METRICS_SERVICE_URL , owner , repo , commit );
63
+ String template = "%s/repos/%s/%s/commits/%s/reports/?branch=%s " ;
64
+ String endpoint = String .format (template , METRICS_SERVICE_URL , owner , repo , commit , branch );
61
65
if (pullRequest != null && !pullRequest .isEmpty ()) {
62
- endpoint += String .format ("? base_commit=%s&pull_request=%s" , baseCommit , pullRequest );
66
+ endpoint += String .format ("& base_commit=%s&pull_request=%s" , baseCommit , pullRequest );
63
67
}
64
68
65
69
String request =
0 commit comments