Search in sources :

Example 6 with SubmissionId

use of com.google.gerrit.entities.SubmissionId in project gerrit by GerritCodeReview.

the class MergeOp method merge.

/**
 * Merges the given change.
 *
 * <p>Depending on the server configuration, more changes may be affected, e.g. by submission of a
 * topic or via superproject subscriptions. All affected changes are integrated using the projects
 * integration strategy.
 *
 * @param change the change to be merged.
 * @param caller the identity of the caller
 * @param checkSubmitRules whether the prolog submit rules should be evaluated
 * @param submitInput parameters regarding the merge
 * @throws RestApiException if an error occurred.
 * @throws PermissionBackendException if permissions can't be checked
 * @throws IOException an error occurred reading from NoteDb.
 * @return the merged change
 */
public Change merge(Change change, IdentifiedUser caller, boolean checkSubmitRules, SubmitInput submitInput, boolean dryrun) throws RestApiException, UpdateException, IOException, ConfigInvalidException, PermissionBackendException {
    this.submitInput = submitInput;
    this.notify = notifyResolver.resolve(firstNonNull(submitInput.notify, NotifyHandling.ALL), submitInput.notifyDetails);
    this.dryrun = dryrun;
    this.caller = caller;
    this.ts = TimeUtil.now();
    this.submissionId = new SubmissionId(change);
    try (TraceContext traceContext = TraceContext.open().addTag(RequestId.Type.SUBMISSION_ID, new RequestId(submissionId.toString()))) {
        openRepoManager();
        logger.atFine().log("Beginning integration of %s", change);
        try {
            ChangeSet indexBackedChangeSet = mergeSuperSet.setMergeOpRepoManager(orm).completeChangeSet(change, caller, /* includingTopicClosure= */
            false);
            if (!indexBackedChangeSet.ids().contains(change.getId())) {
                // indexBackedChangeSet contains only open changes, if the change is missing in this set
                // it might be that the change was concurrently submitted in the meantime.
                change = changeDataFactory.create(change).reloadChange();
                if (!change.isNew()) {
                    throw new ResourceConflictException("change is " + ChangeUtil.status(change));
                }
                throw new IllegalStateException(String.format("change %s missing from %s", change.getId(), indexBackedChangeSet));
            }
            if (indexBackedChangeSet.furtherHiddenChanges()) {
                throw new AuthException("A change to be submitted with " + change.getId() + " is not visible");
            }
            logger.atFine().log("Calculated to merge %s", indexBackedChangeSet);
            // Reload ChangeSet so that we don't rely on (potentially) stale index data for merging
            ChangeSet noteDbChangeSet = reloadChanges(indexBackedChangeSet);
            // At this point, any change that isn't new can be filtered out since they were only here
            // in the first place due to stale index.
            List<ChangeData> filteredChanges = new ArrayList<>();
            for (ChangeData changeData : noteDbChangeSet.changes()) {
                if (!changeData.change().getStatus().equals(Status.NEW)) {
                    logger.atFine().log("Change %s has status %s due to stale index, so it is skipped during submit", changeData.getId(), changeData.change().getStatus().name());
                    continue;
                }
                filteredChanges.add(changeData);
            }
            // There are no hidden changes (or else we would have thrown AuthException above).
            ChangeSet filteredNoteDbChangeSet = new ChangeSet(filteredChanges, /* hiddenChanges= */
            ImmutableList.of());
            // Count cross-project submissions outside of the retry loop. The chance of a single project
            // failing increases with the number of projects, so the failure count would be inflated if
            // this metric were incremented inside of integrateIntoHistory.
            int projects = filteredNoteDbChangeSet.projects().size();
            if (projects > 1) {
                topicMetrics.topicSubmissions.increment();
            }
            SubmissionExecutor submissionExecutor = new SubmissionExecutor(dryrun, superprojectUpdateSubmissionListeners);
            RetryTracker retryTracker = new RetryTracker();
            retryHelper.changeUpdate("integrateIntoHistory", updateFactory -> {
                long attempt = retryTracker.lastAttemptNumber + 1;
                boolean isRetry = attempt > 1;
                if (isRetry) {
                    logger.atFine().log("Retrying, attempt #%d; skipping merged changes", attempt);
                    this.ts = TimeUtil.now();
                    openRepoManager();
                }
                this.commitStatus = new CommitStatus(filteredNoteDbChangeSet, isRetry);
                if (checkSubmitRules) {
                    logger.atFine().log("Checking submit rules and state");
                    checkSubmitRulesAndState(filteredNoteDbChangeSet, isRetry);
                } else {
                    logger.atFine().log("Bypassing submit rules");
                    bypassSubmitRulesAndRequirements(filteredNoteDbChangeSet);
                }
                integrateIntoHistory(filteredNoteDbChangeSet, submissionExecutor);
                return null;
            }).listener(retryTracker).defaultTimeoutMultiplier(filteredNoteDbChangeSet.projects().size() * 2).retryOn(t -> t instanceof RuntimeException).call();
            submissionExecutor.afterExecutions(orm);
            if (projects > 1) {
                topicMetrics.topicSubmissionsCompleted.increment();
            }
            // (e.g. caller provided a change that was already merged).
            return updatedChanges.containsKey(change.getId()) ? updatedChanges.get(change.getId()) : change;
        } catch (IOException e) {
            // Anything before the merge attempt is an error
            throw new StorageException(e);
        }
    }
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) SuperprojectUpdateOnSubmission(com.google.gerrit.server.update.SuperprojectUpdateOnSubmission) ListMultimap(com.google.common.collect.ListMultimap) MultimapBuilder(com.google.common.collect.MultimapBuilder) InternalUser(com.google.gerrit.server.InternalUser) Inject(com.google.inject.Inject) SubmissionId(com.google.gerrit.entities.SubmissionId) UpdateException(com.google.gerrit.server.update.UpdateException) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) Map(java.util.Map) AuthException(com.google.gerrit.extensions.restapi.AuthException) StoreSubmitRequirementsOp(com.google.gerrit.server.notedb.StoreSubmitRequirementsOp) RetryHelper(com.google.gerrit.server.update.RetryHelper) MergeTip(com.google.gerrit.server.git.MergeTip) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableSet(com.google.common.collect.ImmutableSet) Status(com.google.gerrit.entities.Change.Status) ImmutableMap(com.google.common.collect.ImmutableMap) TraceContext(com.google.gerrit.server.logging.TraceContext) SubmitType(com.google.gerrit.extensions.client.SubmitType) Collection(java.util.Collection) Set(java.util.Set) Constants(org.eclipse.jgit.lib.Constants) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit) Instant(java.time.Instant) RetryListener(com.github.rholder.retry.RetryListener) SubmitRecord(com.google.gerrit.entities.SubmitRecord) Collectors(java.util.stream.Collectors) BranchNameKey(com.google.gerrit.entities.BranchNameKey) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) SubmitTypeRecord(com.google.gerrit.entities.SubmitTypeRecord) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) Ref(org.eclipse.jgit.lib.Ref) AutoValue(com.google.auto.value.AutoValue) InternalChangeQuery(com.google.gerrit.server.query.change.InternalChangeQuery) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) Counter0(com.google.gerrit.metrics.Counter0) MetricMaker(com.google.gerrit.metrics.MetricMaker) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) FluentLogger(com.google.common.flogger.FluentLogger) Joiner(com.google.common.base.Joiner) ChangeMessagesUtil(com.google.gerrit.server.ChangeMessagesUtil) Singleton(com.google.inject.Singleton) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) OpenRepo(com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) HashMap(java.util.HashMap) Function(java.util.function.Function) SubmissionListener(com.google.gerrit.server.update.SubmissionListener) MergeValidators(com.google.gerrit.server.git.validators.MergeValidators) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) SubmissionExecutor(com.google.gerrit.server.update.SubmissionExecutor) Description(com.google.gerrit.metrics.Description) Objects.requireNonNull(java.util.Objects.requireNonNull) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) Comparator.comparing(java.util.Comparator.comparing) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ChangeUtil(com.google.gerrit.server.ChangeUtil) LockFailureException(com.google.gerrit.git.LockFailureException) ChangeContext(com.google.gerrit.server.update.ChangeContext) MergeValidationException(com.google.gerrit.server.git.validators.MergeValidationException) LinkedHashSet(java.util.LinkedHashSet) SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) NotifyResolver(com.google.gerrit.server.change.NotifyResolver) OpenBranch(com.google.gerrit.server.submit.MergeOpRepoManager.OpenBranch) StorageException(com.google.gerrit.exceptions.StorageException) Attempt(com.github.rholder.retry.Attempt) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) SubmitRuleOptions(com.google.gerrit.server.project.SubmitRuleOptions) SetMultimap(com.google.common.collect.SetMultimap) ObjectId(org.eclipse.jgit.lib.ObjectId) Provider(com.google.inject.Provider) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) Project(com.google.gerrit.entities.Project) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) RequestId(com.google.gerrit.server.logging.RequestId) RequestId(com.google.gerrit.server.logging.RequestId) ArrayList(java.util.ArrayList) AuthException(com.google.gerrit.extensions.restapi.AuthException) IOException(java.io.IOException) ChangeData(com.google.gerrit.server.query.change.ChangeData) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) SubmissionId(com.google.gerrit.entities.SubmissionId) TraceContext(com.google.gerrit.server.logging.TraceContext) StorageException(com.google.gerrit.exceptions.StorageException) SubmissionExecutor(com.google.gerrit.server.update.SubmissionExecutor)

