Include branch information in metrics uploading.
@@ -16,6 +16,7 @@ package com.google.firebase.gradle.plugins.measurement;
import org.gradle.api.Project;
+// TODO(yifany): Move to fireci and reuse the metrics uploading code there.
/** A helper class for uploading a metric report to the metrics service. */
public class MetricsReportUploader {
private static final String METRICS_SERVICE_URL = System.getenv("METRICS_SERVICE_URL");
@@ -36,11 +37,13 @@ public class MetricsReportUploader {
String repo = System.getenv("REPO_NAME");
String baseCommit = System.getenv("PULL_BASE_SHA");
String headCommit = System.getenv("PULL_PULL_SHA");
+ String baseRef = System.getenv("PULL_BASE_REF");
String pullRequest = System.getenv("PULL_NUMBER");
String commit = headCommit != null && !headCommit.isEmpty() ? headCommit : baseCommit;
+ String branch = pullRequest != null && !pullRequest.isEmpty() ? "" : baseRef;
- post(project, report, owner, repo, commit, baseCommit, pullRequest);
+ post(project, report, owner, repo, commit, branch, baseCommit, pullRequest);
}
private static void post(
@@ -49,6 +52,7 @@ public class MetricsReportUploader {
String owner,
String repo,
String commit,
+ String branch,
String baseCommit,
String pullRequest) {
String post = "-X POST";
@@ -56,10 +60,10 @@ public class MetricsReportUploader {
String headerContentType = "-H \"Content-Type: application/json\"";
String body = String.format("-d @%s", report);
- String template = "%s/repos/%s/%s/commits/%s/reports";
- String endpoint = String.format(template, METRICS_SERVICE_URL, owner, repo, commit);
+ String template = "%s/repos/%s/%s/commits/%s/reports/?branch=%s";
+ String endpoint = String.format(template, METRICS_SERVICE_URL, owner, repo, commit, branch);
if (pullRequest != null && !pullRequest.isEmpty()) {
- endpoint += String.format("?base_commit=%s&pull_request=%s", baseCommit, pullRequest);
+ endpoint += String.format("&base_commit=%s&pull_request=%s", baseCommit, pullRequest);
}
String request =
