Search in sources :

Example 6 with RevisionInfo

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

the class ActionJson method copy.

private RevisionInfo copy(List<ActionVisitor> visitors, RevisionInfo revisionInfo) {
    if (visitors.isEmpty()) {
        return null;
    }
    // Include all fields from ChangeJson#toRevisionInfo that are not protected
    // by any ListChangesOptions.
    RevisionInfo copy = new RevisionInfo();
    copy.isCurrent = revisionInfo.isCurrent;
    copy._number = revisionInfo._number;
    copy.ref = revisionInfo.ref;
    copy.created = revisionInfo.created;
    copy.uploader = revisionInfo.uploader;
    copy.draft = revisionInfo.draft;
    copy.fetch = revisionInfo.fetch;
    copy.kind = revisionInfo.kind;
    copy.description = revisionInfo.description;
    return copy;
}
Also used : RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo)

Example 7 with RevisionInfo

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

the class ActionJson method format.

public Map<String, ActionInfo> format(RevisionResource rsrc) throws OrmException {
    ChangeInfo changeInfo = null;
    RevisionInfo revisionInfo = null;
    List<ActionVisitor> visitors = visitors();
    if (!visitors.isEmpty()) {
        changeInfo = changeJson().format(rsrc);
        revisionInfo = checkNotNull(Iterables.getOnlyElement(changeInfo.revisions.values()));
        changeInfo.revisions = null;
    }
    return toActionMap(rsrc, visitors, changeInfo, revisionInfo);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor)

Example 8 with RevisionInfo

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

the class ChangeJson method toRevisionInfo.