Example 7 with SubmissionId

use of com.google.gerrit.entities.SubmissionId in project gerrit by GerritCodeReview.

the class CommitMessageOutputTest method submitCommitFormat.

@Test
// Instants
@SuppressWarnings("JdkObsolete")
public void submitCommitFormat() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setSubjectForCommit("Submit patch set 1");
    SubmissionId submissionId = new SubmissionId(c);
    update.merge(submissionId, ImmutableList.of(submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel(LabelId.CODE_REVIEW, "NEED", null)), submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel("Alternative-Code-Review", "NEED", null))));
    update.commit();
    RevCommit commit = parseCommit(update.getResult());
    assertBodyEquals("Submit patch set 1\n" + "\n" + "Patch-set: 1\n" + "Status: merged\n" + "Submission-id: " + submissionId.toString() + "\n" + "Submitted-with: NOT_READY\n" + "Submitted-with: OK: Verified: Gerrit User 1 <1@gerrit>\n" + "Submitted-with: NEED: Code-Review\n" + "Submitted-with: NOT_READY\n" + "Submitted-with: OK: Verified: Gerrit User 1 <1@gerrit>\n" + "Submitted-with: NEED: Alternative-Code-Review\n", commit);
    PersonIdent author = commit.getAuthorIdent();
    assertThat(author.getName()).isEqualTo("Gerrit User 1");
    assertThat(author.getEmailAddress()).isEqualTo("1@gerrit");
    assertThat(author.getWhen().getTime()).isEqualTo(c.getCreatedOn().toEpochMilli() + 2000);
    assertThat(author.getTimeZone()).isEqualTo(TimeZone.getTimeZone("GMT-7:00"));
    PersonIdent committer = commit.getCommitterIdent();
    assertThat(committer.getName()).isEqualTo("Gerrit Server");
    assertThat(committer.getEmailAddress()).isEqualTo("noreply@gerrit.com");
    assertThat(committer.getWhen().getTime()).isEqualTo(author.getWhen().getTime());
    assertThat(committer.getTimeZone()).isEqualTo(author.getTimeZone());
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 8 with SubmissionId

