Class ApprovalsUtil
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
ConstructorsConstructorDescriptionApprovalsUtil
(AccountCache accountCache, String anonymousCowardName, ApprovalCopier approvalCopier, com.google.inject.Provider<ApprovalQueryBuilder> approvalQueryBuilderProvider, PermissionBackend permissionBackend, ProjectCache projectCache, LabelNormalizer labelNormalizer, OneOffRequestContext requestContext) -
Method Summary
Modifier and TypeMethodDescriptionaddApprovalsForNewPatchSet
(ChangeUpdate update, LabelTypes labelTypes, PatchSet ps, CurrentUser user, Map<String, Short> approvals) Adds approvals to ChangeUpdate for a new patch set, and writes to NoteDb.addCcs
(ChangeNotes notes, ChangeUpdate update, Collection<Account.Id> wantCCs, boolean keepExistingReviewers) Adds accounts to a change as reviewers in the CC state.addReviewers
(ChangeNotes notes, ChangeUpdate update, LabelTypes labelTypes, Change change, Iterable<Account.Id> wantReviewers) addReviewers
(ChangeUpdate update, LabelTypes labelTypes, Change change, PatchSet ps, PatchSetInfo info, Iterable<Account.Id> wantReviewers, Collection<Account.Id> existingReviewers) com.google.common.collect.ListMultimap
<PatchSet.Id, PatchSetApproval> com.google.common.collect.ListMultimap
<PatchSet.Id, PatchSetApproval> byPatchSet
(ChangeNotes notes, PatchSet.Id psId) GetsPatchSetApproval
s for a specified patch-set.byPatchSetUser
(ChangeNotes notes, PatchSet.Id psId, Account.Id accountId) static void
checkLabel
(LabelTypes labelTypes, String name, Short value) copyApprovalsToNewPatchSet
(ChangeNotes notes, PatchSet patchSet, RepoView repoView, ChangeUpdate changeUpdate) Copies approvals to a new patch set.formatApprovalCopierResult
(ApprovalCopier.Result approvalCopierResult) getReviewers
(ChangeNotes notes) Get all reviewers for a change.getReviewerUpdates
(ChangeNotes notes) Get updates to reviewer set.static PatchSetApproval
getSubmitter
(PatchSet.Id c, Iterable<PatchSetApproval> approvals) getSubmitter
(ChangeNotes notes, PatchSet.Id c) static PatchSetApproval.Builder
newApproval
(PatchSet.Id psId, CurrentUser user, LabelId labelId, int value, Instant when) static String
renderMessageWithApprovals
(int patchSetId, Map<String, Short> n, Map<String, PatchSetApproval> c)
-
Constructor Details
-
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 Details
-
newApproval
public static PatchSetApproval.Builder newApproval(PatchSet.Id psId, CurrentUser user, LabelId labelId, int value, Instant when) -
getReviewers
Get all reviewers for a change.- Parameters:
notes
- change notes.- Returns:
- reviewers for the change.
-
getReviewerUpdates
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
@CanIgnoreReturnValue public Iterable<PatchSetApproval> addApprovalsForNewPatchSet(ChangeUpdate update, LabelTypes labelTypes, PatchSet ps, CurrentUser user, Map<String, Short> approvals) throws RestApiException, PermissionBackendExceptionAdds 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, RepoView repoView, 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 setrepoView
- repo viewchangeUpdate
- changeUpdate that is used to persist the copied approvals and update the attention set- Returns:
- the result of the approval copying
-
formatApprovalCopierResult
-
byPatchSet
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
-
getSubmitter
-
renderMessageWithApprovals
-