Search in sources :

Example 66 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gerrit by GerritCodeReview.

the class ChangeNotesParserTest method writeCommit.

private RevCommit writeCommit(String body, PersonIdent author) throws Exception {
    Change change = newChange();
    ChangeNotes notes = newNotes(change).load();
    try (ObjectInserter ins = testRepo.getRepository().newObjectInserter()) {
        CommitBuilder cb = new CommitBuilder();
        cb.setParentId(notes.getRevision());
        cb.setAuthor(author);
        cb.setCommitter(new PersonIdent(serverIdent, author.getWhen()));
        cb.setTreeId(testRepo.tree());
        cb.setMessage(body);
        ObjectId id = ins.insert(cb);
        ins.flush();
        RevCommit commit = walk.parseCommit(id);
        walk.parseBody(commit);
        return commit;
    }
}
Also used : ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) PersonIdent(org.eclipse.jgit.lib.PersonIdent) ObjectId(org.eclipse.jgit.lib.ObjectId) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) Change(com.google.gerrit.reviewdb.client.Change) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 67 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gitiles by GerritCodeReview.

the class CommitJsonData method toJsonData.

private static Ident toJsonData(PersonIdent ident, DateFormatter df) {
    Ident result = new Ident();
    result.name = ident.getName();
    result.email = ident.getEmailAddress();
    result.time = df.format(ident);
    return result;
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Example 68 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gerrit by GerritCodeReview.

the class TestChanges method newUpdate.

public static ChangeUpdate newUpdate(Injector injector, Change c, final CurrentUser user) throws Exception {
    injector = injector.createChildInjector(new FactoryModule() {

        @Override
        public void configure() {
            bind(CurrentUser.class).toInstance(user);
        }
    });
    ChangeUpdate update = injector.getInstance(ChangeUpdate.Factory.class).create(stubChangeControl(injector.getInstance(AbstractChangeNotes.Args.class), c, user), TimeUtil.nowTs(), Ordering.<String>natural());
    ChangeNotes notes = update.getNotes();
    boolean hasPatchSets = notes.getPatchSets() != null && !notes.getPatchSets().isEmpty();
    NotesMigration migration = injector.getInstance(NotesMigration.class);
    if (hasPatchSets || !migration.readChanges()) {
        return update;
    }
    // Change doesn't exist yet. NoteDb requires that there be a commit for the
    // first patch set, so create one.
    GitRepositoryManager repoManager = injector.getInstance(GitRepositoryManager.class);
    try (Repository repo = repoManager.openRepository(c.getProject())) {
        TestRepository<Repository> tr = new TestRepository<>(repo);
        PersonIdent ident = user.asIdentifiedUser().newCommitterIdent(update.getWhen(), TimeZone.getDefault());
        TestRepository<Repository>.CommitBuilder<Repository> cb = tr.commit().author(ident).committer(ident).message(firstNonNull(c.getSubject(), "Test change"));
        Ref parent = repo.exactRef(c.getDest().get());
        if (parent != null) {
            cb.parent(tr.getRevWalk().parseCommit(parent.getObjectId()));
        }
        update.setBranch(c.getDest().get());
        update.setChangeId(c.getKey().get());
        update.setCommit(tr.getRevWalk(), cb.create());
        return update;
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) CurrentUser(com.google.gerrit.server.CurrentUser) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) AbstractChangeNotes(com.google.gerrit.server.notedb.AbstractChangeNotes) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) AbstractChangeNotes(com.google.gerrit.server.notedb.AbstractChangeNotes) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate) NotesMigration(com.google.gerrit.server.notedb.NotesMigration) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Example 69 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gerrit by GerritCodeReview.

the class CommitMsgHookTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    final Date when = author.getWhen();
    final TimeZone tz = author.getTimeZone();
    author = new PersonIdent("J. Author", "ja@example.com");
    author = new PersonIdent(author, when, tz);
    committer = new PersonIdent("J. Committer", "jc@example.com");
    committer = new PersonIdent(committer, when, tz);
}
Also used : TimeZone(java.util.TimeZone) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Date(java.util.Date) Before(org.junit.Before)

Example 70 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gerrit by GerritCodeReview.

the class CommitMessageOutputTest method approvalsCommitFormatSimple.

@Test
public void approvalsCommitFormatSimple() throws Exception {
    Change c = TestChanges.newChange(project, changeOwner.getAccountId(), 1);
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putApproval("Verified", (short) 1);
    update.putApproval("Code-Review", (short) -1);
    update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
    update.putReviewer(otherUser.getAccount().getId(), CC);
    update.commit();
    assertThat(update.getRefName()).isEqualTo("refs/changes/01/1/meta");
    RevCommit commit = parseCommit(update.getResult());
    assertBodyEquals("Update patch set 1\n" + "\n" + "Patch-set: 1\n" + "Change-id: " + c.getKey().get() + "\n" + "Subject: Change subject\n" + "Branch: refs/heads/master\n" + "Commit: " + update.getCommit().name() + "\n" + "Reviewer: Change Owner <1@gerrit>\n" + "CC: Other Account <2@gerrit>\n" + "Label: Code-Review=-1\n" + "Label: Verified=+1\n", commit);
    PersonIdent author = commit.getAuthorIdent();
    assertThat(author.getName()).isEqualTo("Change Owner");
    assertThat(author.getEmailAddress()).isEqualTo("1@gerrit");
    assertThat(author.getWhen()).isEqualTo(new Date(c.getCreatedOn().getTime() + 1000));
    assertThat(author.getTimeZone()).isEqualTo(TimeZone.getTimeZone("GMT-7:00"));
    PersonIdent committer = commit.getCommitterIdent();
    assertThat(committer.getName()).isEqualTo("Gerrit Server");
    assertThat(committer.getEmailAddress()).isEqualTo("noreply@gerrit.com");
    assertThat(committer.getWhen()).isEqualTo(author.getWhen());
    assertThat(committer.getTimeZone()).isEqualTo(author.getTimeZone());
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) Change(com.google.gerrit.reviewdb.client.Change) Date(java.util.Date) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

PersonIdent (org.eclipse.jgit.lib.PersonIdent)86 RevCommit (org.eclipse.jgit.revwalk.RevCommit)23 Test (org.junit.Test)21 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)19 ObjectId (org.eclipse.jgit.lib.ObjectId)18 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)15 RevWalk (org.eclipse.jgit.revwalk.RevWalk)13 Change (com.google.gerrit.reviewdb.client.Change)12 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)12 Repository (org.eclipse.jgit.lib.Repository)11 Account (com.google.gerrit.reviewdb.client.Account)10 IOException (java.io.IOException)9 RefUpdate (org.eclipse.jgit.lib.RefUpdate)9 Ref (org.eclipse.jgit.lib.Ref)8 TestRepository (org.eclipse.jgit.junit.TestRepository)7 Date (java.util.Date)6 Result (org.eclipse.jgit.lib.RefUpdate.Result)6 ArrayList (java.util.ArrayList)5 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4