GetChange: populate ChangeInfo.metaRevId with the NoteDb meta ref SHA1
The NoteDb meta SHA1 is the unique identifier the state of a change, together with the robot-comment SHA1. Change-Id: I8b4cf63f9e8255ab9c2d91ddf002820f46a288c8
This commit is contained in:
@@ -6467,6 +6467,8 @@ patch set to a link:#revision-info[RevisionInfo] entity. +
|
|||||||
Only set if link:#current-revision[the current revision] is requested
|
Only set if link:#current-revision[the current revision] is requested
|
||||||
(in which case it will only contain a key for the current revision) or
|
(in which case it will only contain a key for the current revision) or
|
||||||
if link:#all-revisions[all revisions] are requested.
|
if link:#all-revisions[all revisions] are requested.
|
||||||
|
|`meta_rev_id` |optional|
|
||||||
|
The SHA1 of the NoteDb meta ref.
|
||||||
|`tracking_ids` |optional|
|
|`tracking_ids` |optional|
|
||||||
A list of link:#tracking-id-info[TrackingIdInfo] entities describing
|
A list of link:#tracking-id-info[TrackingIdInfo] entities describing
|
||||||
references to external tracking systems. Only set if
|
references to external tracking systems. Only set if
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public class ChangeInfo {
|
|||||||
public String submissionId;
|
public String submissionId;
|
||||||
public Integer cherryPickOfChange;
|
public Integer cherryPickOfChange;
|
||||||
public Integer cherryPickOfPatchSet;
|
public Integer cherryPickOfPatchSet;
|
||||||
|
public String metaRevId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the change contains conflicts.
|
* Whether the change contains conflicts.
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ import com.google.gerrit.entities.ChangeMessage;
|
|||||||
import com.google.gerrit.entities.PatchSet;
|
import com.google.gerrit.entities.PatchSet;
|
||||||
import com.google.gerrit.entities.PatchSetApproval;
|
import com.google.gerrit.entities.PatchSetApproval;
|
||||||
import com.google.gerrit.entities.Project;
|
import com.google.gerrit.entities.Project;
|
||||||
|
import com.google.gerrit.entities.RefNames;
|
||||||
import com.google.gerrit.entities.SubmitRecord;
|
import com.google.gerrit.entities.SubmitRecord;
|
||||||
import com.google.gerrit.entities.SubmitRecord.Status;
|
import com.google.gerrit.entities.SubmitRecord.Status;
|
||||||
import com.google.gerrit.entities.SubmitRequirement;
|
import com.google.gerrit.entities.SubmitRequirement;
|
||||||
@@ -75,6 +76,7 @@ import com.google.gerrit.extensions.common.RevisionInfo;
|
|||||||
import com.google.gerrit.extensions.common.SubmitRequirementInfo;
|
import com.google.gerrit.extensions.common.SubmitRequirementInfo;
|
||||||
import com.google.gerrit.extensions.common.TrackingIdInfo;
|
import com.google.gerrit.extensions.common.TrackingIdInfo;
|
||||||
import com.google.gerrit.extensions.restapi.Url;
|
import com.google.gerrit.extensions.restapi.Url;
|
||||||
|
import com.google.gerrit.index.RefState;
|
||||||
import com.google.gerrit.index.query.QueryResult;
|
import com.google.gerrit.index.query.QueryResult;
|
||||||
import com.google.gerrit.metrics.Description;
|
import com.google.gerrit.metrics.Description;
|
||||||
import com.google.gerrit.metrics.Description.Units;
|
import com.google.gerrit.metrics.Description.Units;
|
||||||
@@ -570,6 +572,15 @@ public class ChangeJson {
|
|||||||
out.totalCommentCount = cd.totalCommentCount();
|
out.totalCommentCount = cd.totalCommentCount();
|
||||||
out.unresolvedCommentCount = cd.unresolvedCommentCount();
|
out.unresolvedCommentCount = cd.unresolvedCommentCount();
|
||||||
|
|
||||||
|
if (cd.getRefStates() != null) {
|
||||||
|
String metaName = RefNames.changeMetaRef(cd.getId());
|
||||||
|
Optional<RefState> metaState =
|
||||||
|
cd.getRefStates().values().stream().filter(r -> r.ref().equals(metaName)).findAny();
|
||||||
|
|
||||||
|
// metaState should always be there, but it doesn't hurt to be extra careful.
|
||||||
|
metaState.ifPresent(rs -> out.metaRevId = rs.id().getName());
|
||||||
|
}
|
||||||
|
|
||||||
if (user.isIdentifiedUser()) {
|
if (user.isIdentifiedUser()) {
|
||||||
Collection<String> stars = cd.stars(user.getAccountId());
|
Collection<String> stars = cd.stars(user.getAccountId());
|
||||||
out.starred = stars.contains(StarredChangesUtil.DEFAULT_LABEL) ? true : null;
|
out.starred = stars.contains(StarredChangesUtil.DEFAULT_LABEL) ? true : null;
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
// Copyright (C) 2017 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.acceptance.rest.change;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static com.google.gerrit.entities.RefNames.changeMetaRef;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
|
import com.google.gerrit.entities.Change;
|
||||||
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
|
import org.eclipse.jgit.lib.Repository;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/** Test handling of the NoteDb commit hash in the GetChange endpoint */
|
||||||
|
public class ChangeMetaIT extends AbstractDaemonTest {
|
||||||
|
@Test
|
||||||
|
public void metaSha1_fromIndex() throws Exception {
|
||||||
|
PushOneCommit.Result result = createChange();
|
||||||
|
String changeId = result.getChangeId();
|
||||||
|
|
||||||
|
try (AutoCloseable ignored = disableNoteDb()) {
|
||||||
|
ChangeInfo change =
|
||||||
|
Iterables.getOnlyElement(gApi.changes().query().withQuery("change:" + changeId).get());
|
||||||
|
|
||||||
|
try (Repository repo = repoManager.openRepository(project)) {
|
||||||
|
assertThat(change.metaRevId)
|
||||||
|
.isEqualTo(
|
||||||
|
repo.exactRef(changeMetaRef(Change.id(change._number))).getObjectId().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void metaSha1_fromNoteDb() throws Exception {
|
||||||
|
PushOneCommit.Result result = createChange();
|
||||||
|
String changeId = result.getChangeId();
|
||||||
|
ChangeInfo before = gApi.changes().id(changeId).get();
|
||||||
|
try (Repository repo = repoManager.openRepository(project)) {
|
||||||
|
assertThat(before.metaRevId)
|
||||||
|
.isEqualTo(
|
||||||
|
repo.exactRef(changeMetaRef(Change.id(before._number))).getObjectId().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user