private RevisionInfo toRevisionInfo(ChangeControl ctl, ChangeData cd, PatchSet in, @Nullable Repository repo, @Nullable RevWalk rw, boolean fillCommit, @Nullable ChangeInfo changeInfo) throws PatchListNotAvailableException, GpgException, OrmException, IOException {
    Change c = ctl.getChange();
    RevisionInfo out = new RevisionInfo();
    out.isCurrent = in.getId().equals(c.currentPatchSetId());
    out._number = in.getId().get();
    out.ref = in.getRefName();
    out.created = in.getCreatedOn();
    out.uploader = accountLoader.get(in.getUploader());
    out.draft = in.isDraft() ? true : null;
    out.fetch = makeFetchMap(ctl, in);
    out.kind = changeKindCache.getChangeKind(rw, repo != null ? repo.getConfig() : null, cd, in);
    out.description = in.getDescription();
    boolean setCommit = has(ALL_COMMITS) || (out.isCurrent && has(CURRENT_COMMIT));
    boolean addFooters = out.isCurrent && has(COMMIT_FOOTERS);
    if (setCommit || addFooters) {
        checkState(rw != null);
        checkState(repo != null);
        Project.NameKey project = c.getProject();
        String rev = in.getRevision().get();
        RevCommit commit = rw.parseCommit(ObjectId.fromString(rev));
        rw.parseBody(commit);
        if (setCommit) {
            out.commit = toCommit(ctl, rw, commit, has(WEB_LINKS), fillCommit);
        }
        if (addFooters) {
            Ref ref = repo.exactRef(ctl.getChange().getDest().get());
            RevCommit mergeTip = null;
            if (ref != null) {
                mergeTip = rw.parseCommit(ref.getObjectId());
                rw.parseBody(mergeTip);
            }
            out.commitWithFooters = mergeUtilFactory.create(projectCache.get(project)).createCommitMessageOnSubmit(commit, mergeTip, ctl, in.getId());
        }
    }
    if (has(ALL_FILES) || (out.isCurrent && has(CURRENT_FILES))) {
        out.files = fileInfoJson.toFileInfoMap(c, in);
        out.files.remove(Patch.COMMIT_MSG);
        out.files.remove(Patch.MERGE_LIST);
    }
    if ((out.isCurrent || (out.draft != null && out.draft)) && has(CURRENT_ACTIONS) && userProvider.get().isIdentifiedUser()) {
        actionJson.addRevisionActions(changeInfo, out, new RevisionResource(changeResourceFactory.create(ctl), in));
    }
    if (gpgApi.isEnabled() && has(PUSH_CERTIFICATES)) {
        if (in.getPushCertificate() != null) {
            out.pushCertificate = gpgApi.checkPushCertificate(in.getPushCertificate(), userFactory.create(in.getUploader()));
        } else {
            out.pushCertificate = new PushCertificateInfo();
        }
    }
    return out;
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Ref(org.eclipse.jgit.lib.Ref) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) Change(com.google.gerrit.reviewdb.client.Change) PushCertificateInfo(com.google.gerrit.extensions.common.PushCertificateInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 9 with RevisionInfo

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

the class ChangeIT method queryChangesOptions.

@Test
public void queryChangesOptions() throws Exception {
    PushOneCommit.Result r = createChange();
    ChangeInfo result = Iterables.getOnlyElement(gApi.changes().query(r.getChangeId()).get());
    assertThat(result.labels).isNull();
    assertThat(result.messages).isNull();
    assertThat(result.actions).isNull();
    assertThat(result.revisions).isNull();
    EnumSet<ListChangesOption> options = EnumSet.of(ListChangesOption.ALL_REVISIONS, ListChangesOption.CHANGE_ACTIONS, ListChangesOption.CURRENT_ACTIONS, ListChangesOption.DETAILED_LABELS, ListChangesOption.MESSAGES);
    result = Iterables.getOnlyElement(gApi.changes().query(r.getChangeId()).withOptions(options).get());
    assertThat(Iterables.getOnlyElement(result.labels.keySet())).isEqualTo("Code-Review");
    assertThat(result.messages).hasSize(1);
    assertThat(result.actions).isNotEmpty();
    RevisionInfo rev = Iterables.getOnlyElement(result.revisions.values());
    assertThat(rev._number).isEqualTo(r.getPatchSetId().get());
    assertThat(rev.created).isNotNull();
    assertThat(rev.uploader._accountId).isEqualTo(admin.getId().get());
    assertThat(rev.ref).isEqualTo(r.getPatchSetId().toRefName());
    assertThat(rev.actions).isNotEmpty();
}
Also used : ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 10 with RevisionInfo

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

the class ChangeIT method changeNoParentToOneParent.

@Test
@TestProjectInput(createEmptyCommit = false)
public void changeNoParentToOneParent() throws Exception {
    // create initial commit with no parent and push it as change, so that patch
    // set 1 has no parent
    RevCommit c = testRepo.commit().message("Initial commit").insertChangeId().create();
    String id = GitUtil.getChangeId(testRepo, c).get();
    testRepo.reset(c);
    PushResult pr = pushHead(testRepo, "refs/for/master", false);
    assertPushOk(pr, "refs/for/master");
    ChangeInfo change = gApi.changes().id(id).get();
    assertThat(change.revisions.get(change.currentRevision).commit.parents).isEmpty();
    // create another initial commit with no parent and push it directly into
    // the remote repository
    c = testRepo.amend(c.getId()).message("Initial Empty Commit").create();
    testRepo.reset(c);
    pr = pushHead(testRepo, "refs/heads/master", false);
    assertPushOk(pr, "refs/heads/master");
    // create a successor commit and push it as second patch set to the change,
    // so that patch set 2 has 1 parent
    RevCommit c2 = testRepo.commit().message("Initial commit").parent(c).insertChangeId(id.substring(1)).create();
    testRepo.reset(c2);
    pr = pushHead(testRepo, "refs/for/master", false);
    assertPushOk(pr, "refs/for/master");
    change = gApi.changes().id(id).get();
    RevisionInfo rev = change.revisions.get(change.currentRevision);
    assertThat(rev.commit.parents).hasSize(1);
    assertThat(rev.commit.parents.get(0).commit).isEqualTo(c.name());
    // check that change kind is correctly detected as REWORK
    assertThat(rev.kind).isEqualTo(ChangeKind.REWORK);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) PushResult(org.eclipse.jgit.transport.PushResult) RevCommit(org.eclipse.jgit.revwalk.RevCommit) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)18 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)13 Test (org.junit.Test)13 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)6 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 ActionVisitor (com.google.gerrit.extensions.api.changes.ActionVisitor)3 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)3 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)3 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)3 Change (com.google.gerrit.reviewdb.client.Change)3 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)2 SubmittedTogetherInfo (com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo)2 ListChangesOption (com.google.gerrit.extensions.client.ListChangesOption)2 ActionInfo (com.google.gerrit.extensions.common.ActionInfo)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 GerritConfig (com.google.gerrit.acceptance.GerritConfig)1 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)1 SubmitTypeRecord (com.google.gerrit.common.data.SubmitTypeRecord)1 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)1