Include submitter in ChangeInfo

Somewhat surprisingly, this was never directly exposed by the REST API.
We already look up the whole PatchSetApproval record corresponding to
submission in order to set `submitted`, so it's trivial to add the
account info as well.

Change-Id: I9bb9cb2c0e85f26548fc94154dd2e02fb4b9537b
This commit is contained in:
Dave Borowitz 2017-08-23 10:28:34 -04:00
parent f0c81b6a89
commit 8ec31f97b7
7 changed files with 28 additions and 7 deletions

View File

@ -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|

View File

@ -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

View File

@ -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;

View File

@ -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<String> stars;

View File

@ -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; }-*/;

View File

@ -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;
}

View File

@ -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<PatchSetApproval> 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<String, LabelWithStatus> labelsForSubmittedChange(