Search in sources :

Example 16 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class GitHubPrOriginTest method gitResolveRequiredStatusContextNamesFail.

@Test
public void gitResolveRequiredStatusContextNamesFail() throws Exception {
    MockPullRequest.create(gitUtil).setState("open").setPrNumber(125).addLabels("bar: yes").addCommitStatus("foo/one", "success").addCommitStatus("foo/two", "failure").mock();
    EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> checkResolve(githubPrOrigin("url = 'https://github.com/google/example'", "required_status_context_names = ['foo/one', 'foo/two']"), sha, 125));
    assertThat(thrown).hasMessageThat().contains("Cannot migrate http://github.com/google/example/pull/125 because the following ci" + " labels have not been passed: [foo/two]");
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 17 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class GitHubPrOriginTest method gitResolveRequiredCheckRunsNotFoundOpenPR.

@Test
public void gitResolveRequiredCheckRunsNotFoundOpenPR() throws Exception {
    MockPullRequest.create(gitUtil).setState("closed").setPrNumber(125).addLabels("bar: yes").mock();
    EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> checkResolve(githubPrOrigin("url = 'https://github.com/google/example'", "required_check_runs = ['foo/one', 'foo/two']"), sha, 125));
    assertThat(thrown).hasMessageThat().contains("Could not find a pr with OPEN state and head being equal to sha " + sha);
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 18 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class GitHubPrOriginTest method testGitResolveRequiredLabelsNotFound.

@Test
public void testGitResolveRequiredLabelsNotFound() throws Exception {
    MockPullRequest.create(gitUtil).setState("open").setPrNumber(125).addLabels("bar: yes").mock();
    EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> checkResolve(githubPrOrigin("url = 'https://github.com/google/example'", "required_labels = ['foo: yes', 'bar: yes']"), "125", 125));
    assertThat(thrown).hasMessageThat().contains("Cannot migrate http://github.com/google/example/pull/125 because it is missing the" + " following labels: [foo: yes]");
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 19 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class GitHubPrOriginTest method testAlreadyClosed_only_open.

@Test
public void testAlreadyClosed_only_open() throws Exception {
    MockPullRequest.create(gitUtil).setState("closed").setPrNumber(125).addLabels("foo: yes").mock();
    EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> checkResolve(githubPrOrigin("url = 'https://github.com/google/example', state = 'OPEN'"), "125", 125));
    assertThat(thrown).hasMessageThat().contains("Pull Request 125 is closed");
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 20 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class GitHubPrOriginTest method testReviewApprovers.

@Test
public void testReviewApprovers() throws Exception {
    GitRevision noReviews = checkReviewApprovers();
    assertThat(noReviews.associatedLabels()).doesNotContainKey(GitHubPrOrigin.GITHUB_PR_REVIEWER_APPROVER);
    assertThat(noReviews.associatedLabels()).doesNotContainKey(GitHubPrOrigin.GITHUB_PR_REVIEWER_OTHER);
    GitRevision any = checkReviewApprovers("review_state = 'ANY'");
    assertThat(any.associatedLabels().get(GitHubPrOrigin.GITHUB_PR_REVIEWER_APPROVER)).containsExactly("APPROVED_MEMBER", "COMMENTED_OWNER", "APPROVED_COLLABORATOR");
    assertThat(any.associatedLabels().get(GitHubPrOrigin.GITHUB_PR_REVIEWER_OTHER)).containsExactly("COMMENTED_OTHER");
    EmptyChangeException e = assertThrows(EmptyChangeException.class, () -> checkReviewApprovers("review_state = 'HEAD_COMMIT_APPROVED'", "review_approvers = [\"MEMBER\", \"OWNER\"]"));
    assertThat(e).hasMessageThat().contains("missing the required approvals");
    assertThat(e).hasMessageThat().contains("MEMBER");
    assertThat(e).hasMessageThat().contains("OWNER");
    assertThat(e).hasMessageThat().contains("User APPROVED_COLLABORATOR - Association: COLLABORATOR");
    assertThat(e).hasMessageThat().contains("User COMMENTED_OTHER - Association: NONE");
    GitRevision hasReviewers = checkReviewApprovers("review_state = 'ANY_COMMIT_APPROVED'", "review_approvers = [\"MEMBER\", \"OWNER\"]");
    assertThat(hasReviewers.associatedLabels().get(GitHubPrOrigin.GITHUB_PR_REVIEWER_APPROVER)).containsExactly("APPROVED_MEMBER", "COMMENTED_OWNER");
    assertThat(hasReviewers.associatedLabels().get(GitHubPrOrigin.GITHUB_PR_REVIEWER_OTHER)).containsExactly("COMMENTED_OTHER", "APPROVED_COLLABORATOR");
    GitRevision anyCommitApproved = checkReviewApprovers("review_state = 'HAS_REVIEWERS'", "review_approvers = [\"OWNER\"]");
    assertThat(anyCommitApproved.associatedLabels().get(GitHubPrOrigin.GITHUB_PR_REVIEWER_APPROVER)).containsExactly("COMMENTED_OWNER");
    assertThat(anyCommitApproved.associatedLabels().get(GitHubPrOrigin.GITHUB_PR_REVIEWER_OTHER)).containsExactly("APPROVED_MEMBER", "COMMENTED_OTHER", "APPROVED_COLLABORATOR");
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Aggregations

EmptyChangeException (com.google.copybara.exception.EmptyChangeException)42 Test (org.junit.Test)27 ImmutableList (com.google.common.collect.ImmutableList)10 RepoException (com.google.copybara.exception.RepoException)10 ValidationException (com.google.copybara.exception.ValidationException)10 ProfilerTask (com.google.copybara.profiler.Profiler.ProfilerTask)10 Path (java.nio.file.Path)10 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)8 Endpoint (com.google.copybara.Endpoint)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 CharMatcher (com.google.common.base.CharMatcher)5 Preconditions (com.google.common.base.Preconditions)5 Splitter (com.google.common.base.Splitter)5 Collections2 (com.google.common.collect.Collections2)5 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)5 Iterables (com.google.common.collect.Iterables)5 Sets (com.google.common.collect.Sets)5 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)5 BaselinesWithoutLabelVisitor (com.google.copybara.BaselinesWithoutLabelVisitor)5 Change (com.google.copybara.Change)5