Skip to content

Commit c5e876b

Browse files
committed
Include branch information in metrics uploading.
1 parent fd3abfc commit c5e876b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 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");
@@ -34,13 +35,14 @@ public static void upload(Project project, String report) {
3435

3536
String owner = System.getenv("REPO_OWNER");
3637
String repo = System.getenv("REPO_NAME");
38+
String branch = System.getenv("PULL_BASE_REF");
3739
String baseCommit = System.getenv("PULL_BASE_SHA");
3840
String headCommit = System.getenv("PULL_PULL_SHA");
3941
String pullRequest = System.getenv("PULL_NUMBER");
4042

4143
String commit = headCommit != null && !headCommit.isEmpty() ? headCommit : baseCommit;
4244

43-
post(project, report, owner, repo, commit, baseCommit, pullRequest);
45+
post(project, report, owner, repo, commit, branch, baseCommit, pullRequest);
4446
}
4547

4648
private static void post(
@@ -49,17 +51,18 @@ private static void post(
4951
String owner,
5052
String repo,
5153
String commit,
54+
String branch,
5255
String baseCommit,
5356
String pullRequest) {
5457
String post = "-X POST";
5558
String headerAuth = "-H \"Authorization: Bearer $(gcloud auth print-identity-token)\"";
5659
String headerContentType = "-H \"Content-Type: application/json\"";
5760
String body = String.format("-d @%s", report);
5861

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);
6164
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);
6366
}
6467

6568
String request =

0 commit comments

Comments
 (0)