diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt index 557fb3cc79..903acc7a83 100644 --- a/Documentation/rest-api-changes.txt +++ b/Documentation/rest-api-changes.txt @@ -5642,6 +5642,9 @@ updated. |`submitted` |only set for merged changes| The link:rest-api.html#timestamp[timestamp] of when the change was submitted. +|`submitter` |only set for merged changes| +The user who submitted the change, as an +link:rest-api-accounts.html#account-info[ AccountInfo] entity. |`starred` |not set if `false`| Whether the calling user has starred this change with the default label. |`stars` |optional| 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 4c209e2c5d..320faa0f76 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 @@ -2117,10 +2117,19 @@ public class ChangeIT extends AbstractDaemonTest { @Test public void submitted() throws Exception { PushOneCommit.Result r = createChange(); - gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve()); - assertThat(gApi.changes().id(r.getChangeId()).info().submitted).isNull(); - gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).submit(); - assertThat(gApi.changes().id(r.getChangeId()).info().submitted).isNotNull(); + String id = r.getChangeId(); + + ChangeInfo c = gApi.changes().id(r.getChangeId()).info(); + assertThat(c.submitted).isNull(); + assertThat(c.submitter).isNull(); + + gApi.changes().id(id).current().review(ReviewInput.approve()); + gApi.changes().id(id).current().submit(); + + c = gApi.changes().id(r.getChangeId()).info(); + assertThat(c.submitted).isNotNull(); + assertThat(c.submitter).isNotNull(); + assertThat(c.submitter._accountId).isEqualTo(atrScope.get().getUser().getAccountId().get()); } @Test diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/CreateChangeIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/CreateChangeIT.java index 43d02a60e1..c0f31a084d 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/CreateChangeIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/CreateChangeIT.java @@ -401,6 +401,7 @@ public class CreateChangeIT extends AbstractDaemonTest { assertThat(out.workInProgress).isEqualTo(in.workInProgress); assertThat(out.revisions).hasSize(1); assertThat(out.submitted).isNull(); + assertThat(out.submitter).isNull(); Boolean draft = Iterables.getOnlyElement(out.revisions.values()).draft; assertThat(booleanToDraftStatus(draft)).isEqualTo(in.status); return out; 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 a4f85e57ad..0ae45dd54e 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 @@ -35,6 +35,7 @@ public class ChangeInfo { public Timestamp created; public Timestamp updated; public Timestamp submitted; + public AccountInfo submitter; public Boolean starred; public Boolean muted; public Collection stars; diff --git a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/info/ChangeInfo.java b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/info/ChangeInfo.java index 9149230757..8db0ef717f 100644 --- a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/info/ChangeInfo.java +++ b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/info/ChangeInfo.java @@ -134,6 +134,8 @@ public class ChangeInfo extends JavaScriptObject { private native String submittedRaw() /*-{ return this.submitted; }-*/; + public final native AccountInfo submitter() /*-{ return this.submitter; }-*/; + public final native boolean starred() /*-{ return this.starred ? true : false; }-*/; public final native boolean muted() /*-{ return this.muted ? true : false; }-*/; diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/ActionJson.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/ActionJson.java index 375deeab7a..9401c88965 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/ActionJson.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/ActionJson.java @@ -133,6 +133,7 @@ public class ActionJson { copy.starred = changeInfo.starred; copy.stars = changeInfo.stars; copy.submitted = changeInfo.submitted; + copy.submitter = changeInfo.submitter; copy.id = changeInfo.id; return copy; } 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 4e6bb5ba18..6471788d33 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 @@ -556,7 +556,7 @@ public class ChangeJson { out.removableReviewers = removableReviewers(ctl, out); } - out.submitted = getSubmittedOn(cd); + setSubmitter(cd, out); out.plugins = pluginDefinedAttributesFactory != null ? pluginDefinedAttributesFactory.create(cd) : null; out.revertOf = cd.change().getRevertOf() != null ? cd.change().getRevertOf().get() : null; @@ -852,9 +852,13 @@ public class ChangeJson { return Ints.tryParse(value); } - private Timestamp getSubmittedOn(ChangeData cd) throws OrmException { + private void setSubmitter(ChangeData cd, ChangeInfo out) throws OrmException { Optional s = cd.getSubmitApproval(); - return s.isPresent() ? s.get().getGranted() : null; + if (!s.isPresent()) { + return; + } + out.submitted = s.get().getGranted(); + out.submitter = accountLoader.get(s.get().getAccountId()); } private Map labelsForSubmittedChange(