Search in sources :

Example 1 with ChangeMessageModifier

use of com.google.gerrit.server.git.ChangeMessageModifier in project gerrit by GerritCodeReview.

the class ChangeIT method customCommitFooters.

@Test
public void customCommitFooters() throws Exception {
    PushOneCommit.Result change = createChange();
    RegistrationHandle handle = changeMessageModifiers.add(new ChangeMessageModifier() {

        @Override
        public String onSubmit(String newCommitMessage, RevCommit original, RevCommit mergeTip, Branch.NameKey destination) {
            assertThat(original.getName()).isNotEqualTo(mergeTip.getName());
            return newCommitMessage + "Custom: " + destination.get();
        }
    });
    ChangeInfo actual;
    try {
        EnumSet<ListChangesOption> options = EnumSet.of(ListChangesOption.ALL_REVISIONS, ListChangesOption.COMMIT_FOOTERS);
        actual = gApi.changes().id(change.getChangeId()).get(options);
    } finally {
        handle.remove();
    }
    List<String> footers = new ArrayList<>(Arrays.asList(actual.revisions.get(change.getCommit().getName()).commitWithFooters.split("\\n")));
    // remove subject + blank line
    footers.remove(0);
    footers.remove(0);
    List<String> expectedFooters = Arrays.asList("Change-Id: " + change.getChangeId(), "Reviewed-on: " + canonicalWebUrl.get() + change.getChange().getId(), "Custom: refs/heads/master");
    assertThat(footers).containsExactlyElementsIn(expectedFooters);
}
Also used : RegistrationHandle(com.google.gerrit.extensions.registration.RegistrationHandle) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ArrayList(java.util.ArrayList) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Branch(com.google.gerrit.reviewdb.client.Branch) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with ChangeMessageModifier

use of com.google.gerrit.server.git.ChangeMessageModifier in project gerrit by GerritCodeReview.

the class SubmitByCherryPickIT method changeMessageOnSubmit.

@Test
public void changeMessageOnSubmit() throws Exception {
    PushOneCommit.Result change = createChange();
    RegistrationHandle handle = changeMessageModifiers.add(new ChangeMessageModifier() {

        @Override
        public String onSubmit(String newCommitMessage, RevCommit original, RevCommit mergeTip, Branch.NameKey destination) {
            return newCommitMessage + "Custom: " + destination.get();
        }
    });
    try {
        submit(change.getChangeId());
    } finally {
        handle.remove();
    }
    testRepo.git().fetch().setRemote("origin").call();
    ChangeInfo info = get(change.getChangeId());
    RevCommit c = testRepo.getRevWalk().parseCommit(ObjectId.fromString(info.currentRevision));
    testRepo.getRevWalk().parseBody(c);
    assertThat(c.getFooterLines("Custom")).containsExactly("refs/heads/master");
    assertThat(c.getFooterLines(FooterConstants.REVIEWED_ON)).hasSize(1);
}
Also used : RegistrationHandle(com.google.gerrit.extensions.registration.RegistrationHandle) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Branch(com.google.gerrit.reviewdb.client.Branch) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 3 with ChangeMessageModifier

use of com.google.gerrit.server.git.ChangeMessageModifier in project gerrit by GerritCodeReview.

the class SubmitByRebaseAlwaysIT method changeMessageOnSubmit.

@Test
@TestProjectInput(useContentMerge = InheritableBoolean.TRUE)
public void changeMessageOnSubmit() throws Exception {
    PushOneCommit.Result change1 = createChange();
    PushOneCommit.Result change2 = createChange();
    RegistrationHandle handle = changeMessageModifiers.add(new ChangeMessageModifier() {

        @Override
        public String onSubmit(String newCommitMessage, RevCommit original, RevCommit mergeTip, Branch.NameKey destination) {
            List<String> custom = mergeTip.getFooterLines("Custom");
            if (!custom.isEmpty()) {
                newCommitMessage += "Custom-Parent: " + custom.get(0) + "\n";
            }
            return newCommitMessage + "Custom: " + destination.get();
        }
    });
    try {
        // change1 is a fast-forward, but should be rebased in cherry pick style
        // anyway, making change2 not a fast-forward, requiring a rebase.
        approve(change1.getChangeId());
        submit(change2.getChangeId());
    } finally {
        handle.remove();
    }
    // ... but both changes should get custom footers.
    assertThat(getCurrentCommit(change1).getFooterLines("Custom")).containsExactly("refs/heads/master");
    assertThat(getCurrentCommit(change2).getFooterLines("Custom")).containsExactly("refs/heads/master");
    assertThat(getCurrentCommit(change2).getFooterLines("Custom-Parent")).containsExactly("refs/heads/master");
}
Also used : RegistrationHandle(com.google.gerrit.extensions.registration.RegistrationHandle) Branch(com.google.gerrit.reviewdb.client.Branch) List(java.util.List) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) RevCommit(org.eclipse.jgit.revwalk.RevCommit) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Test(org.junit.Test)

Aggregations

PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)3 RegistrationHandle (com.google.gerrit.extensions.registration.RegistrationHandle)3 Branch (com.google.gerrit.reviewdb.client.Branch)3 ChangeMessageModifier (com.google.gerrit.server.git.ChangeMessageModifier)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 Test (org.junit.Test)3 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)1 ListChangesOption (com.google.gerrit.extensions.client.ListChangesOption)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1