Search in sources :

Example 6 with GitHubApiException

use of com.google.copybara.git.github.api.GitHubApiException in project copybara by google.

the class GitHubDestinationTest method testWithGitHubApiError.

@Test
public void testWithGitHubApiError() throws Exception {
    gitUtil.mockApi("GET", "https://api.github.com/repos/foo/git/refs/heads/other_12345", mockResponseWithStatus("", 403));
    gitUtil.mockApi("GET", "https://api.github.com/repos/foo/git/refs/other_6789", mockResponseWithStatus("", 403));
    addFiles(remote, primaryBranch, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "foo").buildOrThrow());
    WriterContext writerContext = new WriterContext("piper_to_github", "test", false, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
    Writer<GitRevision> writer = destinationWithExistingPrBranch("other_${my_label}", /*deletePrBranch=*/
    "None").newWriter(writerContext);
    GitHubApiException e = assertThrows(GitHubApiException.class, () -> process(writer, new DummyRevision("origin_ref1")));
    Assert.assertSame(e.getResponseCode(), FORBIDDEN);
}
Also used : WriterContext(com.google.copybara.WriterContext) DummyRevision(com.google.copybara.testing.DummyRevision) GitHubApiException(com.google.copybara.git.github.api.GitHubApiException) Test(org.junit.Test)

Aggregations

GitHubApiException (com.google.copybara.git.github.api.GitHubApiException)6 GitHubApi (com.google.copybara.git.github.api.GitHubApi)3 ValidationException (com.google.copybara.exception.ValidationException)2 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)2 ImmutableList (com.google.common.collect.ImmutableList)1 DestinationEffect (com.google.copybara.DestinationEffect)1 DestinationRef (com.google.copybara.DestinationEffect.DestinationRef)1 WriterContext (com.google.copybara.WriterContext)1 RedundantChangeException (com.google.copybara.exception.RedundantChangeException)1 CreateStatusRequest (com.google.copybara.git.github.api.CreateStatusRequest)1 PullRequestListParams (com.google.copybara.git.github.api.GitHubApi.PullRequestListParams)1 DirectionFilter (com.google.copybara.git.github.api.GitHubApi.PullRequestListParams.DirectionFilter)1 PullRequest (com.google.copybara.git.github.api.PullRequest)1 DummyRevision (com.google.copybara.testing.DummyRevision)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1