ChangeJson: Include change kind in revision info

Change-Id: I00ff6eb125ecdd995832d07dff5d779a863712dd
This commit is contained in:
David Pursehouse
2016-06-28 09:24:08 +09:00
parent b14864dd86
commit 4de41115b1
3 changed files with 29 additions and 11 deletions

View File

@@ -353,6 +353,7 @@ default. Optional fields are:
"current_revision": "184ebe53805e102605d11f6b143486d15c23a09c", "current_revision": "184ebe53805e102605d11f6b143486d15c23a09c",
"revisions": { "revisions": {
"184ebe53805e102605d11f6b143486d15c23a09c": { "184ebe53805e102605d11f6b143486d15c23a09c": {
"kind": "REWORK",
"_number": 1, "_number": 1,
"ref": "refs/changes/97/97/1", "ref": "refs/changes/97/97/1",
"fetch": { "fetch": {
@@ -936,6 +937,7 @@ is included.
"current_revision": "27cc4558b5a3d3387dd11ee2df7a117e7e581822", "current_revision": "27cc4558b5a3d3387dd11ee2df7a117e7e581822",
"revisions": { "revisions": {
"27cc4558b5a3d3387dd11ee2df7a117e7e581822": { "27cc4558b5a3d3387dd11ee2df7a117e7e581822": {
"kind": "REWORK",
"_number": 2, "_number": 2,
"ref": "refs/changes/99/4799/2", "ref": "refs/changes/99/4799/2",
"fetch": { "fetch": {
@@ -1314,6 +1316,7 @@ link:#current-commit[\{CURRENT_COMMIT\}] set.
"current_revision": "9adb9f4c7b40eeee0646e235de818d09164d7379", "current_revision": "9adb9f4c7b40eeee0646e235de818d09164d7379",
"revisions": { "revisions": {
"9adb9f4c7b40eeee0646e235de818d09164d7379": { "9adb9f4c7b40eeee0646e235de818d09164d7379": {
"kind": "REWORK",
"_number": 1, "_number": 1,
"created": "2015-05-01 15:39:57.979000000", "created": "2015-05-01 15:39:57.979000000",
"uploader": { "uploader": {
@@ -1432,6 +1435,7 @@ link:#current-commit[\{CURRENT_COMMIT\}] set.
"current_revision": "1bd7c12a38854a2c6de426feec28800623f492c4", "current_revision": "1bd7c12a38854a2c6de426feec28800623f492c4",
"revisions": { "revisions": {
"1bd7c12a38854a2c6de426feec28800623f492c4": { "1bd7c12a38854a2c6de426feec28800623f492c4": {
"kind": "REWORK",
"_number": 1, "_number": 1,
"created": "2015-05-01 15:39:57.979000000", "created": "2015-05-01 15:39:57.979000000",
"uploader": { "uploader": {
@@ -2659,12 +2663,14 @@ for the current patch set.
"current_revision": "674ac754f91e64a0efb8087e59a176484bd534d1", "current_revision": "674ac754f91e64a0efb8087e59a176484bd534d1",
"revisions": { "revisions": {
"674ac754f91e64a0efb8087e59a176484bd534d1": { "674ac754f91e64a0efb8087e59a176484bd534d1": {
"_number": 2, "kind": "REWORK",
"ref": "refs/changes/65/3965/2", "_number": 2,
"fetch": { "ref": "refs/changes/65/3965/2",
"http": { "fetch": {
"url": "http://gerrit/myProject", "http": {
"ref": "refs/changes/65/3965/2" "url": "http://gerrit/myProject",
"ref": "refs/changes/65/3965/2"
}
} }
} }
} }
@@ -2863,6 +2869,7 @@ is included.
"current_revision": "27cc4558b5a3d3387dd11ee2df7a117e7e581822", "current_revision": "27cc4558b5a3d3387dd11ee2df7a117e7e581822",
"revisions": { "revisions": {
"27cc4558b5a3d3387dd11ee2df7a117e7e581822": { "27cc4558b5a3d3387dd11ee2df7a117e7e581822": {
"kind": "REWORK",
"_number": 2, "_number": 2,
"ref": "refs/changes/99/4799/2", "ref": "refs/changes/99/4799/2",
"fetch": { "fetch": {
@@ -4974,6 +4981,8 @@ link:#list-changes[Query Changes].
|=========================== |===========================
|Field Name ||Description |Field Name ||Description
|`draft` |not set if `false`|Whether the patch set is a draft. |`draft` |not set if `false`|Whether the patch set is a draft.
|`kind` ||The change kind. Valid values are `REWORK`, `TRIVIAL_REBASE`,
`MERGE_FIRST_PARENT_UPDATE`, `NO_CODE_CHANGE`, and `NO_CHANGE`.
|`_number` ||The patch set number. |`_number` ||The patch set number.
|`created` || |`created` ||
The link:rest-api.html#timestamp[timestamp] of when the patch set was The link:rest-api.html#timestamp[timestamp] of when the patch set was

View File

@@ -14,12 +14,15 @@
package com.google.gerrit.extensions.common; package com.google.gerrit.extensions.common;
import com.google.gerrit.extensions.client.ChangeKind;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Map; import java.util.Map;
public class RevisionInfo { public class RevisionInfo {
public transient boolean isCurrent; public transient boolean isCurrent;
public Boolean draft; public Boolean draft;
public ChangeKind kind;
public int _number; public int _number;
public Timestamp created; public Timestamp created;
public AccountInfo uploader; public AccountInfo uploader;

View File

@@ -163,6 +163,7 @@ public class ChangeJson {
private final GpgApiAdapter gpgApi; private final GpgApiAdapter gpgApi;
private final ChangeNotes.Factory notesFactory; private final ChangeNotes.Factory notesFactory;
private final ChangeResource.Factory changeResourceFactory; private final ChangeResource.Factory changeResourceFactory;
private final ChangeKindCache changeKindCache;
private AccountLoader accountLoader; private AccountLoader accountLoader;
private Map<Change.Id, List<SubmitRecord>> submitRecords; private Map<Change.Id, List<SubmitRecord>> submitRecords;
@@ -190,6 +191,7 @@ public class ChangeJson {
GpgApiAdapter gpgApi, GpgApiAdapter gpgApi,
ChangeNotes.Factory notesFactory, ChangeNotes.Factory notesFactory,
ChangeResource.Factory changeResourceFactory, ChangeResource.Factory changeResourceFactory,
ChangeKindCache changeKindCache,
@Assisted Set<ListChangesOption> options) { @Assisted Set<ListChangesOption> options) {
this.db = db; this.db = db;
this.labelNormalizer = ln; this.labelNormalizer = ln;
@@ -211,6 +213,7 @@ public class ChangeJson {
this.gpgApi = gpgApi; this.gpgApi = gpgApi;
this.notesFactory = notesFactory; this.notesFactory = notesFactory;
this.changeResourceFactory = changeResourceFactory; this.changeResourceFactory = changeResourceFactory;
this.changeKindCache = changeKindCache;
this.options = options.isEmpty() this.options = options.isEmpty()
? EnumSet.noneOf(ListChangesOption.class) ? EnumSet.noneOf(ListChangesOption.class)
: EnumSet.copyOf(options); : EnumSet.copyOf(options);
@@ -472,7 +475,7 @@ public class ChangeJson {
finish(out); finish(out);
if (needRevisions) { if (needRevisions) {
out.revisions = revisions(ctl, src); out.revisions = revisions(ctl, cd, src);
if (out.revisions != null) { if (out.revisions != null) {
for (Map.Entry<String, RevisionInfo> entry : out.revisions.entrySet()) { for (Map.Entry<String, RevisionInfo> entry : out.revisions.entrySet()) {
if (entry.getValue().isCurrent) { if (entry.getValue().isCurrent) {
@@ -887,7 +890,7 @@ public class ChangeJson {
.toSortedList(AccountInfoComparator.ORDER_NULLS_FIRST); .toSortedList(AccountInfoComparator.ORDER_NULLS_FIRST);
} }
private Map<String, RevisionInfo> revisions(ChangeControl ctl, private Map<String, RevisionInfo> revisions(ChangeControl ctl, ChangeData cd,
Map<PatchSet.Id, PatchSet> map) throws PatchListNotAvailableException, Map<PatchSet.Id, PatchSet> map) throws PatchListNotAvailableException,
GpgException, OrmException, IOException { GpgException, OrmException, IOException {
Map<String, RevisionInfo> res = new LinkedHashMap<>(); Map<String, RevisionInfo> res = new LinkedHashMap<>();
@@ -897,7 +900,7 @@ public class ChangeJson {
if ((has(ALL_REVISIONS) if ((has(ALL_REVISIONS)
|| in.getId().equals(ctl.getChange().currentPatchSetId())) || in.getId().equals(ctl.getChange().currentPatchSetId()))
&& ctl.isPatchVisible(in, db.get())) { && ctl.isPatchVisible(in, db.get())) {
res.put(in.getRevision().get(), toRevisionInfo(ctl, in, repo)); res.put(in.getRevision().get(), toRevisionInfo(ctl, cd, in, repo));
} }
} }
return res; return res;
@@ -938,13 +941,15 @@ public class ChangeJson {
accountLoader = accountLoaderFactory.create(has(DETAILED_ACCOUNTS)); accountLoader = accountLoaderFactory.create(has(DETAILED_ACCOUNTS));
try (Repository repo = try (Repository repo =
repoManager.openRepository(ctl.getProject().getNameKey())) { repoManager.openRepository(ctl.getProject().getNameKey())) {
RevisionInfo rev = toRevisionInfo(ctl, in, repo); RevisionInfo rev = toRevisionInfo(
ctl, changeDataFactory.create(db.get(), ctl), in, repo);
accountLoader.fill(); accountLoader.fill();
return rev; return rev;
} }
} }
private RevisionInfo toRevisionInfo(ChangeControl ctl, PatchSet in, Repository repo) private RevisionInfo toRevisionInfo(ChangeControl ctl, ChangeData cd,
PatchSet in, Repository repo)
throws PatchListNotAvailableException, GpgException, OrmException, throws PatchListNotAvailableException, GpgException, OrmException,
IOException { IOException {
Change c = ctl.getChange(); Change c = ctl.getChange();
@@ -956,6 +961,7 @@ public class ChangeJson {
out.uploader = accountLoader.get(in.getUploader()); out.uploader = accountLoader.get(in.getUploader());
out.draft = in.isDraft() ? true : null; out.draft = in.isDraft() ? true : null;
out.fetch = makeFetchMap(ctl, in); out.fetch = makeFetchMap(ctl, in);
out.kind = changeKindCache.getChangeKind(repo, cd, in);
boolean setCommit = has(ALL_COMMITS) boolean setCommit = has(ALL_COMMITS)
|| (out.isCurrent && has(CURRENT_COMMIT)); || (out.isCurrent && has(CURRENT_COMMIT));