Introduce id property on REST entities
The /changes/ entities now use "id" to include a triplet of the project, branch and change-id string to uniquely identify that change on the server. This moves the old id field to be named change_id, which is a breaking change. Change-Id: I76671c9f67cb853cae817ab132a5884d89bbc480
This commit is contained in:
parent
bbeb2a96e4
commit
959f96e0a0
@ -137,6 +137,7 @@ and accepts the same options as query parameters.
|
||||
)]}'
|
||||
{
|
||||
"external/bison": {
|
||||
"kind": "gerritcodereview#project",
|
||||
"description": "GNU parser generator"
|
||||
},
|
||||
"external/gcc": {},
|
||||
@ -184,9 +185,11 @@ Query for open changes of watched projects:
|
||||
|
||||
)]}'
|
||||
{
|
||||
"kind": "gerritcodereview#change",
|
||||
"id": "demo~master~Idaf5e098d70898b7119f6f4af5a6c13343d64b57",
|
||||
"project": "demo",
|
||||
"branch": "master",
|
||||
"id": "Idaf5e098d70898b7119f6f4af5a6c13343d64b57",
|
||||
"change_id": "Idaf5e098d70898b7119f6f4af5a6c13343d64b57",
|
||||
"subject": "One change",
|
||||
"status": "NEW",
|
||||
"created": "2012-07-17 07:18:30.854000000",
|
||||
@ -199,9 +202,11 @@ Query for open changes of watched projects:
|
||||
},
|
||||
},
|
||||
{
|
||||
"kind": "gerritcodereview#change",
|
||||
"id": "demo~master~I09c8041b5867d5b33170316e2abc34b79bbb8501",
|
||||
"project": "demo",
|
||||
"branch": "master",
|
||||
"id": "I09c8041b5867d5b33170316e2abc34b79bbb8501",
|
||||
"change_id": "I09c8041b5867d5b33170316e2abc34b79bbb8501",
|
||||
"subject": "Another change",
|
||||
"status": "NEW",
|
||||
"created": "2012-07-17 07:18:30.884000000",
|
||||
@ -242,9 +247,11 @@ Query that retrieves changes for a user's dashboard:
|
||||
[
|
||||
[
|
||||
{
|
||||
"kind": "gerritcodereview#change",
|
||||
"id": "demo~master~Idaf5e098d70898b7119f6f4af5a6c13343d64b57",
|
||||
"project": "demo",
|
||||
"branch": "master",
|
||||
"id": "Idaf5e098d70898b7119f6f4af5a6c13343d64b57",
|
||||
"change_id": "Idaf5e098d70898b7119f6f4af5a6c13343d64b57",
|
||||
"subject": "One change",
|
||||
"status": "NEW",
|
||||
"created": "2012-07-17 07:18:30.854000000",
|
||||
@ -306,9 +313,11 @@ default. Optional fields are:
|
||||
)]}'
|
||||
[
|
||||
{
|
||||
"kind": "gerritcodereview#change",
|
||||
"id": "demo~master~I7ea46d2e2ee5c64c0d807677859cfb7d90b8966a",
|
||||
"project": "gerrit",
|
||||
"branch": "master",
|
||||
"id": "I7ea46d2e2ee5c64c0d807677859cfb7d90b8966a",
|
||||
"change_id": "I7ea46d2e2ee5c64c0d807677859cfb7d90b8966a",
|
||||
"subject": "Use an EventBus to manage star icons",
|
||||
"status": "NEW",
|
||||
"created": "2012-04-25 00:52:25.580000000",
|
||||
|
@ -50,7 +50,7 @@ public class ChangeInfo extends JavaScriptObject {
|
||||
}
|
||||
|
||||
public final String id_abbreviated() {
|
||||
return new Change.Key(id()).abbreviate();
|
||||
return new Change.Key(change_id()).abbreviate();
|
||||
}
|
||||
|
||||
public final Change.Status status() {
|
||||
@ -61,10 +61,11 @@ public class ChangeInfo extends JavaScriptObject {
|
||||
return Natives.keys(labels0());
|
||||
}
|
||||
|
||||
public final native String id() /*-{ return this.id; }-*/;
|
||||
public final native String project() /*-{ return this.project; }-*/;
|
||||
public final native String branch() /*-{ return this.branch; }-*/;
|
||||
public final native String topic() /*-{ return this.topic; }-*/;
|
||||
public final native String id() /*-{ return this.id; }-*/;
|
||||
public final native String change_id() /*-{ return this.change_id; }-*/;
|
||||
private final native String statusRaw() /*-{ return this.status; }-*/;
|
||||
public final native String subject() /*-{ return this.subject; }-*/;
|
||||
public final native AccountInfo owner() /*-{ return this.owner; }-*/;
|
||||
|
@ -22,6 +22,7 @@ import static com.google.gerrit.common.changes.ListChangesOption.CURRENT_FILES;
|
||||
import static com.google.gerrit.common.changes.ListChangesOption.CURRENT_REVISION;
|
||||
import static com.google.gerrit.common.changes.ListChangesOption.LABELS;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
@ -70,7 +71,9 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import java.net.URLEncoder;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -265,7 +268,7 @@ public class ListChanges {
|
||||
out.write('\n');
|
||||
}
|
||||
for (ChangeInfo c : info) {
|
||||
String id = new Change.Key(c.id).abbreviate();
|
||||
String id = new Change.Key(c.changeId).abbreviate();
|
||||
String subject = c.subject;
|
||||
if (subject.length() + id.length() > 80) {
|
||||
subject = subject.substring(0, 80 - id.length());
|
||||
@ -285,7 +288,7 @@ public class ListChanges {
|
||||
out.project = in.getProject().get();
|
||||
out.branch = in.getDest().getShortName();
|
||||
out.topic = in.getTopic();
|
||||
out.id = in.getKey().get();
|
||||
out.changeId = in.getKey().get();
|
||||
out.subject = in.getSubject();
|
||||
out.status = in.getStatus();
|
||||
out.owner = asAccountAttribute(in.getOwner());
|
||||
@ -296,6 +299,7 @@ public class ListChanges {
|
||||
out.starred = user.getStarredChanges().contains(in.getId()) ? true : null;
|
||||
out.reviewed = in.getStatus().isOpen() && isChangeReviewed(cd) ? true : null;
|
||||
out.labels = options.contains(LABELS) ? labelsFor(cd) : null;
|
||||
out.finish();
|
||||
|
||||
if (options.contains(ALL_REVISIONS) || options.contains(CURRENT_REVISION)) {
|
||||
out.revisions = revisions(cd);
|
||||
@ -595,10 +599,11 @@ public class ListChanges {
|
||||
|
||||
static class ChangeInfo {
|
||||
final String kind = "gerritcodereview#change";
|
||||
String id;
|
||||
String project;
|
||||
String branch;
|
||||
String topic;
|
||||
String id;
|
||||
String changeId;
|
||||
String subject;
|
||||
Change.Status status;
|
||||
Timestamp created;
|
||||
@ -615,6 +620,17 @@ public class ListChanges {
|
||||
Map<String, RevisionInfo> revisions;
|
||||
|
||||
Boolean _moreChanges;
|
||||
|
||||
void finish() {
|
||||
try {
|
||||
id = Joiner.on('~').join(
|
||||
URLEncoder.encode(project, "UTF-8"),
|
||||
URLEncoder.encode(branch, "UTF-8"),
|
||||
URLEncoder.encode(changeId, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("Cannot encode components for id", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class RevisionInfo {
|
||||
|
Loading…
Reference in New Issue
Block a user