Skip to content

Commit 7cedbb4

Browse files
authored
Include branch information in metrics uploading. (#1392)
1 parent fd3abfc commit 7cedbb4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/measurement/MetricsReportUploader.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import org.gradle.api.Project;
1818

19+
// TODO(yifany): Move to fireci and reuse the metrics uploading code there.
1920
/** A helper class for uploading a metric report to the metrics service. */
2021
public class MetricsReportUploader {
2122
private static final String METRICS_SERVICE_URL = System.getenv("METRICS_SERVICE_URL");
@@ -36,11 +37,13 @@ public static void upload(Project project, String report) {
3637
String repo = System.getenv("REPO_NAME");
3738
String baseCommit = System.getenv("PULL_BASE_SHA");
3839
String headCommit = System.getenv("PULL_PULL_SHA");
40+
String baseRef = System.getenv("PULL_BASE_REF");
3941
String pullRequest = System.getenv("PULL_NUMBER");
4042

4143
String commit = headCommit != null && !headCommit.isEmpty() ? headCommit : baseCommit;
44+
String branch = pullRequest != null && !pullRequest.isEmpty() ? "" : baseRef;
4245

43-
post(project, report, owner, repo, commit, baseCommit, pullRequest);
46+
post(project, report, owner, repo, commit, branch, baseCommit, pullRequest);
4447
}
4548

4649
private static void post(
@@ -49,17 +52,18 @@ private static void post(
4952
String owner,
5053
String repo,
5154
String commit,
55+
String branch,
5256
String baseCommit,
5357
String pullRequest) {
5458
String post = "-X POST";
5559
String headerAuth = "-H \"Authorization: Bearer $(gcloud auth print-identity-token)\"";
5660
String headerContentType = "-H \"Content-Type: application/json\"";
5761
String body = String.format("-d @%s", report);
5862

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);
6165
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);
6367
}
6468

6569
String request =

0 commit comments

Comments
 (0)