use of com.google.copybara.git.github.api.Status.State 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));
}
}
}
Aggregations