Merge topic 'plugin-api'
* changes: Add ChangeApi.get() method Consistently apply camel case naming convention in server code Plugin API: Add ChangeStatus
This commit is contained in:
@@ -16,6 +16,7 @@ package com.google.gerrit.acceptance.api.change;
|
||||
|
||||
import static com.google.gerrit.acceptance.GitUtil.cloneProject;
|
||||
import static com.google.gerrit.acceptance.GitUtil.createProject;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.AcceptanceTestRequestScope;
|
||||
@@ -25,6 +26,9 @@ import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.extensions.api.GerritApi;
|
||||
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeStatus;
|
||||
import com.google.gerrit.extensions.common.ListChangesOption;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
@@ -41,6 +45,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class ChangeIT extends AbstractDaemonTest {
|
||||
|
||||
@@ -81,6 +86,25 @@ public class ChangeIT extends AbstractDaemonTest {
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void get() throws GitAPIException,
|
||||
IOException, RestApiException {
|
||||
PushOneCommit.Result r = createChange();
|
||||
String triplet = "p~master~" + r.getChangeId();
|
||||
ChangeInfo c =
|
||||
gApi.changes()
|
||||
.id(triplet)
|
||||
.get(EnumSet.noneOf(ListChangesOption.class));
|
||||
assertEquals(triplet, c.id);
|
||||
assertEquals("p", c.project);
|
||||
assertEquals("master", c.branch);
|
||||
assertEquals(ChangeStatus.NEW, c.status);
|
||||
assertEquals("test commit", c.subject);
|
||||
assertEquals(true, c.mergeable);
|
||||
assertEquals(r.getChangeId(), c.changeId);
|
||||
assertEquals(c.created, c.updated);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void abandon() throws GitAPIException,
|
||||
IOException, RestApiException {
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.google.gerrit.server.account.AccountInfo;
|
||||
public class AccountAssert {
|
||||
|
||||
public static void assertAccountInfo(TestAccount a, AccountInfo ai) {
|
||||
assertTrue(a.id.get() == ai._account_id);
|
||||
assertTrue(a.id.get() == ai._accountId);
|
||||
assertEquals(a.fullName, ai.name);
|
||||
assertEquals(a.email, ai.email);
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
protected void assertCurrentRevision(String changeId, int expectedNum,
|
||||
ObjectId expectedId) throws IOException {
|
||||
ChangeInfo c = getChange(changeId, CURRENT_REVISION);
|
||||
assertEquals(expectedId.name(), c.current_revision);
|
||||
assertEquals(expectedId.name(), c.currentRevision);
|
||||
assertEquals(expectedNum, c.revisions.get(expectedId.name())._number);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,14 +87,14 @@ public class ListChangesOptionsIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void noRevisionOptions() throws Exception {
|
||||
ChangeInfo c = getChange(changeId);
|
||||
assertNull(c.current_revision);
|
||||
assertNull(c.currentRevision);
|
||||
assertNull(c.revisions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentRevision() throws Exception {
|
||||
ChangeInfo c = getChange(changeId, CURRENT_REVISION);
|
||||
assertEquals(commitId(2), c.current_revision);
|
||||
assertEquals(commitId(2), c.currentRevision);
|
||||
assertEquals(ImmutableSet.of(commitId(2)), c.revisions.keySet());
|
||||
assertEquals(3, c.revisions.get(commitId(2))._number);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class ListChangesOptionsIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void allRevisions() throws Exception {
|
||||
ChangeInfo c = getChange(changeId, ALL_REVISIONS);
|
||||
assertEquals(commitId(2), c.current_revision);
|
||||
assertEquals(commitId(2), c.currentRevision);
|
||||
assertEquals(ImmutableSet.of(commitId(0), commitId(1), commitId(2)),
|
||||
c.revisions.keySet());
|
||||
assertEquals(1, c.revisions.get(commitId(0))._number);
|
||||
|
||||
@@ -203,7 +203,7 @@ public class AddRemoveGroupMembersIT extends AbstractDaemonTest {
|
||||
private void assertMembers(List<AccountInfo> ai, TestAccount... members) {
|
||||
Map<Integer, AccountInfo> infoById = Maps.newHashMap();
|
||||
for (AccountInfo i : ai) {
|
||||
infoById.put(i._account_id, i);
|
||||
infoById.put(i._accountId, i);
|
||||
}
|
||||
|
||||
for (TestAccount a : members) {
|
||||
|
||||
@@ -14,8 +14,12 @@
|
||||
|
||||
package com.google.gerrit.extensions.api.changes;
|
||||
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.ListChangesOption;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public interface ChangeApi {
|
||||
String id();
|
||||
|
||||
@@ -34,4 +38,6 @@ public interface ChangeApi {
|
||||
|
||||
void addReviewer(AddReviewerInput in) throws RestApiException;
|
||||
void addReviewer(String in) throws RestApiException;
|
||||
|
||||
ChangeInfo get(EnumSet<ListChangesOption> options) throws RestApiException;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
public class AccountInfo {
|
||||
public Integer _accountId;
|
||||
public String name;
|
||||
public String email;
|
||||
public String username;
|
||||
}
|
||||
@@ -12,15 +12,15 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.actions;
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import com.google.gerrit.extensions.webui.UiAction;
|
||||
|
||||
public class ActionInfo {
|
||||
String method;
|
||||
String label;
|
||||
String title;
|
||||
Boolean enabled;
|
||||
public String method;
|
||||
public String label;
|
||||
public String title;
|
||||
public Boolean enabled;
|
||||
|
||||
public ActionInfo(UiAction.Description d) {
|
||||
method = d.getMethod();
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class ApprovalInfo extends AccountInfo {
|
||||
public Integer value;
|
||||
public Timestamp date;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChangeInfo {
|
||||
public String id;
|
||||
public String project;
|
||||
public String branch;
|
||||
public String topic;
|
||||
public String changeId;
|
||||
public String subject;
|
||||
public ChangeStatus status;
|
||||
public Timestamp created;
|
||||
public Timestamp updated;
|
||||
public Boolean starred;
|
||||
public Boolean reviewed;
|
||||
public Boolean mergeable;
|
||||
public Integer insertions;
|
||||
public Integer deletions;
|
||||
public AccountInfo owner;
|
||||
public String currentRevision;
|
||||
public Map<String, ActionInfo> actions;
|
||||
public Map<String, LabelInfo> labels;
|
||||
public Collection<ChangeMessageInfo> messages;
|
||||
public Map<String, RevisionInfo> revisions;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class ChangeMessageInfo {
|
||||
public String id;
|
||||
public AccountInfo author;
|
||||
public Timestamp date;
|
||||
public String message;
|
||||
public Integer _revisionNumber;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
/* Current state within the basic workflow of the change **/
|
||||
public enum ChangeStatus {
|
||||
|
||||
/**
|
||||
* Change is open and pending review, or review is in progress.
|
||||
*
|
||||
* <p>
|
||||
* This is the default state assigned to a change when it is first created
|
||||
* in the database. A change stays in the NEW state throughout its review
|
||||
* cycle, until the change is submitted or abandoned.
|
||||
*
|
||||
* <p>
|
||||
* Changes in the NEW state can be moved to:
|
||||
* <ul>
|
||||
* <li>{@link #SUBMITTED} - when the Submit Patch Set action is used;
|
||||
* <li>{@link #ABANDONED} - when the Abandon action is used.
|
||||
* </ul>
|
||||
*/
|
||||
NEW,
|
||||
|
||||
/**
|
||||
* Change is open, but has been submitted to the merge queue.
|
||||
*
|
||||
* <p>
|
||||
* A change enters the SUBMITTED state when an authorized user presses the
|
||||
* "submit" action through the web UI, requesting that Gerrit merge the
|
||||
* change's current patch set into the destination branch.
|
||||
*
|
||||
* <p>
|
||||
* Typically a change resides in the SUBMITTED for only a brief sub-second
|
||||
* period while the merge queue fires and the destination branch is updated.
|
||||
* However, if a dependency commit (a {@link PatchSetAncestor}, directly or
|
||||
* transitively) is not yet merged into the branch, the change will hang in
|
||||
* the SUBMITTED state indefinitely.
|
||||
*
|
||||
* <p>
|
||||
* Changes in the SUBMITTED state can be moved to:
|
||||
* <ul>
|
||||
* <li>{@link #NEW} - when a replacement patch set is supplied, OR when a
|
||||
* merge conflict is detected;
|
||||
* <li>{@link #MERGED} - when the change has been successfully merged into
|
||||
* the destination branch;
|
||||
* <li>{@link #ABANDONED} - when the Abandon action is used.
|
||||
* </ul>
|
||||
*/
|
||||
SUBMITTED,
|
||||
|
||||
/**
|
||||
* Change is a draft change that only consists of draft patchsets.
|
||||
*
|
||||
* <p>
|
||||
* This is a change that is not meant to be submitted or reviewed yet. If
|
||||
* the uploader publishes the change, it becomes a NEW change.
|
||||
* Publishing is a one-way action, a change cannot return to DRAFT status.
|
||||
* Draft changes are only visible to the uploader and those explicitly
|
||||
* added as reviewers.
|
||||
*
|
||||
* <p>
|
||||
* Changes in the DRAFT state can be moved to:
|
||||
* <ul>
|
||||
* <li>{@link #NEW} - when the change is published, it becomes a new change;
|
||||
* </ul>
|
||||
*/
|
||||
DRAFT,
|
||||
|
||||
/**
|
||||
* Change is closed, and submitted to its destination branch.
|
||||
*
|
||||
* <p>
|
||||
* Once a change has been merged, it cannot be further modified by adding a
|
||||
* replacement patch set. Draft comments however may be published,
|
||||
* supporting a post-submit review.
|
||||
*/
|
||||
MERGED,
|
||||
|
||||
/**
|
||||
* Change is closed, but was not submitted to its destination branch.
|
||||
*
|
||||
* <p>
|
||||
* Once a change has been abandoned, it cannot be further modified by adding
|
||||
* a replacement patch set, and it cannot be merged. Draft comments however
|
||||
* may be published, permitting reviewers to send constructive feedback.
|
||||
*/
|
||||
ABANDONED
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommitInfo {
|
||||
public String commit;
|
||||
public List<CommitInfo> parents;
|
||||
public GitPerson author;
|
||||
public GitPerson committer;
|
||||
public String subject;
|
||||
public String message;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class FetchInfo {
|
||||
public String url;
|
||||
public String ref;
|
||||
public Map<String, String> commands;
|
||||
|
||||
public FetchInfo(String url, String ref) {
|
||||
this.url = url;
|
||||
this.ref = ref;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
public class FileInfo {
|
||||
public Character status;
|
||||
public Boolean binary;
|
||||
public String oldPath;
|
||||
public Integer linesInserted;
|
||||
public Integer linesDeleted;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class GitPerson {
|
||||
public String name;
|
||||
public String email;
|
||||
public Timestamp date;
|
||||
public int tz;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class LabelInfo {
|
||||
public AccountInfo approved;
|
||||
public AccountInfo rejected;
|
||||
public AccountInfo recommended;
|
||||
public AccountInfo disliked;
|
||||
public List<ApprovalInfo> all;
|
||||
public Map<String, String> values;
|
||||
public Short value;
|
||||
public Boolean optional;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class RevisionInfo {
|
||||
public transient boolean isCurrent;
|
||||
public Boolean draft;
|
||||
public Boolean hasDraftComments;
|
||||
public int _number;
|
||||
public Map<String, FetchInfo> fetch;
|
||||
public CommitInfo commit;
|
||||
public Map<String, FileInfo> files;
|
||||
public Map<String, ActionInfo> actions;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class AccountInfo {
|
||||
if (info == null) {
|
||||
info = new AccountInfo(id);
|
||||
if (detailed) {
|
||||
info._account_id = id.get();
|
||||
info._accountId = id.get();
|
||||
}
|
||||
created.put(id, info);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public class AccountInfo {
|
||||
|
||||
public void put(AccountInfo info) {
|
||||
if (detailed) {
|
||||
info._account_id = info._id.get();
|
||||
info._accountId = info._id.get();
|
||||
}
|
||||
provided.add(info);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class AccountInfo {
|
||||
_id = id;
|
||||
}
|
||||
|
||||
public Integer _account_id;
|
||||
public Integer _accountId;
|
||||
public String name;
|
||||
public String email;
|
||||
public String username;
|
||||
|
||||
@@ -22,9 +22,12 @@ import com.google.gerrit.extensions.api.changes.Changes;
|
||||
import com.google.gerrit.extensions.api.changes.RestoreInput;
|
||||
import com.google.gerrit.extensions.api.changes.RevertInput;
|
||||
import com.google.gerrit.extensions.api.changes.RevisionApi;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.ListChangesOption;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.change.Abandon;
|
||||
import com.google.gerrit.server.change.ChangeJson;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.PostReviewers;
|
||||
import com.google.gerrit.server.change.Restore;
|
||||
@@ -36,6 +39,7 @@ import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
class ChangeApiImpl implements ChangeApi {
|
||||
interface Factory {
|
||||
@@ -50,6 +54,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
private final Provider<Revert> revert;
|
||||
private final Provider<Restore> restore;
|
||||
private final Provider<PostReviewers> postReviewers;
|
||||
private final ChangeJson changeJson;
|
||||
|
||||
@Inject
|
||||
ChangeApiImpl(Changes changeApi,
|
||||
@@ -59,6 +64,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
Provider<Revert> revert,
|
||||
Provider<Restore> restore,
|
||||
Provider<PostReviewers> postReviewers,
|
||||
ChangeJson changeJson,
|
||||
@Assisted ChangeResource change) {
|
||||
this.changeApi = changeApi;
|
||||
this.revert = revert;
|
||||
@@ -67,6 +73,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
this.abandon = abandon;
|
||||
this.restore = restore;
|
||||
this.postReviewers = postReviewers;
|
||||
this.changeJson = changeJson;
|
||||
this.change = change;
|
||||
}
|
||||
|
||||
@@ -152,4 +159,15 @@ class ChangeApiImpl implements ChangeApi {
|
||||
throw new RestApiException("Cannot add change reviewer", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeInfo get(EnumSet<ListChangesOption> s)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return new ChangeInfoMapper(s).map(
|
||||
changeJson.addOptions(s).format(change));
|
||||
} catch (OrmException e) {
|
||||
throw new RestApiException("Cannot retrieve change", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.api.changes;
|
||||
|
||||
import static com.google.gerrit.extensions.common.ListChangesOption.ALL_REVISIONS;
|
||||
import static com.google.gerrit.extensions.common.ListChangesOption.CURRENT_ACTIONS;
|
||||
import static com.google.gerrit.extensions.common.ListChangesOption.CURRENT_REVISION;
|
||||
import static com.google.gerrit.extensions.common.ListChangesOption.DETAILED_LABELS;
|
||||
import static com.google.gerrit.extensions.common.ListChangesOption.LABELS;
|
||||
import static com.google.gerrit.extensions.common.ListChangesOption.MESSAGES;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.ApprovalInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeMessageInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeStatus;
|
||||
import com.google.gerrit.extensions.common.LabelInfo;
|
||||
import com.google.gerrit.extensions.common.ListChangesOption;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Change.Status;
|
||||
import com.google.gerrit.server.change.ChangeJson;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class ChangeInfoMapper {
|
||||
private final static ImmutableMap<Change.Status, ChangeStatus> MAP =
|
||||
Maps.immutableEnumMap(ImmutableMap.of(
|
||||
Status.DRAFT, ChangeStatus.DRAFT,
|
||||
Status.NEW, ChangeStatus.NEW,
|
||||
Status.SUBMITTED, ChangeStatus.SUBMITTED,
|
||||
Status.MERGED, ChangeStatus.MERGED,
|
||||
Status.ABANDONED, ChangeStatus.ABANDONED));
|
||||
|
||||
private final EnumSet<ListChangesOption> s;
|
||||
|
||||
ChangeInfoMapper(EnumSet<ListChangesOption> s) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
ChangeInfo map(ChangeJson.ChangeInfo i) {
|
||||
ChangeInfo o = new ChangeInfo();
|
||||
mapCommon(i, o);
|
||||
if (has(LABELS) || has(DETAILED_LABELS)) {
|
||||
mapLabels(i, o);
|
||||
}
|
||||
if (has(MESSAGES)) {
|
||||
mapMessages(i, o);
|
||||
}
|
||||
if (has(ALL_REVISIONS) || has(CURRENT_REVISION)) {
|
||||
o.revisions = i.revisions;
|
||||
}
|
||||
if (has(CURRENT_ACTIONS)) {
|
||||
o.actions = i.actions;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
private void mapCommon(ChangeJson.ChangeInfo i, ChangeInfo o) {
|
||||
o.id = i.id;
|
||||
o.project = i.project;
|
||||
o.branch = i.branch;
|
||||
o.topic = i.topic;
|
||||
o.changeId = i.changeId;
|
||||
o.subject = i.subject;
|
||||
o.status = MAP.get(i.status);
|
||||
o.created = i.created;
|
||||
o.updated = i.updated;
|
||||
o.starred = i.starred;
|
||||
o.reviewed = i.reviewed;
|
||||
o.mergeable = i.mergeable;
|
||||
o.insertions = i.insertions;
|
||||
o.deletions = i.deletions;
|
||||
o.owner = fromAcountInfo(i.owner);
|
||||
o.currentRevision = i.currentRevision;
|
||||
}
|
||||
|
||||
private void mapMessages(ChangeJson.ChangeInfo i, ChangeInfo o) {
|
||||
List<ChangeMessageInfo> r =
|
||||
Lists.newArrayListWithCapacity(i.messages.size());
|
||||
for (ChangeJson.ChangeMessageInfo m : i.messages) {
|
||||
ChangeMessageInfo cmi = new ChangeMessageInfo();
|
||||
cmi.id = m.id;
|
||||
cmi.author = fromAcountInfo(m.author);
|
||||
cmi.date = m.date;
|
||||
cmi.message = m.message;
|
||||
cmi._revisionNumber = m._revisionNumber;
|
||||
r.add(cmi);
|
||||
}
|
||||
o.messages = r;
|
||||
}
|
||||
|
||||
private void mapLabels(ChangeJson.ChangeInfo i, ChangeInfo o) {
|
||||
Map<String, LabelInfo> r = Maps.newLinkedHashMap();
|
||||
for (Map.Entry<String, ChangeJson.LabelInfo> e : i.labels.entrySet()) {
|
||||
ChangeJson.LabelInfo li = e.getValue();
|
||||
LabelInfo lo = new LabelInfo();
|
||||
lo.approved = fromAcountInfo(li.approved);
|
||||
lo.rejected = fromAcountInfo(li.rejected);
|
||||
lo.recommended = fromAcountInfo(li.recommended);
|
||||
lo.disliked = fromAcountInfo(li.disliked);
|
||||
lo.value = li.value;
|
||||
lo.optional = li.optional;
|
||||
lo.values = li.values;
|
||||
lo.all = Lists.newArrayListWithExpectedSize(li.all.size());
|
||||
for (ChangeJson.ApprovalInfo ai : li.all) {
|
||||
lo.all.add(fromApprovalInfo(ai));
|
||||
}
|
||||
r.put(e.getKey(), lo);
|
||||
}
|
||||
o.labels = r;
|
||||
}
|
||||
|
||||
private boolean has(ListChangesOption o) {
|
||||
return s.contains(o);
|
||||
}
|
||||
|
||||
private static ApprovalInfo fromApprovalInfo(ChangeJson.ApprovalInfo ai) {
|
||||
ApprovalInfo ao = new ApprovalInfo();
|
||||
ao.value = ai.value;
|
||||
ao.date = ai.date;
|
||||
fromAccount(ai, ao);
|
||||
return ao;
|
||||
}
|
||||
|
||||
private static AccountInfo fromAcountInfo(
|
||||
com.google.gerrit.server.account.AccountInfo i) {
|
||||
AccountInfo ai = new AccountInfo();
|
||||
fromAccount(i, ai);
|
||||
return ai;
|
||||
}
|
||||
|
||||
private static void fromAccount(
|
||||
com.google.gerrit.server.account.AccountInfo i, AccountInfo ai) {
|
||||
ai._accountId = i._accountId;
|
||||
ai.email = i.email;
|
||||
ai.name = i.name;
|
||||
ai.username = i.username;
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,12 @@ 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.extensions.common.ActionInfo;
|
||||
import com.google.gerrit.extensions.common.CommitInfo;
|
||||
import com.google.gerrit.extensions.common.FetchInfo;
|
||||
import com.google.gerrit.extensions.common.GitPerson;
|
||||
import com.google.gerrit.extensions.common.ListChangesOption;
|
||||
import com.google.gerrit.extensions.common.RevisionInfo;
|
||||
import com.google.gerrit.extensions.config.DownloadCommand;
|
||||
import com.google.gerrit.extensions.config.DownloadScheme;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
@@ -75,7 +80,6 @@ import com.google.gerrit.server.AnonymousUser;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountInfo;
|
||||
import com.google.gerrit.server.actions.ActionInfo;
|
||||
import com.google.gerrit.server.extensions.webui.UiActions;
|
||||
import com.google.gerrit.server.git.LabelNormalizer;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
@@ -308,11 +312,11 @@ public class ChangeJson {
|
||||
// list permitted labels, since users can't vote on those patch sets.
|
||||
if (!limitToPsId.isPresent()
|
||||
|| limitToPsId.get().equals(in.currentPatchSetId())) {
|
||||
out.permitted_labels = permittedLabels(cd);
|
||||
out.permittedLabels = permittedLabels(cd);
|
||||
}
|
||||
out.removable_reviewers = removableReviewers(cd, out.labels.values());
|
||||
out.removableReviewers = removableReviewers(cd, out.labels.values());
|
||||
}
|
||||
if (options.contains(MESSAGES)) {
|
||||
if (has(MESSAGES)) {
|
||||
out.messages = messages(cd);
|
||||
}
|
||||
out.finish();
|
||||
@@ -324,7 +328,7 @@ public class ChangeJson {
|
||||
if (out.revisions != null) {
|
||||
for (Map.Entry<String, RevisionInfo> entry : out.revisions.entrySet()) {
|
||||
if (entry.getValue().isCurrent) {
|
||||
out.current_revision = entry.getKey();
|
||||
out.currentRevision = entry.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -917,7 +921,7 @@ public class ChangeJson {
|
||||
DownloadCommand command = e2.getProvider().get();
|
||||
String c = command.getCommand(scheme, projectName, refName);
|
||||
if (c != null) {
|
||||
fetchInfo.addCommand(commandName, c);
|
||||
addCommand(fetchInfo, commandName, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -926,6 +930,13 @@ public class ChangeJson {
|
||||
return r;
|
||||
}
|
||||
|
||||
private void addCommand(FetchInfo fetchInfo, String commandName, String c) {
|
||||
if (fetchInfo.commands == null) {
|
||||
fetchInfo.commands = Maps.newTreeMap();
|
||||
}
|
||||
fetchInfo.commands.put(commandName, c);
|
||||
}
|
||||
|
||||
private static GitPerson toGitPerson(UserIdentity committer) {
|
||||
GitPerson p = new GitPerson();
|
||||
p.name = committer.getName();
|
||||
@@ -959,11 +970,11 @@ public class ChangeJson {
|
||||
|
||||
public Map<String, ActionInfo> actions;
|
||||
public Map<String, LabelInfo> labels;
|
||||
public Map<String, Collection<String>> permitted_labels;
|
||||
public Collection<AccountInfo> removable_reviewers;
|
||||
public Map<String, Collection<String>> permittedLabels;
|
||||
public Collection<AccountInfo> removableReviewers;
|
||||
public Collection<ChangeMessageInfo> messages;
|
||||
|
||||
public String current_revision;
|
||||
public String currentRevision;
|
||||
public Map<String, RevisionInfo> revisions;
|
||||
public Boolean _moreChanges;
|
||||
|
||||
@@ -975,52 +986,6 @@ public class ChangeJson {
|
||||
}
|
||||
}
|
||||
|
||||
public static class RevisionInfo {
|
||||
private transient boolean isCurrent;
|
||||
public Boolean draft;
|
||||
public Boolean hasDraftComments;
|
||||
public int _number;
|
||||
public Map<String, FetchInfo> fetch;
|
||||
public CommitInfo commit;
|
||||
public Map<String, FileInfoJson.FileInfo> files;
|
||||
public Map<String, ActionInfo> actions;
|
||||
}
|
||||
|
||||
public static class FetchInfo {
|
||||
public String url;
|
||||
public String ref;
|
||||
public Map<String, String> commands;
|
||||
|
||||
FetchInfo(String url, String ref) {
|
||||
this.url = url;
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
void addCommand(String name, String command) {
|
||||
if (commands == null) {
|
||||
commands = Maps.newTreeMap();
|
||||
}
|
||||
commands.put(name, command);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GitPerson {
|
||||
public String name;
|
||||
public String email;
|
||||
public Timestamp date;
|
||||
public int tz;
|
||||
}
|
||||
|
||||
public static class CommitInfo {
|
||||
public final String kind = "gerritcodereview#commit";
|
||||
public String commit;
|
||||
public List<CommitInfo> parents;
|
||||
public GitPerson author;
|
||||
public GitPerson committer;
|
||||
public String subject;
|
||||
public String message;
|
||||
}
|
||||
|
||||
public static class LabelInfo {
|
||||
transient SubmitRecord.Label.Status _status;
|
||||
|
||||
|
||||
@@ -16,10 +16,11 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.common.FileInfo;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
|
||||
import com.google.gerrit.server.patch.PatchList;
|
||||
import com.google.gerrit.server.patch.PatchListCache;
|
||||
import com.google.gerrit.server.patch.PatchListEntry;
|
||||
@@ -55,7 +56,7 @@ public class FileInfoJson {
|
||||
|
||||
Map<String, FileInfo> files = Maps.newTreeMap();
|
||||
for (PatchListEntry e : list.getPatches()) {
|
||||
FileInfoJson.FileInfo d = new FileInfoJson.FileInfo();
|
||||
FileInfo d = new FileInfo();
|
||||
d.status = e.getChangeType() != Patch.ChangeType.MODIFIED
|
||||
? e.getChangeType().getCode() : null;
|
||||
d.oldPath = e.getOldName();
|
||||
@@ -66,7 +67,7 @@ public class FileInfoJson {
|
||||
d.linesDeleted = e.getDeletions() > 0 ? e.getDeletions() : null;
|
||||
}
|
||||
|
||||
FileInfoJson.FileInfo o = files.put(e.getNewName(), d);
|
||||
FileInfo o = files.put(e.getNewName(), d);
|
||||
if (o != null) {
|
||||
// This should only happen on a delete-add break created by JGit
|
||||
// when the file was rewritten and too little content survived. Write
|
||||
@@ -85,12 +86,4 @@ public class FileInfoJson {
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
static class FileInfo {
|
||||
Character status;
|
||||
Boolean binary;
|
||||
String oldPath;
|
||||
Integer linesInserted;
|
||||
Integer linesDeleted;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.extensions.common.FileInfo;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
@@ -33,7 +34,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.change.FileInfoJson.FileInfo;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.patch.PatchList;
|
||||
import com.google.gerrit.server.patch.PatchListCache;
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.extensions.common.CommitInfo;
|
||||
import com.google.gerrit.extensions.restapi.CacheControl;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.change.ChangeJson.CommitInfo;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -20,13 +20,13 @@ import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.common.CommitInfo;
|
||||
import com.google.gerrit.extensions.common.GitPerson;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetAncestor;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.change.ChangeJson.CommitInfo;
|
||||
import com.google.gerrit.server.change.ChangeJson.GitPerson;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
|
||||
@@ -83,7 +83,7 @@ public class ListMembers implements RestReadView<GroupResource> {
|
||||
return ComparisonChain.start()
|
||||
.compare(a.name, b.name, Ordering.natural().nullsFirst())
|
||||
.compare(a.email, b.email, Ordering.natural().nullsFirst())
|
||||
.compare(a._account_id, b._account_id, Ordering.natural().nullsFirst()).result();
|
||||
.compare(a._accountId, b._accountId, Ordering.natural().nullsFirst()).result();
|
||||
}
|
||||
});
|
||||
return memberInfos;
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.google.gerrit.server.project;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.extensions.common.ActionInfo;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap.Entry;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
@@ -24,7 +25,6 @@ import com.google.gerrit.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
|
||||
import com.google.gerrit.reviewdb.client.Project.SubmitType;
|
||||
import com.google.gerrit.server.actions.ActionInfo;
|
||||
import com.google.gerrit.server.config.AllProjectsNameProvider;
|
||||
import com.google.gerrit.server.config.PluginConfig;
|
||||
import com.google.gerrit.server.config.PluginConfigFactory;
|
||||
|
||||
Reference in New Issue
Block a user