use of com.google.gerrit.entities.SubmissionId in project gerrit by GerritCodeReview.

the class ChangeInserter method updateChange.

@Override
public boolean updateChange(ChangeContext ctx) throws RestApiException, IOException, PermissionBackendException, ConfigInvalidException {
    // Use defensive copy created by ChangeControl.
    change = ctx.getChange();
    patchSetInfo = patchSetInfoFactory.get(ctx.getRevWalk(), ctx.getRevWalk().parseCommit(commitId), psId);
    ctx.getChange().setCurrentPatchSet(patchSetInfo);
    ChangeUpdate update = ctx.getUpdate(psId);
    update.setChangeId(change.getKey().get());
    update.setSubjectForCommit("Create change");
    update.setBranch(change.getDest().branch());
    try {
        update.setTopic(change.getTopic());
    } catch (ValidationException ex) {
        throw new BadRequestException(ex.getMessage());
    }
    update.setPsDescription(patchSetDescription);
    update.setPrivate(isPrivate);
    update.setWorkInProgress(workInProgress);
    if (revertOf != null) {
        update.setRevertOf(revertOf.get());
    }
    if (cherryPickOf != null) {
        update.setCherryPickOf(cherryPickOf.getCommaSeparatedChangeAndPatchSetId());
    }
    List<String> newGroups = groups;
    if (newGroups.isEmpty()) {
        newGroups = GroupCollector.getDefaultGroups(commitId);
    }
    patchSet = psUtil.insert(ctx.getRevWalk(), update, psId, commitId, newGroups, pushCert, patchSetDescription);
    /* TODO: fixStatusToMerged is used here because the tests
     * (byStatusClosed() in AbstractQueryChangesTest)
     * insert changes that are already merged,
     * and setStatus may not be used to set the Status to merged
     *
     * is it possible to make the tests use the merge code path,
     * instead of setting the status directly?
     */
    if (change.getStatus() == Change.Status.MERGED) {
        update.fixStatusToMerged(new SubmissionId(change));
    } else {
        update.setStatus(change.getStatus());
    }
    reviewerAdditions = reviewerModifier.prepare(ctx.getNotes(), ctx.getUser(), getReviewerInputs(), true);
    Optional<ReviewerModification> reviewerError = reviewerAdditions.getFailures().stream().findFirst();
    if (reviewerError.isPresent()) {
        throw new UnprocessableEntityException(reviewerError.get().result.error);
    }
    reviewerAdditions.updateChange(ctx, patchSet);
    LabelTypes labelTypes = projectState.getLabelTypes();
    approvalsUtil.addApprovalsForNewPatchSet(update, labelTypes, patchSet, ctx.getUser(), approvals);
    // TODO(dborowitz): Still necessary?
    if (!approvals.isEmpty()) {
        update.putReviewer(ctx.getAccountId(), REVIEWER);
    }
    if (message != null) {
        changeMessage = cmUtil.setChangeMessage(update, message, ChangeMessagesUtil.uploadedPatchSetTag(workInProgress));
    }
    return true;
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) LabelTypes(com.google.gerrit.entities.LabelTypes) CommitValidationException(com.google.gerrit.server.git.validators.CommitValidationException) ValidationException(com.google.gerrit.server.validators.ValidationException) SubmissionId(com.google.gerrit.entities.SubmissionId) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ReviewerModification(com.google.gerrit.server.change.ReviewerModifier.ReviewerModification) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate)

