use of com.google.copybara.WriterContext in project copybara by google.
the class GitHubDestinationTest method testChecker.
@Test
public void testChecker() throws Exception {
GitDestination d = skylark.eval("r", "r = git.github_destination(" + " url = 'http://github.com/example/example', \n" + " api_checker = testing.dummy_checker(),\n" + ")");
WriterContext writerContext = new WriterContext("piper_to_github", "test", false, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = d.newWriter(writerContext);
GitHubEndPoint endpoint = (GitHubEndPoint) writer.getFeedbackEndPoint(console);
EvalException e = assertThrows(EvalException.class, () -> endpoint.getCombinedStatus("bad_word"));
assertThat(e).hasMessageThat().contains("Bad word 'bad_word' found: field 'path'");
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GitHubDestinationTest method checkRefNotFound.
private void checkRefNotFound() throws IOException, RepoException, ValidationException {
addFiles(remote, primaryBranch, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "foo").buildOrThrow());
GitTesting.assertThatCheckout(remote, primaryBranch).containsFile("foo.txt", "foo").containsNoMoreFiles();
writeFile(this.workdir, "test.txt", "some content");
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);
process(writer, new DummyRevision("origin_ref1"));
GitTesting.assertThatCheckout(remote, primaryBranch).containsFile("test.txt", "some content").containsNoMoreFiles();
console.assertThat().onceInLog(MessageType.VERBOSE, "Branch other_12345 does not exist");
console.assertThat().onceInLog(MessageType.VERBOSE, "Branch other_6789 does not exist");
}
use of com.google.copybara.WriterContext 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);
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GitHubPrDestinationTest method testWrite_noContextReference.
@Test
public void testWrite_noContextReference() throws ValidationException {
WriterContext writerContext = new WriterContext("piper_to_github_pr", "TEST", false, new DummyRevision("feature", null), Glob.ALL_FILES.roots());
GitHubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'https://github.com/foo'" + ")");
ValidationException thrown = assertThrows(ValidationException.class, () -> d.newWriter(writerContext));
assertThat(thrown).hasMessageThat().contains("git.github_pr_destination is incompatible with the current origin." + " Origin has to be able to provide the contextReference or use" + " '--github-destination-pr-branch' flag");
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GitHubPrDestinationTest method testCustomTitleAndBody_withUpdate.
@Test
public void testCustomTitleAndBody_withUpdate() throws ValidationException, IOException, RepoException {
options.githubDestination.destinationPrBranch = "feature";
mockNoPullRequestsGet("feature");
gitUtil.mockApi("POST", "https://api.github.com/repos/foo/pulls", mockResponseAndValidateRequest("{\n" + " \"id\": 1,\n" + " \"number\": 12345,\n" + " \"state\": \"open\",\n" + " \"title\": \"custom title\",\n" + " \"body\": \"custom body\"" + "}", MockRequestAssertion.equals("{\"base\":\"main\"," + "\"body\":\"Body first a\"," + "\"head\":\"feature\"," + "\"title\":\"Title first a\"}")));
GitHubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'https://github.com/foo', \n" + " title = 'Title ${aaa}',\n" + " body = 'Body ${aaa}',\n" + " destination_ref = 'main',\n" + " update_description = True,\n" + ")");
WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("feature", "feature"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = d.newWriter(writerContext);
GitRepository remote = gitUtil.mockRemoteRepo("github.com/foo");
addFiles(remote, null, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "").buildOrThrow());
writeFile(this.workdir, "test.txt", "some content");
writer.write(TransformResults.of(this.workdir, new DummyRevision("one")).withLabelFinder(Functions.forMap(ImmutableMap.of("aaa", ImmutableList.of("first a", "second a")))), Glob.ALL_FILES, console);
verify(gitUtil.httpTransport(), times(1)).buildRequest("GET", getPullRequestsUrl("feature"));
verify(gitUtil.httpTransport(), times(1)).buildRequest("POST", "https://api.github.com/repos/foo/pulls");
reset(gitUtil.httpTransport());
gitUtil.mockApi("GET", getPullRequestsUrl("feature"), mockResponse("" + "[{\n" + " \"id\": 1,\n" + " \"number\": 12345,\n" + " \"state\": \"open\",\n" + " \"title\": \"test summary\",\n" + " \"body\": \"test summary\"," + " \"head\": { \"ref\": \"feature\"}," + " \"base\": { \"ref\": \"feature\"}" + "}]"));
gitUtil.mockApi("POST", "https://api.github.com/repos/foo/pulls/12345", mockResponseAndValidateRequest("{\n" + " \"id\": 1,\n" + " \"number\": 12345,\n" + " \"state\": \"open\",\n" + " \"title\": \"custom title\",\n" + " \"body\": \"custom body\"" + "}", MockRequestAssertion.equals("{\"body\":\"Body first b\"," + "\"title\":\"Title first b\"}")));
writeFile(this.workdir, "test.txt", "some other content");
writer = d.newWriter(writerContext);
writer.write(TransformResults.of(this.workdir, new DummyRevision("two")).withLabelFinder(Functions.forMap(ImmutableMap.of("aaa", ImmutableList.of("first b", "second b")))), Glob.ALL_FILES, console);
verify(gitUtil.httpTransport(), times(1)).buildRequest("GET", getPullRequestsUrl("feature"));
verify(gitUtil.httpTransport(), times(1)).buildRequest("POST", "https://api.github.com/repos/foo/pulls/12345");
}
Aggregations