Make submittable a ListChangesOption

Some scripts rely on the submittable bit from QueryChanges to
implement an 'automatically submit when approved to do so' feature,
to allow a person to mark a change as Autosubmit-Ready and go home
for the night in the expectation that a CI system will verify the
change and cause it to be submitted.

4cd05b2c5e (Only compute submittable
during submitted_together, 2016-09-17), which was needed for
performance reasons when rendering dashboards, broke these scripts.
Allow them to work again through a new o=SUBMITTABLE option.

Change-Id: Ia6ce6d95b1d774ede786b797eb04ce1353de6c86
This commit is contained in:
Jonathan Nieder
2016-09-23 11:37:57 -07:00
parent b21c20ba0e
commit cb51d7465a
5 changed files with 23 additions and 15 deletions

View File

@@ -301,6 +301,12 @@ default. Optional fields are:
link:user-search.html#reviewedby[reviewedby:self].
--
[[submittable]]
--
* `SUBMITTABLE`: include the `submittable` field in link:#commit-info[CommitInfo],
which can be used to tell if the change is reviewed and ready for submit.
--
[[web-links]]
--
* `WEB_LINKS`: include the `web_links` field in link:#commit-info[CommitInfo],
@@ -1420,8 +1426,9 @@ changes to be merged.
The listed changes use the same format as in
link:#list-changes[Query Changes] with the
link:#labels[`LABELS`], link:#detailed-labels[`DETAILED_LABELS`],
link:#current-revision[`CURRENT_REVISION`], and
link:#current-commit[`CURRENT_COMMIT`] options set.
link:#current-revision[`CURRENT_REVISION`],
link:#current-commit[`CURRENT_COMMIT`], and
link:#submittable[`SUBMITTABLE`] options set.
Standard link:#query-options[formatting options] can be specified
with the `o` parameter, as well as the `submitted_together` specific
@@ -4640,7 +4647,7 @@ Whether the change is mergeable. +
Not set for merged changes, or if the change has not yet been tested.
|`submittable` |optional|
Whether the change has been approved by the project submit rules. +
Provided only by link:#submitted-together[submitted_together].
Only set if link:#submittable[requested].
|`insertions` ||
Number of inserted lines.
|`deletions` ||

View File

@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assert_;
import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION;
import static com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS;
import static com.google.gerrit.extensions.client.ListChangesOption.SUBMITTABLE;
import static com.google.gerrit.server.group.SystemGroupBackend.CHANGE_OWNER;
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -474,6 +475,9 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
}
protected void assertSubmittable(String changeId) throws Exception {
assertThat(get(changeId, SUBMITTABLE).submittable)
.named("submit bit on ChangeInfo")
.isEqualTo(true);
RevisionResource rsrc = parseCurrentRevisionResource(changeId);
UiAction.Description desc = submitHandler.getDescription(rsrc);
assertThat(desc.isVisible()).named("visible bit on submit action").isTrue();

View File

@@ -69,7 +69,10 @@ public enum ListChangesOption {
PUSH_CERTIFICATES(18),
/** Include change's reviewer updates. */
REVIEWER_UPDATES(19);
REVIEWER_UPDATES(19),
/** Set the submittable boolean. */
SUBMITTABLE(20);
private final int value;

View File

@@ -32,6 +32,7 @@ import static com.google.gerrit.extensions.client.ListChangesOption.MESSAGES;
import static com.google.gerrit.extensions.client.ListChangesOption.PUSH_CERTIFICATES;
import static com.google.gerrit.extensions.client.ListChangesOption.REVIEWED;
import static com.google.gerrit.extensions.client.ListChangesOption.REVIEWER_UPDATES;
import static com.google.gerrit.extensions.client.ListChangesOption.SUBMITTABLE;
import static com.google.gerrit.extensions.client.ListChangesOption.WEB_LINKS;
import static com.google.gerrit.server.CommonConverters.toGitPerson;
import static java.util.stream.Collectors.toList;
@@ -177,7 +178,6 @@ public class ChangeJson {
private boolean lazyLoad = true;
private AccountLoader accountLoader;
private boolean includeSubmittable;
private Map<Change.Id, List<SubmitRecord>> submitRecords;
private FixInput fix;
@@ -233,11 +233,6 @@ public class ChangeJson {
: EnumSet.copyOf(options);
}
public ChangeJson includeSubmittable(boolean include) {
includeSubmittable = include;
return this;
}
public ChangeJson lazyLoad(boolean load) {
lazyLoad = load;
return this;
@@ -454,7 +449,7 @@ public class ChangeJson {
out.submitType = str.type;
}
out.mergeable = cd.isMergeable();
if (includeSubmittable) {
if (has(SUBMITTABLE)) {
out.submittable = submittable(cd);
}
}

View File

@@ -54,7 +54,8 @@ public class SubmittedTogether implements RestReadView<ChangeResource> {
private final EnumSet<ListChangesOption> jsonOpt = EnumSet.of(
ListChangesOption.CURRENT_REVISION,
ListChangesOption.CURRENT_COMMIT);
ListChangesOption.CURRENT_COMMIT,
ListChangesOption.SUBMITTABLE);
private final ChangeJson.Factory json;
private final Provider<ReviewDb> dbProvider;
@@ -152,9 +153,7 @@ public class SubmittedTogether implements RestReadView<ChangeResource> {
}
SubmittedTogetherInfo info = new SubmittedTogetherInfo();
info.changes = json.create(jsonOpt)
.includeSubmittable(true)
.formatChangeDatas(cds);
info.changes = json.create(jsonOpt).formatChangeDatas(cds);
info.nonVisibleChanges = hidden;
return info;
} catch (OrmException | IOException e) {