Search in sources :

Example 1 with ApprovalsUtil

use of com.google.gerrit.server.approval.ApprovalsUtil in project gerrit by GerritCodeReview.

the class PatchSetUtil method isPatchSetLocked.

/**
 * Is the current patch set locked against state changes?
 */
public boolean isPatchSetLocked(ChangeNotes notes) {
    Change change = notes.getChange();
    if (change.isMerged()) {
        return false;
    }
    ProjectState projectState = projectCache.get(notes.getProjectName()).orElseThrow(illegalState(notes.getProjectName()));
    ApprovalsUtil approvalsUtil = approvalsUtilProvider.get();
    for (PatchSetApproval ap : approvalsUtil.byPatchSet(notes, change.currentPatchSetId())) {
        Optional<LabelType> type = projectState.getLabelTypes(notes).byLabel(ap.label());
        if (type.isPresent() && ap.value() == 1 && type.get().getFunction() == LabelFunction.PATCH_SET_LOCK) {
            return true;
        }
    }
    return false;
}
Also used : LabelType(com.google.gerrit.entities.LabelType) ApprovalsUtil(com.google.gerrit.server.approval.ApprovalsUtil) ProjectState(com.google.gerrit.server.project.ProjectState) Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval)

Example 2 with ApprovalsUtil

use of com.google.gerrit.server.approval.ApprovalsUtil in project gerrit by GerritCodeReview.

the class AddReviewersOp method updateChange.

@Override
public boolean updateChange(ChangeContext ctx) throws RestApiException, IOException {
    change = ctx.getChange();
    if (!accountIds.isEmpty()) {
        if (state == CC) {
            addedCCs = approvalsUtil.addCcs(ctx.getNotes(), ctx.getUpdate(change.currentPatchSetId()), accountIds, forGroup);
        } else {
            addedReviewers = approvalsUtil.addReviewers(ctx.getNotes(), ctx.getUpdate(change.currentPatchSetId()), projectCache.get(change.getProject()).orElseThrow(illegalState(change.getProject())).getLabelTypes(change.getDest()), change, accountIds);
        }
    }
    ReviewerStateInternal internalState = ReviewerStateInternal.fromReviewerState(state);
    // TODO(dborowitz): This behavior should live in ApprovalsUtil or something, like addCcs does.
    ImmutableSet<Address> existing = ctx.getNotes().getReviewersByEmail().byState(internalState);
    ImmutableList<Address> addressesToAdd = addresses.stream().filter(a -> !existing.contains(a)).collect(toImmutableList());
    if (state == CC) {
        addedCCsByEmail = addressesToAdd;
    } else {
        addedReviewersByEmail = addressesToAdd;
    }
    for (Address a : addressesToAdd) {
        ctx.getUpdate(change.currentPatchSetId()).putReviewerByEmail(a, internalState);
    }
    if (addedCCs.isEmpty() && addedReviewers.isEmpty() && addressesToAdd.isEmpty()) {
        return false;
    }
    checkAdded();
    if (patchSet == null) {
        patchSet = requireNonNull(psUtil.current(ctx.getNotes()));
    }
    return true;
}
Also used : AccountCache(com.google.gerrit.server.account.AccountCache) CC(com.google.gerrit.extensions.client.ReviewerState.CC) ProjectCache(com.google.gerrit.server.project.ProjectCache) Inject(com.google.inject.Inject) REVIEWER(com.google.gerrit.extensions.client.ReviewerState.REVIEWER) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Assisted(com.google.inject.assistedinject.Assisted) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) PostUpdateContext(com.google.gerrit.server.update.PostUpdateContext) Objects.requireNonNull(java.util.Objects.requireNonNull) Change(com.google.gerrit.entities.Change) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Address(com.google.gerrit.entities.Address) ChangeContext(com.google.gerrit.server.update.ChangeContext) ProjectCache.illegalState(com.google.gerrit.server.project.ProjectCache.illegalState) ImmutableSet(com.google.common.collect.ImmutableSet) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) ReviewerAdded(com.google.gerrit.server.extensions.events.ReviewerAdded) Account(com.google.gerrit.entities.Account) Set(java.util.Set) IOException(java.io.IOException) Streams(com.google.common.collect.Streams) ApprovalsUtil(com.google.gerrit.server.approval.ApprovalsUtil) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) AccountState(com.google.gerrit.server.account.AccountState) PatchSetUtil(com.google.gerrit.server.PatchSetUtil) Address(com.google.gerrit.entities.Address) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal)

Aggregations

Change (com.google.gerrit.entities.Change)2 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)2 ApprovalsUtil (com.google.gerrit.server.approval.ApprovalsUtil)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Streams (com.google.common.collect.Streams)1 Account (com.google.gerrit.entities.Account)1 Address (com.google.gerrit.entities.Address)1 LabelType (com.google.gerrit.entities.LabelType)1 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)1 CC (com.google.gerrit.extensions.client.ReviewerState.CC)1 REVIEWER (com.google.gerrit.extensions.client.ReviewerState.REVIEWER)1 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 PatchSetUtil (com.google.gerrit.server.PatchSetUtil)1 AccountCache (com.google.gerrit.server.account.AccountCache)1 AccountState (com.google.gerrit.server.account.AccountState)1