Search in sources :

Example 6 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class OutputStreamQuery method buildChangeAttribute.

private ChangeAttribute buildChangeAttribute(ChangeData d, Map<Project.NameKey, Repository> repos, Map<Project.NameKey, RevWalk> revWalks) throws IOException {
    LabelTypes labelTypes = d.getLabelTypes();
    ChangeAttribute c = eventFactory.asChangeAttribute(d.change(), d.notes());
    eventFactory.extend(c, d.change());
    if (!trackingFooters.isEmpty()) {
        eventFactory.addTrackingIds(c, d.trackingFooters());
    }
    if (includeAllReviewers) {
        eventFactory.addAllReviewers(c, d.notes());
    }
    if (includeSubmitRecords) {
        SubmitRuleOptions options = SubmitRuleOptions.builder().recomputeOnClosedChanges(true).build();
        eventFactory.addSubmitRecords(c, submitRuleEvaluatorFactory.create(options).evaluate(d));
    }
    if (includeCommitMessage) {
        eventFactory.addCommitMessage(c, d.commitMessage());
    }
    RevWalk rw = null;
    if (includePatchSets || includeCurrentPatchSet || includeDependencies) {
        Project.NameKey p = d.change().getProject();
        rw = revWalks.get(p);
        // Cache and reuse repos and revwalks.
        if (rw == null) {
            Repository repo = repoManager.openRepository(p);
            checkState(repos.put(p, repo) == null);
            rw = new RevWalk(repo);
            revWalks.put(p, rw);
        }
    }
    if (includePatchSets) {
        eventFactory.addPatchSets(rw, c, d.patchSets(), includeApprovals ? d.approvals().asMap() : null, includeFiles, d.change(), labelTypes);
    }
    if (includeCurrentPatchSet) {
        PatchSet current = d.currentPatchSet();
        if (current != null) {
            c.currentPatchSet = eventFactory.asPatchSetAttribute(rw, d.change(), current);
            eventFactory.addApprovals(c.currentPatchSet, d.currentApprovals(), labelTypes);
            if (includeFiles) {
                eventFactory.addPatchSetFileNames(c.currentPatchSet, d.change(), d.currentPatchSet());
            }
            if (includeComments) {
                eventFactory.addPatchSetComments(c.currentPatchSet, d.publishedComments());
            }
        }
    }
    if (includeComments) {
        eventFactory.addComments(c, d.messages());
        if (includePatchSets) {
            eventFactory.addPatchSets(rw, c, d.patchSets(), includeApprovals ? d.approvals().asMap() : null, includeFiles, d.change(), labelTypes);
            for (PatchSetAttribute attribute : c.patchSets) {
                eventFactory.addPatchSetComments(attribute, d.publishedComments());
            }
        }
    }
    if (includeDependencies) {
        eventFactory.addDependencies(rw, c, d.change(), d.currentPatchSet());
    }
    List<PluginDefinedInfo> pluginInfos = pluginInfosByChange.get(d.getId());
    if (!pluginInfos.isEmpty()) {
        c.plugins = pluginInfos;
    }
    return c;
}
Also used : Project(com.google.gerrit.entities.Project) LabelTypes(com.google.gerrit.entities.LabelTypes) Repository(org.eclipse.jgit.lib.Repository) ChangeAttribute(com.google.gerrit.server.data.ChangeAttribute) SubmitRuleOptions(com.google.gerrit.server.project.SubmitRuleOptions) PatchSetAttribute(com.google.gerrit.server.data.PatchSetAttribute) PatchSet(com.google.gerrit.entities.PatchSet) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PluginDefinedInfo(com.google.gerrit.extensions.common.PluginDefinedInfo)

Example 7 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class UserInPredicate method match.

@Override
public boolean match(ApprovalContext ctx) {
    Account.Id accountId;
    if (field == Field.UPLOADER) {
        PatchSet patchSet = ctx.target();
        accountId = patchSet.uploader();
    } else if (field == Field.APPROVER) {
        accountId = ctx.patchSetApproval().accountId();
    } else {
        throw new IllegalStateException("unknown field in group membership check: " + field);
    }
    return identifiedUserFactory.create(accountId).getEffectiveGroups().contains(group);
}
Also used : Account(com.google.gerrit.entities.Account) PatchSet(com.google.gerrit.entities.PatchSet)

Example 8 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class ChangeData method isMergeable.

