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(AccountCache accountCache, String anonymousCowardName, ApprovalCopier approvalCopier, com.google.inject.Provider<ApprovalQueryBuilder> approvalQueryBuilderProvider, PermissionBackend permissionBackend, ProjectCache projectCache, LabelNormalizer labelNormalizer, OneOffRequestContext requestContext)
-
Method Summary
-
-
-
Constructor Detail
-
ApprovalsUtil
@Inject public ApprovalsUtil(AccountCache accountCache, String anonymousCowardName, ApprovalCopier approvalCopier, com.google.inject.Provider<ApprovalQueryBuilder> approvalQueryBuilderProvider, PermissionBackend permissionBackend, ProjectCache projectCache, LabelNormalizer labelNormalizer, OneOffRequestContext requestContext)
-
-
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)
-
byChangeIncludingCopiedApprovals
public com.google.common.collect.ListMultimap<PatchSet.Id,PatchSetApproval> byChangeIncludingCopiedApprovals(ChangeNotes notes)
-
copyApprovalsToNewPatchSet
public ApprovalCopier.Result copyApprovalsToNewPatchSet(ChangeNotes notes, PatchSet patchSet, org.eclipse.jgit.revwalk.RevWalk revWalk, org.eclipse.jgit.lib.Config repoConfig, ChangeUpdate changeUpdate)
Copies approvals to a new patch set.Computes the approvals of the prior patch set that should be copied to the new patch set and stores them in NoteDb.
For outdated approvals (approvals on the prior patch set which are outdated by the new patch set and hence not copied) the approvers are added to the attention set since they need to re-review the change and renew their approvals.
- Parameters:
notes
- the change notespatchSet
- the newly created patch setrevWalk
-RevWalk
that can see the new patch set revisionrepoConfig
- the repo configchangeUpdate
- changeUpdate that is used to persist the copied approvals and update the attention set- Returns:
- the result of the approval copying
-
formatApprovalCopierResult
public Optional<String> formatApprovalCopierResult(ApprovalCopier.Result approvalCopierResult, LabelTypes labelTypes)
-
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)
-
-