Example 9 with SubmissionId

use of com.google.gerrit.entities.SubmissionId in project gerrit by GerritCodeReview.

the class ReceiveCommits method autoCloseChanges.

private void autoCloseChanges(ReceiveCommand cmd, Task progress) {
    try (TraceTimer traceTimer = newTimer("autoCloseChanges")) {
        logger.atFine().log("Starting auto-closing of changes");
        String refName = cmd.getRefName();
        Set<Change.Id> ids = new HashSet<>();
        // handleRegularCommands
        try {
            retryHelper.changeUpdate("autoCloseChanges", updateFactory -> {
                try (BatchUpdate bu = updateFactory.create(projectState.getNameKey(), user, TimeUtil.now());
                    ObjectInserter ins = repo.newObjectInserter();
                    ObjectReader reader = ins.newReader();
                    RevWalk rw = new RevWalk(reader)) {
                    if (ObjectId.zeroId().equals(cmd.getOldId())) {
                        // potentially expensive computation that loop over all commits.
                        return null;
                    }
                    bu.setRepository(repo, rw, ins);
                    // TODO(dborowitz): Teach BatchUpdate to ignore missing changes.
                    RevCommit newTip = rw.parseCommit(cmd.getNewId());
                    BranchNameKey branch = BranchNameKey.create(project.getNameKey(), refName);
                    rw.reset();
                    rw.sort(RevSort.REVERSE);
                    rw.markStart(newTip);
                    rw.markUninteresting(rw.parseCommit(cmd.getOldId()));
                    Map<Change.Key, ChangeNotes> byKey = null;
                    List<ReplaceRequest> replaceAndClose = new ArrayList<>();
                    int existingPatchSets = 0;
                    int newPatchSets = 0;
                    SubmissionId submissionId = null;
                    COMMIT: for (RevCommit c; (c = rw.next()) != null; ) {
                        rw.parseBody(c);
                        // refs pointing to this commit.
                        for (PatchSet.Id psId : receivePackRefCache.patchSetIdsFromObjectId(c.copy())) {
                            Optional<ChangeNotes> notes = getChangeNotes(psId.changeId());
                            if (notes.isPresent() && notes.get().getChange().getDest().equals(branch)) {
                                if (submissionId == null) {
                                    submissionId = new SubmissionId(notes.get().getChange());
                                }
                                existingPatchSets++;
                                bu.addOp(notes.get().getChangeId(), setPrivateOpFactory.create(false, null));
                                bu.addOp(psId.changeId(), mergedByPushOpFactory.create(requestScopePropagator, psId, submissionId, refName, newTip.getId().getName()));
                                continue COMMIT;
                            }
                        }
                        for (String changeId : ChangeUtil.getChangeIdsFromFooter(c, urlFormatter.get())) {
                            if (byKey == null) {
                                byKey = retryHelper.changeIndexQuery("queryOpenChangesByKeyByBranch", q -> openChangesByKeyByBranch(q, branch)).call();
                            }
                            ChangeNotes onto = byKey.get(Change.key(changeId.trim()));
                            if (onto != null) {
                                newPatchSets++;
                                // Hold onto this until we're done with the walk, as the call to
                                // req.validate below calls isMergedInto which resets the walk.
                                ReplaceRequest req = new ReplaceRequest(onto.getChangeId(), c, cmd, false);
                                req.notes = onto;
                                replaceAndClose.add(req);
                                continue COMMIT;
                            }
                        }
                    }
                    for (ReplaceRequest req : replaceAndClose) {
                        Change.Id id = req.notes.getChangeId();
                        if (!req.validateNewPatchSetForAutoClose()) {
                            logger.atFine().log("Not closing %s because validation failed", id);
                            continue;
                        }
                        if (submissionId == null) {
                            submissionId = new SubmissionId(req.notes.getChange());
                        }
                        req.addOps(bu, null);
                        bu.addOp(id, setPrivateOpFactory.create(false, null));
                        bu.addOp(id, mergedByPushOpFactory.create(requestScopePropagator, req.psId, submissionId, refName, newTip.getId().getName()).setPatchSetProvider(req.replaceOp::getPatchSet));
                        bu.addOp(id, new ChangeProgressOp(progress));
                        ids.add(id);
                    }
                    logger.atFine().log("Auto-closing %d changes with existing patch sets and %d with new patch" + " sets", existingPatchSets, newPatchSets);
                    bu.execute();
                } catch (IOException | StorageException | PermissionBackendException e) {
                    throw new StorageException("Failed to auto-close changes", e);
                }
                // If we are here, we didn't throw UpdateException. Record the result.
                // The ordering is indeterminate due to the HashSet; unfortunately, Change.Id
                // doesn't
                // fit into TreeSet.
                ids.stream().forEach(id -> result.addChange(ReceiveCommitsResult.ChangeStatus.AUTOCLOSED, id));
                return null;
            }).defaultTimeoutMultiplier(5).call();
        } catch (RestApiException e) {
            logger.atSevere().withCause(e).log("Can't insert patchset");
        } catch (UpdateException e) {
            logger.atSevere().withCause(e).log("Failed to auto-close changes");
        } finally {
            logger.atFine().log("Done auto-closing changes");
        }
    }
}
Also used : NotifyInfo(com.google.gerrit.extensions.api.changes.NotifyInfo) DynamicItem(com.google.gerrit.extensions.registration.DynamicItem) MultimapBuilder(com.google.common.collect.MultimapBuilder) ChangeReportFormatter(com.google.gerrit.server.git.ChangeReportFormatter) DeadlineChecker(com.google.gerrit.server.DeadlineChecker) ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) RevObject(org.eclipse.jgit.revwalk.RevObject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) HashtagsInput(com.google.gerrit.extensions.api.changes.HashtagsInput) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Config(org.eclipse.jgit.lib.Config) Future(java.util.concurrent.Future) FooterLine(org.eclipse.jgit.revwalk.FooterLine) Map(java.util.Map) UrlFormatter(com.google.gerrit.server.config.UrlFormatter) Metadata(com.google.gerrit.server.logging.Metadata) MailRecipients(com.google.gerrit.server.mail.MailUtil.MailRecipients) RevSort(org.eclipse.jgit.revwalk.RevSort) Constants(org.eclipse.jgit.lib.Constants) PublishCommentsOp(com.google.gerrit.server.PublishCommentsOp) Collectors.joining(java.util.stream.Collectors.joining) RequestListener(com.google.gerrit.server.RequestListener) PersonIdent(org.eclipse.jgit.lib.PersonIdent) TagCache(com.google.gerrit.server.git.TagCache) Stream(java.util.stream.Stream) HashtagsUtil.cleanupHashtag(com.google.gerrit.server.change.HashtagsUtil.cleanupHashtag) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig) Counter3(com.google.gerrit.metrics.Counter3) PluginSetContext(com.google.gerrit.server.plugincontext.PluginSetContext) ProjectConfigEntryType(com.google.gerrit.extensions.api.projects.ProjectConfigEntryType) Counter0(com.google.gerrit.metrics.Counter0) MetricMaker(com.google.gerrit.metrics.MetricMaker) PatchSetInfo(com.google.gerrit.entities.PatchSetInfo) FluentLogger(com.google.common.flogger.FluentLogger) Joiner(com.google.common.base.Joiner) ValidationError(com.google.gerrit.server.git.ValidationError) SAME_CHANGE_ID_IN_MULTIPLE_CHANGES(com.google.gerrit.server.git.receive.ReceiveConstants.SAME_CHANGE_ID_IN_MULTIPLE_CHANGES) RevCommit(org.eclipse.jgit.revwalk.RevCommit) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) CommentsUtil(com.google.gerrit.server.CommentsUtil) RequestScopePropagator(com.google.gerrit.server.util.RequestScopePropagator) PerformanceLogger(com.google.gerrit.server.logging.PerformanceLogger) LinkedHashMap(java.util.LinkedHashMap) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) SubmissionExecutor(com.google.gerrit.server.update.SubmissionExecutor) Description(com.google.gerrit.metrics.Description) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) StreamSupport(java.util.stream.StreamSupport) MagicBranch(com.google.gerrit.server.util.MagicBranch) ProjectCache.illegalState(com.google.gerrit.server.project.ProjectCache.illegalState) NotifyResolver(com.google.gerrit.server.change.NotifyResolver) ObjectIds.abbreviateName(com.google.gerrit.git.ObjectIds.abbreviateName) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ChangeEdit(com.google.gerrit.server.edit.ChangeEdit) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) Project(com.google.gerrit.entities.Project) DynamicSet(com.google.gerrit.extensions.registration.DynamicSet) NOT_ATTEMPTED(org.eclipse.jgit.transport.ReceiveCommand.Result.NOT_ATTEMPTED) LabelVote(com.google.gerrit.server.util.LabelVote) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) CommentValidator(com.google.gerrit.extensions.validators.CommentValidator) ONLY_USERS_WITH_TOGGLE_WIP_STATE_PERM_CAN_MODIFY_WIP(com.google.gerrit.server.git.receive.ReceiveConstants.ONLY_USERS_WITH_TOGGLE_WIP_STATE_PERM_CAN_MODIFY_WIP) RequestCancelledException(com.google.gerrit.server.cancellation.RequestCancelledException) RequestId(com.google.gerrit.server.logging.RequestId) REJECTED_MISSING_OBJECT(org.eclipse.jgit.transport.ReceiveCommand.Result.REJECTED_MISSING_OBJECT) CommentSizeValidator(com.google.gerrit.server.git.validators.CommentSizeValidator) RefPermission(com.google.gerrit.server.permissions.RefPermission) PUSH_OPTION_SKIP_VALIDATION(com.google.gerrit.server.git.receive.ReceiveConstants.PUSH_OPTION_SKIP_VALIDATION) URLDecoder(java.net.URLDecoder) ValidationMessage(com.google.gerrit.server.git.validators.ValidationMessage) Inject(com.google.inject.Inject) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) RepoOnlyOp(com.google.gerrit.server.update.RepoOnlyOp) PatchSetInfoFactory(com.google.gerrit.server.patch.PatchSetInfoFactory) UpdateException(com.google.gerrit.server.update.UpdateException) Assisted(com.google.inject.assistedinject.Assisted) ImmutableListMultimap.toImmutableListMultimap(com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap) LabelType(com.google.gerrit.entities.LabelType) AuthException(com.google.gerrit.extensions.restapi.AuthException) AutoMerger(com.google.gerrit.server.patch.AutoMerger) PerformanceLogContext(com.google.gerrit.server.logging.PerformanceLogContext) PluginConfig(com.google.gerrit.server.config.PluginConfig) NoteMap(org.eclipse.jgit.notes.NoteMap) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) CommentCountValidator(com.google.gerrit.server.git.validators.CommentCountValidator) BiMap(com.google.common.collect.BiMap) ImmutableSet(com.google.common.collect.ImmutableSet) SortedSetMultimap(com.google.common.collect.SortedSetMultimap) Collection(java.util.Collection) OK(org.eclipse.jgit.transport.ReceiveCommand.Result.OK) PermissionDeniedException(com.google.gerrit.server.permissions.PermissionDeniedException) Collectors(java.util.stream.Collectors) ApprovalsUtil(com.google.gerrit.server.approval.ApprovalsUtil) Objects(java.util.Objects) CmdLineException(org.kohsuke.args4j.CmdLineException) SetPrivateOp(com.google.gerrit.server.change.SetPrivateOp) ChangeData(com.google.gerrit.server.query.change.ChangeData) Nullable(com.google.gerrit.common.Nullable) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) Ref(org.eclipse.jgit.lib.Ref) InternalChangeQuery(com.google.gerrit.server.query.change.InternalChangeQuery) Providers(com.google.inject.util.Providers) Queue(java.util.Queue) RefNames.isConfigRef(com.google.gerrit.entities.RefNames.isConfigRef) RequestStateContext(com.google.gerrit.server.cancellation.RequestStateContext) CommentValidationContext(com.google.gerrit.extensions.validators.CommentValidationContext) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) RepoContext(com.google.gerrit.server.update.RepoContext) MergedByPushOp(com.google.gerrit.server.git.MergedByPushOp) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) REFS_CHANGES(com.google.gerrit.entities.RefNames.REFS_CHANGES) Field(com.google.gerrit.metrics.Field) UsedAt(com.google.gerrit.common.UsedAt) Change(com.google.gerrit.entities.Change) ChangeUtil(com.google.gerrit.server.ChangeUtil) ChangeContext(com.google.gerrit.server.update.ChangeContext) SetTopicOp(com.google.gerrit.server.change.SetTopicOp) SetHashtagsOp(com.google.gerrit.server.change.SetHashtagsOp) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ProjectState(com.google.gerrit.server.project.ProjectState) Collectors.toList(java.util.stream.Collectors.toList) HashBiMap(com.google.common.collect.HashBiMap) Provider(com.google.inject.Provider) ReceivePack(org.eclipse.jgit.transport.ReceivePack) SuperprojectUpdateOnSubmission(com.google.gerrit.server.update.SuperprojectUpdateOnSubmission) Arrays(java.util.Arrays) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) ListMultimap(com.google.common.collect.ListMultimap) GroupCollector(com.google.gerrit.server.git.GroupCollector) ProjectCache(com.google.gerrit.server.project.ProjectCache) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) InvalidDeadlineException(com.google.gerrit.server.InvalidDeadlineException) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) RetryHelper(com.google.gerrit.server.update.RetryHelper) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) TraceContext(com.google.gerrit.server.logging.TraceContext) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) BranchNameKey(com.google.gerrit.entities.BranchNameKey) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) ProjectPermission(com.google.gerrit.server.permissions.ProjectPermission) NEW_PATCHSET_PATTERN(com.google.gerrit.server.git.validators.CommitValidators.NEW_PATCHSET_PATTERN) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) LazyArgs.lazy(com.google.common.flogger.LazyArgs.lazy) Singleton(com.google.inject.Singleton) Iterables(com.google.common.collect.Iterables) CommentType(com.google.gerrit.extensions.validators.CommentForValidation.CommentType) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RefOperationValidationException(com.google.gerrit.server.git.validators.RefOperationValidationException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) CommentForValidation(com.google.gerrit.extensions.validators.CommentForValidation) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) CancellationMetrics(com.google.gerrit.server.CancellationMetrics) SubmissionListener(com.google.gerrit.server.update.SubmissionListener) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ChangeEditUtil(com.google.gerrit.server.edit.ChangeEditUtil) PatchSet(com.google.gerrit.entities.PatchSet) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Extension(com.google.gerrit.extensions.registration.Extension) LinkedHashSet(java.util.LinkedHashSet) UNKNOWN(com.google.gerrit.server.git.MultiProgressMonitor.UNKNOWN) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Sequences(com.google.gerrit.server.notedb.Sequences) CreateRefControl(com.google.gerrit.server.project.CreateRefControl) RevFilter(org.eclipse.jgit.revwalk.filter.RevFilter) AttentionSetUnchangedOp(com.google.gerrit.server.change.AttentionSetUnchangedOp) StorageException(com.google.gerrit.exceptions.StorageException) StringWriter(java.io.StringWriter) CommentValidationFailure(com.google.gerrit.extensions.validators.CommentValidationFailure) CmdLineParser(com.google.gerrit.util.cli.CmdLineParser) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) R_HEADS(org.eclipse.jgit.lib.Constants.R_HEADS) RefOperationValidators(com.google.gerrit.server.git.validators.RefOperationValidators) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) ObjectReader(org.eclipse.jgit.lib.ObjectReader) Repository(org.eclipse.jgit.lib.Repository) REJECTED_OTHER_REASON(org.eclipse.jgit.transport.ReceiveCommand.Result.REJECTED_OTHER_REASON) MailUtil.getRecipientsFromFooters(com.google.gerrit.server.mail.MailUtil.getRecipientsFromFooters) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) HumanComment(com.google.gerrit.entities.HumanComment) SubmissionId(com.google.gerrit.entities.SubmissionId) RefNames.isRefsUsersSelf(com.google.gerrit.entities.RefNames.isRefsUsersSelf) LabelTypes(com.google.gerrit.entities.LabelTypes) ChangeIndexer(com.google.gerrit.server.index.change.ChangeIndexer) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) RefNames(com.google.gerrit.entities.RefNames) COMMAND_REJECTION_MESSAGE_FOOTER(com.google.gerrit.server.git.receive.ReceiveConstants.COMMAND_REJECTION_MESSAGE_FOOTER) Splitter(com.google.common.base.Splitter) ReceivePackInitializer(com.google.gerrit.server.git.ReceivePackInitializer) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) GlobalPermission(com.google.gerrit.server.permissions.GlobalPermission) Task(com.google.gerrit.server.git.MultiProgressMonitor.Task) ImmutableMap(com.google.common.collect.ImmutableMap) Account(com.google.gerrit.entities.Account) RequestInfo(com.google.gerrit.server.RequestInfo) ProjectConfigEntry(com.google.gerrit.server.config.ProjectConfigEntry) Option(org.kohsuke.args4j.Option) Streams(com.google.common.collect.Streams) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) BanCommit(com.google.gerrit.server.git.BanCommit) CommentSource(com.google.gerrit.extensions.validators.CommentForValidation.CommentSource) PublishCommentUtil(com.google.gerrit.server.PublishCommentUtil) MultiProgressMonitor(com.google.gerrit.server.git.MultiProgressMonitor) MergeOpRepoManager(com.google.gerrit.server.submit.MergeOpRepoManager) ChangePermission(com.google.gerrit.server.permissions.ChangePermission) CreateGroupPermissionSyncer(com.google.gerrit.server.CreateGroupPermissionSyncer) HashMap(java.util.HashMap) ReplyAttentionSetUpdates(com.google.gerrit.server.restapi.change.ReplyAttentionSetUpdates) MergeOp(com.google.gerrit.server.submit.MergeOp) PostUpdateContext(com.google.gerrit.server.update.PostUpdateContext) Objects.requireNonNull(java.util.Objects.requireNonNull) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) AccountResolver(com.google.gerrit.server.account.AccountResolver) Iterator(java.util.Iterator) Maps(com.google.common.collect.Maps) ObjectId(org.eclipse.jgit.lib.ObjectId) RecipientType(com.google.gerrit.extensions.api.changes.RecipientType) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) PatchSetUtil(com.google.gerrit.server.PatchSetUtil) Collections(java.util.Collections) ArrayList(java.util.ArrayList) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) BranchNameKey(com.google.gerrit.entities.BranchNameKey) ObjectReader(org.eclipse.jgit.lib.ObjectReader) UpdateException(com.google.gerrit.server.update.UpdateException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Optional(java.util.Optional) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) Change(com.google.gerrit.entities.Change) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) SubmissionId(com.google.gerrit.entities.SubmissionId) RequestId(com.google.gerrit.server.logging.RequestId) SubmissionId(com.google.gerrit.entities.SubmissionId) ObjectId(org.eclipse.jgit.lib.ObjectId) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) StorageException(com.google.gerrit.exceptions.StorageException) BranchNameKey(com.google.gerrit.entities.BranchNameKey)

