use of com.google.copybara.git.github.api.CheckRuns in project copybara by google.
the class GitHubPrOrigin method checkRequiredCheckRuns.
/**
* Check that the PR has a conclusion of "success" for each check_run whose name is in the list
* provided in the `required_check_runs` param
*/
private void checkRequiredCheckRuns(GitHubApi api, String project, PullRequest prData) throws ValidationException, RepoException {
Set<String> requiredCheckRuns = getRequiredCheckRuns();
if (forceImport() || requiredCheckRuns.isEmpty()) {
return;
}
try (ProfilerTask ignore = generalOptions.profiler().start("github_api_get_combined_status")) {
CheckRuns checkRuns = api.getCheckRuns(project, prData.getHead().getSha());
Set<String> requiredButNotPresent = Sets.newHashSet(requiredCheckRuns);
List<CheckRun> passedCheckRuns = checkRuns.getCheckRuns().stream().filter(e -> e.getConclusion().equals("success")).collect(Collectors.toList());
requiredButNotPresent.removeAll(Collections2.transform(passedCheckRuns, CheckRun::getName));
if (!requiredButNotPresent.isEmpty()) {
throw new EmptyChangeException(String.format("Cannot migrate http://github.com/%s/pull/%d because the following check runs " + "have not been passed: %s", project, prData.getNumber(), requiredButNotPresent));
}
}
}
use of com.google.copybara.git.github.api.CheckRuns in project copybara by google.
the class AbstractGitHubApiTest method test_getCheckRuns_success.
@Test
public void test_getCheckRuns_success() throws Exception {
trainMockGet("/repos/example/project/commits/12345/check-runs", getResource("get_check_runs_testdata.json"));
CheckRuns checkRuns = api.getCheckRuns("example/project", "12345");
assertThat(checkRuns.getTotalCount()).isEqualTo(1);
assertThat(checkRuns.getCheckRuns().get(0).getStatus()).isEqualTo("completed");
assertThat(checkRuns.getCheckRuns().get(0).getConclusion()).isEqualTo("neutral");
assertThat(checkRuns.getCheckRuns().get(0).getDetailUrl()).isEqualTo("https://example.com");
assertThat(checkRuns.getCheckRuns().get(0).getApp().getId()).isEqualTo(1);
assertThat(checkRuns.getCheckRuns().get(0).getApp().getName()).isEqualTo("Octocat App");
assertThat(checkRuns.getCheckRuns().get(0).getApp().getSlug()).isEqualTo("octoapp");
}
Aggregations