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.ApprovalInference approvalInference, PermissionBackend permissionBackend, ProjectCache projectCache, ApprovalCache approvalCache)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Iterable<PatchSetApproval>
addApprovalsForNewPatchSet(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.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.List<PatchSetApproval>
addReviewers(ChangeNotes notes, ChangeUpdate update, LabelTypes labelTypes, Change change, Iterable<Account.Id> wantReviewers)
List<PatchSetApproval>
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>
byChange(ChangeNotes notes)
Iterable<PatchSetApproval>
byPatchSet(ChangeNotes notes, PatchSet patchSet)
Iterable<PatchSetApproval>
byPatchSet(ChangeNotes notes, PatchSet.Id psId)
Iterable<PatchSetApproval>
byPatchSet(ChangeNotes notes, PatchSet.Id psId, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.Config repoConfig)
Iterable<PatchSetApproval>
byPatchSetUser(ChangeNotes notes, PatchSet.Id psId, Account.Id accountId)
Iterable<PatchSetApproval>
byPatchSetUser(ChangeNotes notes, PatchSet.Id psId, Account.Id accountId, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.Config repoConfig)
static void
checkLabel(LabelTypes labelTypes, String name, Short value)
ReviewerSet
getReviewers(ChangeNotes notes)
Get all reviewers for a change.List<ReviewerStatusUpdate>
getReviewerUpdates(ChangeNotes notes)
Get updates to reviewer set.static PatchSetApproval
getSubmitter(PatchSet.Id c, Iterable<PatchSetApproval> approvals)
PatchSetApproval
getSubmitter(ChangeNotes notes, PatchSet.Id c)
static PatchSetApproval.Builder
newApproval(PatchSet.Id psId, CurrentUser user, LabelId labelId, int value, Date when)
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.static String
renderMessageWithApprovals(int patchSetId, Map<String,Short> n, Map<String,PatchSetApproval> c)
-
-
-
Constructor Detail
-
ApprovalsUtil
@Inject public ApprovalsUtil(com.google.gerrit.server.approval.ApprovalInference approvalInference, PermissionBackend permissionBackend, ProjectCache projectCache, ApprovalCache approvalCache)
-
-
Method Detail
-
newApproval
public static PatchSetApproval.Builder newApproval(PatchSet.Id psId, CurrentUser user, LabelId labelId, int value, Date 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
-
byChange
public com.google.common.collect.ListMultimap<PatchSet.Id,PatchSetApproval> byChange(ChangeNotes notes)
-
byPatchSet
public Iterable<PatchSetApproval> byPatchSet(ChangeNotes notes, PatchSet.Id psId, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.Config repoConfig)
-
byPatchSet
public Iterable<PatchSetApproval> byPatchSet(ChangeNotes notes, PatchSet patchSet)
-
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)
-
byPatchSetUser
public Iterable<PatchSetApproval> byPatchSetUser(ChangeNotes notes, PatchSet.Id psId, Account.Id accountId, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.Config repoConfig)
-
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)
-
-