Search in sources :

Example 1 with GitPerson

use of com.google.gerrit.extensions.common.GitPerson in project gerrit by GerritCodeReview.

the class CreateChangeIT method createDefaultAuthor.

@Test
public void createDefaultAuthor() throws Exception {
    ChangeInput input = newChangeInput(ChangeStatus.NEW);
    ChangeInfo info = assertCreateSucceeds(input);
    GitPerson person = gApi.changes().id(info.id).current().commit(false).author;
    assertThat(person).email().isEqualTo(admin.email());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) GitPerson(com.google.gerrit.extensions.common.GitPerson) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with GitPerson

use of com.google.gerrit.extensions.common.GitPerson in project gerrit by GerritCodeReview.

the class ChangeIT method testRebase.

private void testRebase(Rebase rebase) throws Exception {
    // Create two changes both with the same parent
    PushOneCommit.Result r = createChange();
    testRepo.reset("HEAD~1");
    PushOneCommit.Result r2 = createChange();
    // Approve and submit the first change
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
    revision.review(ReviewInput.approve());
    revision.submit();
    // Add an approval whose score should be copied on trivial rebase
    gApi.changes().id(r2.getChangeId()).current().review(ReviewInput.recommend());
    String changeId = r2.getChangeId();
    // Rebase the second change
    rebase.call(changeId);
    // Second change should have 2 patch sets and an approval
    ChangeInfo c2 = gApi.changes().id(changeId).get(CURRENT_REVISION, DETAILED_LABELS);
    assertThat(c2.revisions.get(c2.currentRevision)._number).isEqualTo(2);
    // ...and the committer and description should be correct
    ChangeInfo info = gApi.changes().id(changeId).get(CURRENT_REVISION, CURRENT_COMMIT);
    GitPerson committer = info.revisions.get(info.currentRevision).commit.committer;
    assertThat(committer.name).isEqualTo(admin.fullName());
    assertThat(committer.email).isEqualTo(admin.email());
    String description = info.revisions.get(info.currentRevision).description;
    assertThat(description).isEqualTo("Rebase");
    // ...and the approval was copied
    LabelInfo cr = c2.labels.get(LabelId.CODE_REVIEW);
    assertThat(cr).isNotNull();
    assertThat(cr.all).hasSize(1);
    assertThat(cr.all.get(0).value).isEqualTo(1);
    // Rebasing the second change again should fail
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.changes().id(changeId).current().rebase());
    assertThat(thrown).hasMessageThat().contains("Change is already up to date");
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) GitPerson(com.google.gerrit.extensions.common.GitPerson) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 3 with GitPerson

use of com.google.gerrit.extensions.common.GitPerson in project gerrit by GerritCodeReview.

the class CommonConverters method toGitPerson.

// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
public static GitPerson toGitPerson(PersonIdent ident) {
    GitPerson result = new GitPerson();
    result.name = ident.getName();
    result.email = ident.getEmailAddress();
    result.setDate(ident.getWhen().toInstant());
    result.tz = ident.getTimeZoneOffset();
    return result;
}
Also used : GitPerson(com.google.gerrit.extensions.common.GitPerson)

Example 4 with GitPerson

use of com.google.gerrit.extensions.common.GitPerson in project gerrit by GerritCodeReview.

the class CreateChangeIT method createMergeChangeAuthor.

@Test
public void createMergeChangeAuthor() throws Exception {
    changeInTwoBranches("branchA", "a.txt", "branchB", "b.txt");
    ChangeInput in = newMergeChangeInput("branchA", "branchB", "");
    in.author = new AccountInput();
    in.author.name = "Gerritless Jane";
    in.author.email = "gerritlessjane@invalid";
    ChangeInfo change = assertCreateSucceeds(in);
    RevisionApi rApi = gApi.changes().id(change.id).current();
    GitPerson author = rApi.commit(false).author;
    assertThat(author).email().isEqualTo(in.author.email);
    GitPerson committer = rApi.commit(false).committer;
    assertThat(committer).email().isEqualTo(admin.getNameEmail().email());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) GitPerson(com.google.gerrit.extensions.common.GitPerson) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) AccountInput(com.google.gerrit.extensions.api.accounts.AccountInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with GitPerson

use of com.google.gerrit.extensions.common.GitPerson in project gerrit by GerritCodeReview.

the class CreateChangeIT method createAuthorOverride.

@Test
public void createAuthorOverride() throws Exception {
    ChangeInput input = newChangeInput(ChangeStatus.NEW);
    input.author = new AccountInput();
    input.author.email = "gerritlessjane@invalid";
    // This is an email address that doesn't exist as account on the Gerrit server.
    input.author.name = "Gerritless Jane";
    ChangeInfo info = assertCreateSucceeds(input);
    RevisionApi rApi = gApi.changes().id(info.id).current();
    GitPerson author = rApi.commit(false).author;
    assertThat(author).email().isEqualTo(input.author.email);
    assertThat(author).name().isEqualTo(input.author.name);
    GitPerson committer = rApi.commit(false).committer;
    assertThat(committer).email().isEqualTo(admin.getNameEmail().email());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) GitPerson(com.google.gerrit.extensions.common.GitPerson) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) AccountInput(com.google.gerrit.extensions.api.accounts.AccountInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

GitPerson (com.google.gerrit.extensions.common.GitPerson)5 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)4 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)3 ChangeInput (com.google.gerrit.extensions.common.ChangeInput)3 Test (org.junit.Test)3 AccountInput (com.google.gerrit.extensions.api.accounts.AccountInput)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1