Expose submit type in ChangeInfo

As noted in the removed TODO, this is already needed to compute the
key for the mergeability cache, so including it in the ChangeInfo is
free.

The submit type always corresponds to current patch set, for the same
reason the mergeable bit does: only the current patch may be submitted
at all. It is also only shown in the UI for the current patch set.

Change-Id: I62aecac9bed035e8c3199e78691c0e01f3564151
This commit is contained in:
Dave Borowitz 2015-12-17 13:08:25 -05:00
parent be4d7a7c9d
commit ace3210a62
4 changed files with 15 additions and 4 deletions

View File

@ -3950,6 +3950,9 @@ Whether the calling user has starred this change.
|`reviewed` |not set if `false`|
Whether the change was reviewed by the calling user.
Only set if link:#reviewed[reviewed] is requested.
|`submit_type` |optional|
The link:project-configuration.html#submit_type[submit type] of the change. +
Not set for merged changes.
|`mergeable` |optional|
Whether the change is mergeable. +
Not set for merged changes, or if the change has not yet been tested.

View File

@ -42,6 +42,7 @@ import com.google.gerrit.extensions.api.changes.RevisionApi;
import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.SubmitType;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ApprovalInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
@ -84,6 +85,7 @@ public class ChangeIT extends AbstractDaemonTest {
assertThat(c.branch).isEqualTo("master");
assertThat(c.status).isEqualTo(ChangeStatus.NEW);
assertThat(c.subject).isEqualTo("test commit");
assertThat(c.submitType).isEqualTo(SubmitType.MERGE_IF_NECESSARY);
assertThat(c.mergeable).isTrue();
assertThat(c.changeId).isEqualTo(r.getChangeId());
assertThat(c.created).isEqualTo(c.updated);

View File

@ -16,6 +16,7 @@ package com.google.gerrit.extensions.common;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.ReviewerState;
import com.google.gerrit.extensions.client.SubmitType;
import java.sql.Timestamp;
import java.util.Collection;
@ -35,6 +36,7 @@ public class ChangeInfo {
public Timestamp updated;
public Boolean starred;
public Boolean reviewed;
public SubmitType submitType;
public Boolean mergeable;
public Boolean submittable;
public Integer insertions;

View File

@ -58,6 +58,7 @@ import com.google.gerrit.common.data.LabelValue;
import com.google.gerrit.common.data.Permission;
import com.google.gerrit.common.data.PermissionRange;
import com.google.gerrit.common.data.SubmitRecord;
import com.google.gerrit.common.data.SubmitTypeRecord;
import com.google.gerrit.extensions.api.changes.FixInput;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.AccountInfo;
@ -403,10 +404,13 @@ public class ChangeJson {
out.topic = in.getTopic();
out.hashtags = ctl.getNotes().load().getHashtags();
out.changeId = in.getKey().get();
// TODO(dborowitz): This gets the submit type, so we could include that in
// the response and avoid making a request to /submit_type from the UI.
out.mergeable = in.getStatus() == Change.Status.MERGED
? null : cd.isMergeable();
if (in.getStatus() != Change.Status.MERGED) {
SubmitTypeRecord str = cd.submitTypeRecord();
if (str.isOk()) {
out.submitType = str.type;
}
out.mergeable = cd.isMergeable();
}
out.submittable = Submit.submittable(cd);
ChangedLines changedLines = cd.changedLines();
if (changedLines != null) {