use of com.google.copybara.WriterContext in project copybara by google.
the class GitHubPrDestinationTest method checkWrite.
private void checkWrite(Revision revision) throws ValidationException, RepoException, IOException {
mockNoPullRequestsGet("feature");
gitUtil.mockApi("POST", "https://api.github.com/repos/foo/pulls", mockResponseAndValidateRequest("{\n" + " \"id\": 1,\n" + " \"number\": 12345,\n" + " \"state\": \"open\",\n" + " \"title\": \"test summary\",\n" + " \"body\": \"test summary\"\n" + "}", MockRequestAssertion.equals("{\"base\":\"main\",\"body\":\"test summary\\n\",\"head\":\"" + "feature" + "\",\"title\":\"test summary\"}")));
GitHubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'https://github.com/foo'," + " destination_ref = 'main'" + ")");
Writer<GitRevision> writer = d.newWriter(new WriterContext("piper_to_github_pr", "TEST", false, revision, Glob.ALL_FILES.roots()));
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")), Glob.ALL_FILES, console);
writeFile(this.workdir, "test.txt", "other content");
writer.write(TransformResults.of(this.workdir, new DummyRevision("two")), Glob.ALL_FILES, console);
writeFile(this.workdir, "test.txt", "and content");
writer.write(TransformResults.of(this.workdir, new DummyRevision("three")), Glob.ALL_FILES, console);
console.assertThat().timesInLog(1, MessageType.INFO, "Pull Request https://github.com/foo/pull/12345 created using branch 'feature'.");
assertThat(remote.refExists("feature")).isTrue();
assertThat(Iterables.transform(remote.log("feature").run(), GitLogEntry::getBody)).containsExactly("first change\n", "test summary\n" + "\n" + "DummyOrigin-RevId: one\n", "test summary\n" + "\n" + "DummyOrigin-RevId: two\n", "test summary\n" + "\n" + "DummyOrigin-RevId: three\n");
// If we don't keep writer state (same as a new migration). We do a rebase of
// all the changes.
writer = d.newWriter(new WriterContext("piper_to_github_pr", "TEST", false, revision, Glob.ALL_FILES.roots()));
writeFile(this.workdir, "test.txt", "and content");
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\"}" + "}]"));
writer.write(TransformResults.of(this.workdir, new DummyRevision("four")), Glob.ALL_FILES, console);
assertThat(Iterables.transform(remote.log("feature").run(), GitLogEntry::getBody)).containsExactly("first change\n", "test summary\n" + "\n" + "DummyOrigin-RevId: four\n");
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GitHubPrDestinationTest method testCustomTitleAndBody.
@Test
public void testCustomTitleAndBody() 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\":\"custom body\"," + "\"head\":\"feature\"," + "\"title\":\"custom title\"}")));
GitHubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'https://github.com/foo', \n" + " title = 'custom title',\n" + " body = 'custom body',\n" + " destination_ref = 'main'" + ")");
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")), 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");
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GitHubPrDestinationTest method testTrimMessageForPrTitle.
@Test
public void testTrimMessageForPrTitle() 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\": \"test summary\",\n" + " \"body\": \"test summary\"" + "}", MockRequestAssertion.equals("{\"base\":\"main\",\"body\":\"Internal change.\\n\",\"head\":\"feature\"," + "\"title\":\"Internal change.\"}")));
GitHubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'https://github.com/foo'," + " destination_ref = 'main'" + ")");
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")).withSummary("\n\n\n\n\nInternal change."), 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");
}
Aggregations