Example 10 with SubmissionId

use of com.google.gerrit.entities.SubmissionId in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method mergedChangeIsNotMerged.

@Test
public void mergedChangeIsNotMerged() throws Exception {
    ChangeNotes notes = insertChange();
    try (BatchUpdate bu = newUpdate(adminId)) {
        bu.addOp(notes.getChangeId(), new BatchUpdateOp() {

            @Override
            public boolean updateChange(ChangeContext ctx) {
                ctx.getChange().setStatus(Change.Status.MERGED);
                ctx.getUpdate(ctx.getChange().currentPatchSetId()).fixStatusToMerged(new SubmissionId(ctx.getChange()));
                return true;
            }
        });
        bu.execute();
    }
    notes = reload(notes);
    ObjectId tip = getDestRef(notes);
    assertProblems(notes, null, problem("Patch set 1 (" + psUtil.current(notes).commitId().name() + ") is not merged into destination ref" + " refs/heads/master (" + tip.name() + "), but change status is MERGED"));
}
Also used : ChangeContext(com.google.gerrit.server.update.ChangeContext) ObjectId(org.eclipse.jgit.lib.ObjectId) SubmissionId(com.google.gerrit.entities.SubmissionId) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

SubmissionId (com.google.gerrit.entities.SubmissionId)18 Change (com.google.gerrit.entities.Change)13 Test (org.junit.Test)12 ObjectId (org.eclipse.jgit.lib.ObjectId)5 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)4 Instant (java.time.Instant)4 Joiner (com.google.common.base.Joiner)3 SubmitRecord (com.google.gerrit.entities.SubmitRecord)3 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)3 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)3 ChangeContext (com.google.gerrit.server.update.ChangeContext)3 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)2 ListMultimap (com.google.common.collect.ListMultimap)2 MultimapBuilder (com.google.common.collect.MultimapBuilder)2 Account (com.google.gerrit.entities.Account)2 LabelTypes (com.google.gerrit.entities.LabelTypes)2