use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ReplaceOp method updateChange.
@Override
public boolean updateChange(ChangeContext ctx) throws RestApiException, OrmException, IOException {
notes = ctx.getNotes();
Change change = notes.getChange();
if (change == null || change.getStatus().isClosed()) {
rejectMessage = CHANGE_IS_CLOSED;
return false;
}
if (groups.isEmpty()) {
PatchSet prevPs = psUtil.current(ctx.getDb(), notes);
groups = prevPs != null ? prevPs.getGroups() : ImmutableList.<String>of();
}
ChangeUpdate update = ctx.getUpdate(patchSetId);
update.setSubjectForCommit("Create patch set " + patchSetId.get());
String reviewMessage = null;
String psDescription = null;
if (magicBranch != null) {
recipients.add(magicBranch.getMailRecipients());
reviewMessage = magicBranch.message;
psDescription = magicBranch.message;
approvals.putAll(magicBranch.labels);
Set<String> hashtags = magicBranch.hashtags;
if (hashtags != null && !hashtags.isEmpty()) {
hashtags.addAll(notes.getHashtags());
update.setHashtags(hashtags);
}
if (magicBranch.topic != null && !magicBranch.topic.equals(ctx.getChange().getTopic())) {
update.setTopic(magicBranch.topic);
}
if (magicBranch.removePrivate) {
change.setPrivate(false);
update.setPrivate(false);
} else if (magicBranch.isPrivate) {
change.setPrivate(true);
update.setPrivate(true);
}
if (magicBranch.ready) {
change.setWorkInProgress(false);
update.setWorkInProgress(false);
} else if (magicBranch.workInProgress) {
change.setWorkInProgress(true);
update.setWorkInProgress(true);
}
if (shouldPublishComments()) {
comments = publishComments(ctx);
}
}
boolean draft = magicBranch != null && magicBranch.draft;
if (change.getStatus() == Change.Status.DRAFT && !draft) {
update.setStatus(Change.Status.NEW);
}
newPatchSet = psUtil.insert(ctx.getDb(), ctx.getRevWalk(), update, patchSetId, commitId, draft, groups, pushCertificate != null ? pushCertificate.toTextWithSignature() : null, psDescription);
update.setPsDescription(psDescription);
recipients.add(getRecipientsFromFooters(ctx.getDb(), accountResolver, draft, commit.getFooterLines()));
recipients.remove(ctx.getAccountId());
ChangeData cd = changeDataFactory.create(ctx.getDb(), ctx.getControl());
MailRecipients oldRecipients = getRecipientsFromReviewers(cd.reviewers());
Iterable<PatchSetApproval> newApprovals = approvalsUtil.addApprovalsForNewPatchSet(ctx.getDb(), update, projectControl.getLabelTypes(), newPatchSet, ctx.getControl(), approvals);
approvalCopier.copy(ctx.getDb(), ctx.getControl(), newPatchSet, newApprovals);
approvalsUtil.addReviewers(ctx.getDb(), update, projectControl.getLabelTypes(), change, newPatchSet, info, recipients.getReviewers(), oldRecipients.getAll());
// reviewer which is needed in several other code paths.
if (magicBranch != null && !magicBranch.labels.isEmpty()) {
update.putReviewer(ctx.getAccountId(), REVIEWER);
}
recipients.add(oldRecipients);
msg = createChangeMessage(ctx, reviewMessage);
cmUtil.addChangeMessage(ctx.getDb(), update, msg);
if (mergedByPushOp == null) {
resetChange(ctx);
} else {
mergedByPushOp.setPatchSetProvider(Providers.of(newPatchSet)).updateChange(ctx);
}
return true;
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class MergeOp method validateChangeList.
private BranchBatch validateChangeList(OpenRepo or, Collection<ChangeData> submitted) throws IntegrationException {
logDebug("Validating {} changes", submitted.size());
Set<CodeReviewCommit> toSubmit = new LinkedHashSet<>(submitted.size());
SetMultimap<ObjectId, PatchSet.Id> revisions = getRevisions(or, submitted);
SubmitType submitType = null;
ChangeData choseSubmitTypeFrom = null;
for (ChangeData cd : submitted) {
Change.Id changeId = cd.getId();
ChangeControl ctl;
Change chg;
try {
ctl = cd.changeControl();
chg = cd.change();
} catch (OrmException e) {
commitStatus.logProblem(changeId, e);
continue;
}
SubmitType st = getSubmitType(cd);
if (st == null) {
commitStatus.logProblem(changeId, "No submit type for change");
continue;
}
if (submitType == null) {
submitType = st;
choseSubmitTypeFrom = cd;
} else if (st != submitType) {
commitStatus.problem(changeId, String.format("Change has submit type %s, but previously chose submit type %s " + "from change %s in the same batch", st, submitType, choseSubmitTypeFrom.getId()));
continue;
}
if (chg.currentPatchSetId() == null) {
String msg = "Missing current patch set on change";
logError(msg + " " + changeId);
commitStatus.problem(changeId, msg);
continue;
}
PatchSet ps;
Branch.NameKey destBranch = chg.getDest();
try {
ps = cd.currentPatchSet();
} catch (OrmException e) {
commitStatus.logProblem(changeId, e);
continue;
}
if (ps == null || ps.getRevision() == null || ps.getRevision().get() == null) {
commitStatus.logProblem(changeId, "Missing patch set or revision on change");
continue;
}
String idstr = ps.getRevision().get();
ObjectId id;
try {
id = ObjectId.fromString(idstr);
} catch (IllegalArgumentException e) {
commitStatus.logProblem(changeId, e);
continue;
}
if (!revisions.containsEntry(id, ps.getId())) {
// TODO this is actually an error, the branch is gone but we
// want to merge the issue. We can't safely do that if the
// tip is not reachable.
//
commitStatus.logProblem(changeId, "Revision " + idstr + " of patch set " + ps.getPatchSetId() + " does not match " + ps.getId().toRefName() + " for change");
continue;
}
CodeReviewCommit commit;
try {
commit = or.rw.parseCommit(id);
} catch (IOException e) {
commitStatus.logProblem(changeId, e);
continue;
}
// TODO(dborowitz): Consider putting ChangeData in CodeReviewCommit.
commit.setControl(ctl);
commit.setPatchsetId(ps.getId());
commitStatus.put(commit);
MergeValidators mergeValidators = mergeValidatorsFactory.create();
try {
mergeValidators.validatePreMerge(or.repo, commit, or.project, destBranch, ps.getId(), caller);
} catch (MergeValidationException mve) {
commitStatus.problem(changeId, mve.getMessage());
continue;
}
commit.add(or.canMergeFlag);
toSubmit.add(commit);
}
logDebug("Submitting on this run: {}", toSubmit);
return new AutoValue_MergeOp_BranchBatch(submitType, toSubmit);
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class AbandonOp method updateChange.
@Override
public boolean updateChange(ChangeContext ctx) throws OrmException, ResourceConflictException {
change = ctx.getChange();
PatchSet.Id psId = change.currentPatchSetId();
ChangeUpdate update = ctx.getUpdate(psId);
if (!change.getStatus().isOpen()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} else if (change.getStatus() == Change.Status.DRAFT) {
throw new ResourceConflictException("draft changes cannot be abandoned");
}
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
change.setStatus(Change.Status.ABANDONED);
change.setLastUpdatedOn(ctx.getWhen());
update.setStatus(change.getStatus());
message = newMessage(ctx);
cmUtil.addChangeMessage(ctx.getDb(), update, message);
return true;
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ChangeEditModifier method merge.
private static ObjectId merge(Repository repository, ChangeEdit changeEdit, ObjectId newTreeId) throws IOException, MergeConflictException {
PatchSet basePatchSet = changeEdit.getBasePatchSet();
ObjectId basePatchSetCommitId = getPatchSetCommitId(basePatchSet);
ObjectId editCommitId = changeEdit.getEditCommit();
ThreeWayMerger threeWayMerger = MergeStrategy.RESOLVE.newMerger(repository, true);
threeWayMerger.setBase(basePatchSetCommitId);
boolean successful = threeWayMerger.merge(newTreeId, editCommitId);
if (!successful) {
throw new MergeConflictException("The existing change edit could not be merged with another tree.");
}
return threeWayMerger.getResultTreeId();
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ChangeEditModifier method createEdit.
/**
* Creates a new change edit.
*
* @param repository the affected Git repository
* @param changeControl the {@code ChangeControl} of the change for which the change edit should
* be created
* @throws AuthException if the user isn't authenticated or not allowed to use change edits
* @throws InvalidChangeOperationException if a change edit already existed for the change
* @throws PermissionBackendException
*/
public void createEdit(Repository repository, ChangeControl changeControl) throws AuthException, IOException, InvalidChangeOperationException, OrmException, PermissionBackendException {
assertCanEdit(changeControl);
Optional<ChangeEdit> changeEdit = lookupChangeEdit(changeControl);
if (changeEdit.isPresent()) {
throw new InvalidChangeOperationException(String.format("A change edit already exists for change %s", changeControl.getId()));
}
PatchSet currentPatchSet = lookupCurrentPatchSet(changeControl);
ObjectId patchSetCommitId = getPatchSetCommitId(currentPatchSet);
createEdit(repository, changeControl, currentPatchSet, patchSetCommitId, TimeUtil.nowTs());
}
Aggregations