use of com.google.copybara.authoring.Authoring in project copybara by google.
the class DummyOriginTest method testCanSpecifyMessage.
@Test
public void testCanSpecifyMessage() throws Exception {
DummyOrigin origin = new DummyOrigin().addSimpleChange(/*timestamp*/
4242, "foo msg");
Authoring authoring = new Authoring(new Author("foo", "default.example.com"), AuthoringMappingMode.OVERWRITE, ImmutableSet.of());
Reader<DummyRevision> reader = origin.newReader(Glob.ALL_FILES, authoring);
ImmutableList<Change<DummyRevision>> changes = reader.changes(/*fromRef*/
null, /*toRef*/
origin.resolve("0")).getChanges();
assertThat(changes).hasSize(1);
assertThat(changes.get(0).getMessage()).isEqualTo("foo msg");
}
use of com.google.copybara.authoring.Authoring in project copybara by google.
the class GithubPROrigin method newReader.
@Override
public Reader<GitRevision> newReader(Glob originFiles, Authoring authoring) throws ValidationException {
return new ReaderImpl(url, originFiles, authoring, gitOptions, gitOriginOptions, generalOptions, /*includeBranchCommitLogs=*/
false, submoduleStrategy, firstParent) {
/**
* Disable rebase since this is controlled by useMerge field.
*/
@Override
protected void maybeRebase(GitRepository repo, GitRevision ref, Path workdir) throws RepoException, CannotResolveRevisionException {
}
@Override
public Optional<Baseline<GitRevision>> findBaseline(GitRevision startRevision, String label) throws RepoException, ValidationException {
if (!baselineFromBranch) {
return super.findBaseline(startRevision, label);
}
return findBaselinesWithoutLabel(startRevision, /*limit=*/
1).stream().map(e -> new Baseline<>(e.getSha1(), e)).findFirst();
}
@Override
public ImmutableList<GitRevision> findBaselinesWithoutLabel(GitRevision startRevision, int limit) throws RepoException, ValidationException {
String baseline = startRevision.associatedLabels().get(GITHUB_BASE_BRANCH_SHA1);
Preconditions.checkNotNull(baseline, "%s label should be present in %s", GITHUB_BASE_BRANCH_SHA1, startRevision);
GitRevision baselineRev = getRepository().resolveReference(baseline);
// Don't skip the first change as it is already the baseline
BaselinesWithoutLabelVisitor<GitRevision> visitor = new BaselinesWithoutLabelVisitor<>(originFiles, limit, /*skipFirst=*/
false);
visitChanges(baselineRev, visitor);
return visitor.getResult();
}
@Override
public Endpoint getFeedbackEndPoint() {
return new GitHubEndPoint(githubOptions, url);
}
/**
* Deal with the case of useMerge. We have a new commit (the merge) and first-parent from that
* commit doesn't work for this case.
*/
@Override
public ChangesResponse<GitRevision> changes(@Nullable GitRevision fromRef, GitRevision toRef) throws RepoException {
if (!useMerge) {
return super.changes(fromRef, toRef);
}
GitLogEntry merge = Iterables.getOnlyElement(getRepository().log(toRef.getSha1()).withLimit(1).run());
// Fast-forward merge
if (merge.getParents().size() == 1) {
return super.changes(fromRef, toRef);
}
// HEAD of the Pull Request
GitRevision gitRevision = merge.getParents().get(1);
ChangesResponse<GitRevision> prChanges = super.changes(fromRef, gitRevision);
// origin_files
if (prChanges.isEmpty()) {
return prChanges;
}
try {
return ChangesResponse.forChanges(ImmutableList.<Change<GitRevision>>builder().addAll(prChanges.getChanges()).add(change(merge.getCommit())).build());
} catch (EmptyChangeException e) {
throw new RepoException("Error getting the merge commit information: " + merge, e);
}
}
@Nullable
@Override
public String getGroupIdentity(GitRevision rev) throws RepoException {
return rev.associatedLabels().get(GITHUB_PR_NUMBER_LABEL);
}
};
}
use of com.google.copybara.authoring.Authoring in project copybara by google.
the class MetadataModuleTest method setup.
@Before
public void setup() throws Exception {
options = new OptionsBuilder();
authoring = "authoring.overwrite('" + DEFAULT_AUTHOR + "')";
workdir = Files.createTempDirectory("workdir");
Files.createDirectories(workdir);
origin = new DummyOrigin().setAuthor(ORIGINAL_AUTHOR);
destination = new RecordsProcessCallDestination();
options.setConsole(new TestingConsole());
options.testingOptions.origin = origin;
options.testingOptions.destination = destination;
skylark = new SkylarkParser(ImmutableSet.of(Core.class, Authoring.Module.class, TestingModule.class, MetadataModule.class));
skylarkExecutor = new SkylarkTestExecutor(options, MetadataModule.class);
origin.addSimpleChange(0, "first commit\n\nExtended text").setAuthor(FOO_BAR).addSimpleChange(1, "second commit\n\nExtended text").setAuthor(FOO_BAZ).addSimpleChange(2, "third commit\n\nExtended text");
options.setLastRevision("0");
// We don't care about already migrated code
options.setForce(true);
testingConsole = new TestingConsole();
options.setConsole(testingConsole);
}
use of com.google.copybara.authoring.Authoring in project copybara by google.
the class WorkflowTest method setup.
@Before
public void setup() throws Exception {
options = new OptionsBuilder();
authoring = "authoring.overwrite('" + DEFAULT_AUTHOR + "')";
includeReleaseNotes = false;
workdir = Files.createTempDirectory("workdir");
Files.createDirectories(workdir);
origin = new DummyOrigin().setAuthor(ORIGINAL_AUTHOR);
originFiles = "glob(['**'], exclude = ['copy.bara.sky', 'excluded/**'])";
destinationFiles = "glob(['**'])";
destination = new RecordsProcessCallDestination();
transformations = ImmutableList.of("" + " core.replace(\n" + " before = '${linestart}${number}',\n" + " after = '${linestart}" + PREFIX + "${number}',\n" + " regex_groups = {\n" + " 'number' : '[0-9]+',\n" + " 'linestart' : '^',\n" + " },\n" + " multiline = True," + " )");
TestingConsole console = new TestingConsole();
options.setConsole(console);
options.testingOptions.origin = origin;
options.testingOptions.destination = destination;
// Force by default unless we are testing the flag.
options.setForce(true);
skylark = new SkylarkParser(ImmutableSet.of(Core.class, Authoring.Module.class, TestingModule.class, MetadataModule.class, FolderModule.class, GitModule.class));
eventMonitor = new TestingEventMonitor();
options.general.withEventMonitor(eventMonitor);
transformWork = TransformWorks.of(workdir, "example", console);
}
use of com.google.copybara.authoring.Authoring in project copybara by google.
the class DummyOriginTest method canSetAuthorOfIndividualChanges.
@Test
public void canSetAuthorOfIndividualChanges() throws Exception {
DummyOrigin origin = new DummyOrigin().setAuthor(new Author("Dummy Origin", "dummy_origin@google.com")).addSimpleChange(/*timestamp*/
42).setAuthor(new Author("Wise Origin", "wise_origin@google.com")).addSimpleChange(/*timestamp*/
999);
Authoring authoring = new Authoring(new Author("foo", "default.example.com"), AuthoringMappingMode.PASS_THRU, ImmutableSet.of());
ImmutableList<Change<DummyRevision>> changes = origin.newReader(Glob.ALL_FILES, authoring).changes(/*fromRef*/
null, /*toRef*/
origin.resolve("1")).getChanges();
assertThat(changes).hasSize(2);
assertThat(changes.get(0).getAuthor()).isEqualTo(new Author("Dummy Origin", "dummy_origin@google.com"));
assertThat(changes.get(1).getAuthor()).isEqualTo(new Author("Wise Origin", "wise_origin@google.com"));
}
Aggregations