diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt index 261a272f4c..20b1dab264 100644 --- a/Documentation/rest-api-changes.txt +++ b/Documentation/rest-api-changes.txt @@ -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. diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/change/ChangeIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/change/ChangeIT.java index ec429c44bf..9006cb5ba7 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/change/ChangeIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/change/ChangeIT.java @@ -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); diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/common/ChangeInfo.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/common/ChangeInfo.java index 455243a86f..cc7fb7742c 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/common/ChangeInfo.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/common/ChangeInfo.java @@ -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; diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java index 7d64591209..da5f9be14c 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java @@ -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) {