use of com.google.copybara.git.github.api.CombinedStatus in project copybara by google.
the class AbstractGithubApiTest method testGetCombinedStatus.
@Test
public void testGetCombinedStatus() throws Exception {
trainMockGet("/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e", getResource("get_combined_status_testdata.json"));
CombinedStatus response = api.getCombinedStatus("octocat/Hello-World", "6dcb09b5b57875f334f61aebed695e2e4193db5e");
assertThat(response.getSha()).isEqualTo("6dcb09b5b57875f334f61aebed695e2e4193db5e");
assertThat(response.getStatuses()).hasSize(2);
assertThat(response.getState()).isEqualTo(State.SUCCESS);
assertThat(response.getTotalCount()).isEqualTo(2);
assertThat(response.getStatuses().get(0).getContext()).isEqualTo("continuous-integration/jenkins");
assertThat(response.getStatuses().get(0).getTargetUrl()).isEqualTo("https://ci.example.com/1000/output");
assertThat(response.getStatuses().get(0).getDescription()).isEqualTo("Build has completed successfully");
assertThat(response.getStatuses().get(0).getState()).isEqualTo(State.SUCCESS);
}
use of com.google.copybara.git.github.api.CombinedStatus in project copybara by google.
the class GitHubPrOrigin method checkRequiredStatusContextNames.
/**
* Check that the PR has a state of "success" for each status whose context is in the list
* provided in the `required_status_context_names` param
*/
private void checkRequiredStatusContextNames(GitHubApi api, String project, PullRequest prData) throws ValidationException, RepoException {
Set<String> requiredStatusContextNames = getRequiredStatusContextNames();
if (forceImport() || requiredStatusContextNames.isEmpty()) {
return;
}
try (ProfilerTask ignore = generalOptions.profiler().start("github_api_get_combined_status")) {
CombinedStatus combinedStatus = api.getCombinedStatus(project, prData.getHead().getSha());
Set<String> requiredButNotPresent = Sets.newHashSet(requiredStatusContextNames);
List<Status> successStatuses = combinedStatus.getStatuses().stream().filter(e -> e.getState() == State.SUCCESS).collect(Collectors.toList());
requiredButNotPresent.removeAll(Collections2.transform(successStatuses, Status::getContext));
if (!requiredButNotPresent.isEmpty()) {
throw new EmptyChangeException(String.format("Cannot migrate http://github.com/%s/pull/%d because the following ci labels " + "have not been passed: %s", project, prData.getNumber(), requiredButNotPresent));
}
}
}
use of com.google.copybara.git.github.api.CombinedStatus in project copybara by google.
the class AbstractGitHubApiTest method testGetCombinedStatus.
@Test
public void testGetCombinedStatus() throws Exception {
trainMockGet("/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e" + "/status?per_page=100", getResource("get_combined_status_testdata.json"));
CombinedStatus response = api.getCombinedStatus("octocat/Hello-World", "6dcb09b5b57875f334f61aebed695e2e4193db5e");
assertThat(response.getSha()).isEqualTo("6dcb09b5b57875f334f61aebed695e2e4193db5e");
assertThat(response.getStatuses()).hasSize(2);
assertThat(response.getState()).isEqualTo(State.SUCCESS);
assertThat(response.getTotalCount()).isEqualTo(2);
assertThat(response.getStatuses().get(0).getContext()).isEqualTo("continuous-integration/jenkins");
assertThat(response.getStatuses().get(0).getTargetUrl()).isEqualTo("https://ci.example.com/1000/output");
assertThat(response.getStatuses().get(0).getDescription()).isEqualTo("Build has completed successfully");
assertThat(response.getStatuses().get(0).getState()).isEqualTo(State.SUCCESS);
}
Aggregations