@Nullable
public Boolean isMergeable() {
    if (mergeable == null) {
        Change c = change();
        if (c == null) {
            return null;
        }
        if (c.isMerged()) {
            mergeable = true;
        } else if (c.isAbandoned()) {
            return null;
        } else if (c.isWorkInProgress()) {
            return null;
        } else {
            if (!lazyload()) {
                return null;
            }
            PatchSet ps = currentPatchSet();
            if (ps == null) {
                return null;
            }
            try (Repository repo = repoManager.openRepository(project())) {
                Ref ref = repo.getRefDatabase().exactRef(c.getDest().branch());
                SubmitTypeRecord str = submitTypeRecord();
                if (!str.isOk()) {
                    // No need to log, as SubmitRuleEvaluator already did it for us.
                    return false;
                }
                String mergeStrategy = mergeUtilFactory.create(projectCache.get(project()).orElseThrow(illegalState(project()))).mergeStrategyName();
                mergeable = mergeabilityCache.get(ps.commitId(), ref, str.type, mergeStrategy, c.getDest(), repo);
            } catch (IOException e) {
                throw new StorageException(e);
            }
        }
    }
    return mergeable;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) StarRef(com.google.gerrit.server.StarredChangesUtil.StarRef) Ref(org.eclipse.jgit.lib.Ref) SubmitTypeRecord(com.google.gerrit.entities.SubmitTypeRecord) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException) Nullable(com.google.gerrit.common.Nullable)

Example 9 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class PortedCommentsIT method portedDraftCommentHasPatchsetFilled.

@Test
public void portedDraftCommentHasPatchsetFilled() throws Exception {
    // Set up change and patchsets.
    Account.Id authorId = accountOps.newAccount().create();
    Change.Id changeId = changeOps.newChange().create();
    PatchSet.Id patchset1Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
    PatchSet.Id patchset2Id = changeOps.change(changeId).newPatchset().create();
    // Add comment.
    String commentUuid = newDraftComment(patchset1Id).author(authorId).create();
    Map<String, List<CommentInfo>> portedComments = getPortedDraftCommentsOfUser(patchset2Id, authorId);
    CommentInfo portedComment = extractSpecificComment(portedComments, commentUuid);
    // We explicitly need to request that the patchset field is filled, which we could have missed
    // for drafts. -> Test that aspect. Don't verify the actual patchset number as that's already
    // covered by the previous test.
    assertThat(portedComment).patchSet().isNotNull();
}
Also used : Account(com.google.gerrit.entities.Account) PatchSet(com.google.gerrit.entities.PatchSet) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) CommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.testing.CommentInfoSubject.assertThatList) List(java.util.List) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 10 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class CommentsIT method updatedDraftStillPointsToParentComment.

@Test
public void updatedDraftStillPointsToParentComment() throws Exception {
    Account.Id accountId = accountOperations.newAccount().create();
    Change.Id changeId = changeOperations.newChange().create();
    PatchSet.Id patchsetId = changeOperations.change(changeId).currentPatchset().get().patchsetId();
    String parentCommentUuid = changeOperations.change(changeId).patchset(patchsetId).newComment().create();
    String draftCommentUuid = changeOperations.change(changeId).patchset(patchsetId).newDraftComment().parentUuid(parentCommentUuid).author(accountId).create();
    // Each user can only see their own drafts.
    requestScopeOperations.setApiUser(accountId);
    DraftInput draftInput = CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 0, "bar");
    draftInput.message = "Another comment text.";
    gApi.changes().id(changeId.get()).revision(patchsetId.get()).draft(draftCommentUuid).update(draftInput);
    TestHumanComment comment = changeOperations.change(changeId).draftComment(draftCommentUuid).get();
    assertThat(comment.parentUuid()).hasValue(parentCommentUuid);
}
Also used : Account(com.google.gerrit.entities.Account) TestHumanComment(com.google.gerrit.acceptance.testsuite.change.TestHumanComment) PatchSet(com.google.gerrit.entities.PatchSet) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.entities.Change) IdString(com.google.gerrit.extensions.restapi.IdString) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

PatchSet (com.google.gerrit.entities.PatchSet)123 Change (com.google.gerrit.entities.Change)61 Test (org.junit.Test)48 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)41 ObjectId (org.eclipse.jgit.lib.ObjectId)35 RevCommit (org.eclipse.jgit.revwalk.RevCommit)29 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)28 Project (com.google.gerrit.entities.Project)25 StorageException (com.google.gerrit.exceptions.StorageException)25 Repository (org.eclipse.jgit.lib.Repository)22 IOException (java.io.IOException)20 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)19 ChangeData (com.google.gerrit.server.query.change.ChangeData)18 HumanComment (com.google.gerrit.entities.HumanComment)16 RevWalk (org.eclipse.jgit.revwalk.RevWalk)16 Inject (com.google.inject.Inject)14 Map (java.util.Map)14 List (java.util.List)13 ImmutableList (com.google.common.collect.ImmutableList)12 AuthException (com.google.gerrit.extensions.restapi.AuthException)11