Search in sources :

Example 1 with State

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));
        }
    }
}
Also used : CombinedStatus(com.google.copybara.git.github.api.CombinedStatus) Status(com.google.copybara.git.github.api.Status) GitHubUtil.asHeadRef(com.google.copybara.git.github.util.GitHubUtil.asHeadRef) Origin(com.google.copybara.Origin) CombinedStatus(com.google.copybara.git.github.api.CombinedStatus) Collections2(com.google.common.collect.Collections2) Review(com.google.copybara.git.github.api.Review) ImmutableListMultimap.toImmutableListMultimap(com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap) Matcher(java.util.regex.Matcher) Change(com.google.copybara.Change) BaselinesWithoutLabelVisitor(com.google.copybara.BaselinesWithoutLabelVisitor) CannotResolveRevisionException(com.google.copybara.exception.CannotResolveRevisionException) Endpoint(com.google.copybara.Endpoint) Splitter(com.google.common.base.Splitter) GeneralOptions(com.google.copybara.GeneralOptions) Path(java.nio.file.Path) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) User(com.google.copybara.git.github.api.User) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Collectors(java.util.stream.Collectors) Collectors.joining(java.util.stream.Collectors.joining) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) List(java.util.List) GitHubApi(com.google.copybara.git.github.api.GitHubApi) PullRequest(com.google.copybara.git.github.api.PullRequest) GitHubUtil.asMergeRef(com.google.copybara.git.github.util.GitHubUtil.asMergeRef) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) AutoValue(com.google.auto.value.AutoValue) Optional(java.util.Optional) Joiner(com.google.common.base.Joiner) AuthorAssociation(com.google.copybara.git.github.api.AuthorAssociation) Iterables(com.google.common.collect.Iterables) CheckRuns(com.google.copybara.git.github.api.CheckRuns) ValidationException.checkCondition(com.google.copybara.exception.ValidationException.checkCondition) RepoException(com.google.copybara.exception.RepoException) SubmoduleStrategy(com.google.copybara.git.GitOrigin.SubmoduleStrategy) HashSet(java.util.HashSet) GitHubUtil(com.google.copybara.git.github.util.GitHubUtil) Label(com.google.copybara.git.github.api.Label) State(com.google.copybara.git.github.api.Status.State) ImmutableList(com.google.common.collect.ImmutableList) Issue(com.google.copybara.git.github.api.Issue) Nullable(javax.annotation.Nullable) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) CharMatcher(com.google.common.base.CharMatcher) ValidationException(com.google.copybara.exception.ValidationException) ReaderImpl(com.google.copybara.git.GitOrigin.ReaderImpl) PatchTransformation(com.google.copybara.transform.patch.PatchTransformation) Console(com.google.copybara.util.console.Console) TimeUnit(java.util.concurrent.TimeUnit) Authoring(com.google.copybara.authoring.Authoring) Checker(com.google.copybara.checks.Checker) Glob(com.google.copybara.util.Glob) CheckRun(com.google.copybara.git.github.api.CheckRun) Preconditions(com.google.common.base.Preconditions) Status(com.google.copybara.git.github.api.Status) GitHubHost(com.google.copybara.git.github.util.GitHubHost) GitHubPrUrl(com.google.copybara.git.github.util.GitHubHost.GitHubPrUrl) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) CombinedStatus(com.google.copybara.git.github.api.CombinedStatus)

Aggregations

AutoValue (com.google.auto.value.AutoValue)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CharMatcher (com.google.common.base.CharMatcher)1 Joiner (com.google.common.base.Joiner)1 Preconditions (com.google.common.base.Preconditions)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Splitter (com.google.common.base.Splitter)1 Collections2 (com.google.common.collect.Collections2)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableListMultimap.toImmutableListMultimap (com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 BaselinesWithoutLabelVisitor (com.google.copybara.BaselinesWithoutLabelVisitor)1 Change (com.google.copybara.Change)1 Endpoint (com.google.copybara.Endpoint)1