Class ApprovalsUtil
- java.lang.Object
-
- com.google.gerrit.server.approval.ApprovalsUtil
-
public class ApprovalsUtil extends Object
Utility functions to manipulate patchset approvals.Approvals are overloaded, they represent both approvals and reviewers which should be CCed on a change. To ensure that reviewers are not lost there must always be an approval on each patchset for each reviewer, even if the reviewer hasn't actually given a score to the change. To mark the "no score" case, a dummy approval, which may live in any of the available categories, with a score of 0 is used.
-
-
Constructor Summary
Constructors Constructor Description ApprovalsUtil(com.google.gerrit.server.approval.ApprovalCopier approvalInference, PermissionBackend permissionBackend, ProjectCache projectCache, LabelNormalizer labelNormalizer)
-
Method Summary
-
-
-
Constructor Detail
-
ApprovalsUtil
@Inject public ApprovalsUtil(com.google.gerrit.server.approval.ApprovalCopier approvalInference, PermissionBackend permissionBackend, ProjectCache projectCache, LabelNormalizer labelNormalizer)
-
-
Method Detail
-
newApproval
public static PatchSetApproval.Builder newApproval(PatchSet.Id psId, CurrentUser user, LabelId labelId, int value, Instant when)
-
getReviewers
public ReviewerSet getReviewers(ChangeNotes notes)
Get all reviewers for a change.- Parameters:
notes
- change notes.- Returns:
- reviewers for the change.
-
getReviewerUpdates
public List<ReviewerStatusUpdate> getReviewerUpdates(ChangeNotes notes)
Get updates to reviewer set.- Parameters:
notes
- change notes.- Returns:
- reviewer updates for the change.
-
addReviewers
public List<PatchSetApproval> addReviewers(ChangeUpdate update, LabelTypes labelTypes, Change change, PatchSet ps, PatchSetInfo info, Iterable<Account.Id> wantReviewers, Collection<Account.Id> existingReviewers)
-
addReviewers
public List<PatchSetApproval> addReviewers(ChangeNotes notes, ChangeUpdate update, LabelTypes labelTypes, Change change, Iterable<Account.Id> wantReviewers)
-
addCcs
public Collection<Account.Id> addCcs(ChangeNotes notes, ChangeUpdate update, Collection<Account.Id> wantCCs, boolean keepExistingReviewers)
Adds accounts to a change as reviewers in the CC state.- Parameters:
notes
- change notes.update
- change update.wantCCs
- accounts to CC.keepExistingReviewers
- whether provided accounts that are already reviewer should be kept as reviewer or be downgraded to CC- Returns:
- whether a change was made.
-
addApprovalsForNewPatchSet
public Iterable<PatchSetApproval> addApprovalsForNewPatchSet(ChangeUpdate update, LabelTypes labelTypes, PatchSet ps, CurrentUser user, Map<String,Short> approvals) throws RestApiException, PermissionBackendException
Adds approvals to ChangeUpdate for a new patch set, and writes to NoteDb.- Parameters:
update
- change update.labelTypes
- label types for the containing project.ps
- patch set being approved.user
- user adding approvals.approvals
- approvals to add.- Throws:
RestApiException
PermissionBackendException
-
checkLabel
public static void checkLabel(LabelTypes labelTypes, String name, Short value) throws BadRequestException
- Throws:
BadRequestException
-
byChangeExcludingCopiedApprovals
public com.google.common.collect.ListMultimap<PatchSet.Id,PatchSetApproval> byChangeExcludingCopiedApprovals(ChangeNotes notes)
-
persistCopiedApprovals
public void persistCopiedApprovals(ChangeNotes notes, PatchSet patchSet, org.eclipse.jgit.revwalk.RevWalk revWalk, org.eclipse.jgit.lib.Config repoConfig, ChangeUpdate changeUpdate)
This method should only be used when we want to dynamically compute the approvals. Generally, the copied approvals are available inChangeNotes
. However, if the patch-set is just being created, we need to dynamically compute the approvals so that we can persist them in storage. TheRevWalk
andConfig
objects that are being used to create the new patch-set are required for this method. Here we also add those votes to the providedChangeUpdate
object.
-
byPatchSet
public Iterable<PatchSetApproval> byPatchSet(ChangeNotes notes, PatchSet.Id psId)
GetsPatchSetApproval
s for a specified patch-set. The result includes copied votes but does not include deleted labels.- Parameters:
notes
- changenotes of the change.psId
- patch-set id for the change and patch-set we want to get approvals.- Returns:
- all approvals for the specified patch-set, including copied votes, not including deleted labels.
-
byPatchSetUser
public Iterable<PatchSetApproval> byPatchSetUser(ChangeNotes notes, PatchSet.Id psId, Account.Id accountId)
-
getSubmitter
public PatchSetApproval getSubmitter(ChangeNotes notes, PatchSet.Id c)
-
getSubmitter
public static PatchSetApproval getSubmitter(PatchSet.Id c, Iterable<PatchSetApproval> approvals)
-
-