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" );
@@ -34,13 +35,14 @@ public static void upload(Project project, String report) {
34
35
35
36
String owner = System .getenv ("REPO_OWNER" );
36
37
String repo = System .getenv ("REPO_NAME" );
38
+ String branch = System .getenv ("PULL_BASE_REF" );
37
39
String baseCommit = System .getenv ("PULL_BASE_SHA" );
38
40
String headCommit = System .getenv ("PULL_PULL_SHA" );
39
41
String pullRequest = System .getenv ("PULL_NUMBER" );
40
42
41
43
String commit = headCommit != null && !headCommit .isEmpty () ? headCommit : baseCommit ;
42
44
43
- post (project , report , owner , repo , commit , baseCommit , pullRequest );
45
+ post (project , report , owner , repo , commit , branch , baseCommit , pullRequest );
44
46
}
45
47
46
48
private static void post (
@@ -49,17 +51,18 @@ private static void post(
49
51
String owner ,
50
52
String repo ,
51
53
String commit ,
54
+ String branch ,
52
55
String baseCommit ,
53
56
String pullRequest ) {
54
57
String post = "-X POST" ;
55
58
String headerAuth = "-H \" Authorization: Bearer $(gcloud auth print-identity-token)\" " ;
56
59
String headerContentType = "-H \" Content-Type: application/json\" " ;
57
60
String body = String .format ("-d @%s" , report );
58
61
59
- String template = "%s/repos/%s/%s/commits/%s/reports" ;
60
- String endpoint = String .format (template , METRICS_SERVICE_URL , owner , repo , commit );
62
+ String template = "%s/repos/%s/%s/commits/%s/reports/?branch=%s " ;
63
+ String endpoint = String .format (template , METRICS_SERVICE_URL , owner , repo , commit , branch );
61
64
if (pullRequest != null && !pullRequest .isEmpty ()) {
62
- endpoint += String .format ("? base_commit=%s&pull_request=%s" , baseCommit , pullRequest );
65
+ endpoint += String .format ("& base_commit=%s&pull_request=%s" , baseCommit , pullRequest );
63
66
}
64
67
65
68
String request =
0 commit comments