Option for SSHD review-cmd to always publish the message.

"--force-message" option for the SSHD review command,
which allows Gerrit to publish the "--message", even if the
labels could not be applied due to change being closed.

Used by some scripts/CI-systems, where the results (or links
to the result) are posted as a message after completion of a
build (often together with a label-change, indicating the
success of the build).

If the message is posted successfully, the cmd will return
successfully, even if the label could not be changed.

Change-Id: Ic2d5fc25ba97ddcedce832c7444e4f07512c761c
This commit is contained in:
Gustaf Lundh
2011-11-01 15:19:13 -07:00
committed by Shawn O. Pearce
parent 6cc0abd4ca
commit 1fbf2c28a0
4 changed files with 28 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ SYNOPSIS
'ssh' -p <port> <host> 'gerrit review'
[--project <PROJECT>]
[--message <MESSAGE>]
[--force-message]
[--submit]
[--abandon | --restore]
[--verified <N>] [--code-review <N>]
@@ -47,6 +48,19 @@ OPTIONS
Optional cover letter to include as part of the message
sent to reviewers when the approval states are updated.
--force-message::
Option which allows Gerrit to publish the --message, even
when the labels could not be applied due to change being
closed).
+
Used by some scripts/CI-systems, where the results (or links
to the result) are posted as a message after completion of a
build (often together with a label-change, indicating the success
of the build).
+
If the message is posted successfully, the cmd will return
successfully, even if the label could not be changed.
--help::
-h::
Display site-specific usage information, including the

View File

@@ -136,7 +136,7 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements
public void publishComments(final PatchSet.Id psid, final String msg,
final Set<ApprovalCategoryValue.Id> tags,
final AsyncCallback<VoidResult> cb) {
Handler.wrap(publishCommentsFactory.create(psid, msg, tags)).to(cb);
Handler.wrap(publishCommentsFactory.create(psid, msg, tags, false)).to(cb);
}
/**

View File

@@ -57,7 +57,7 @@ public class PublishComments implements Callable<VoidResult> {
public interface Factory {
PublishComments create(PatchSet.Id patchSetId, String messageText,
Set<ApprovalCategoryValue.Id> approvals);
Set<ApprovalCategoryValue.Id> approvals, boolean forceMessage);
}
private final ReviewDb db;
@@ -72,6 +72,7 @@ public class PublishComments implements Callable<VoidResult> {
private final PatchSet.Id patchSetId;
private final String messageText;
private final Set<ApprovalCategoryValue.Id> approvals;
private final boolean forceMessage;
private Change change;
private PatchSet patchSet;
@@ -89,7 +90,8 @@ public class PublishComments implements Callable<VoidResult> {
@Assisted final PatchSet.Id patchSetId,
@Assisted final String messageText,
@Assisted final Set<ApprovalCategoryValue.Id> approvals) {
@Assisted final Set<ApprovalCategoryValue.Id> approvals,
@Assisted final boolean forceMessage) {
this.db = db;
this.user = user;
this.types = approvalTypes;
@@ -102,6 +104,7 @@ public class PublishComments implements Callable<VoidResult> {
this.patchSetId = patchSetId;
this.messageText = messageText;
this.approvals = approvals;
this.forceMessage = forceMessage;
}
@Override
@@ -123,10 +126,10 @@ public class PublishComments implements Callable<VoidResult> {
final boolean isCurrent = patchSetId.equals(change.currentPatchSetId());
if (isCurrent && change.getStatus().isOpen()) {
publishApprovals(ctl);
} else if (!approvals.isEmpty()) {
throw new InvalidChangeOperationException("Change is closed");
} else {
} else if (approvals.isEmpty() || forceMessage) {
publishMessageOnly();
} else {
throw new InvalidChangeOperationException("Change is closed");
}
touchChange();

View File

@@ -100,6 +100,10 @@ public class ReviewCommand extends BaseCommand {
@Option(name = "--submit", aliases = "-s", usage = "submit the patch set")
private boolean submitChange;
@Option(name = "--force-message", usage = "publish the message, "
+ "even if the label score cannot be applied due to change being closed")
private boolean forceMessage = false;
@Inject
private ReviewDb db;
@@ -227,7 +231,7 @@ public class ReviewCommand extends BaseCommand {
}
try {
publishCommentsFactory.create(patchSetId, changeComment, aps).call();
publishCommentsFactory.create(patchSetId, changeComment, aps, forceMessage).call();
if (abandonChange) {
if (changeControl.canAbandon()) {