Skip to content

Commit 731ba87

Browse files
vs-systencessjujokini
authored andcommitted
Keep status of non-staged cherry-picked changes on build approve
A fix on build approve method. When running 'build approve' after merging a branch to another branch, an incorrect status change was fulfilled: The status of cherry picked change (on targed branch) was changed from new/abandoned to merged. This occurred because cherry picked change had the same change-id as one of the merged changes on source branch. Fixes: QTQAINFRA-3411 Fixes: QTQAINFRA-3374 Change-Id: Ie04c5268b0196f5ff9e43618fe93c300865b9ea6 Reviewed-by: Jukka Jokiniva <[email protected]>
1 parent 4305930 commit 731ba87

File tree

3 files changed

+76
-7
lines changed

3 files changed

+76
-7
lines changed

src/main/java/com/googlesource/gerrit/plugins/qtcodereview/QtCommandBuildApprove.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private void approveBuildChanges()
236236
}
237237

238238
updateChanges(
239-
affectedChanges, Change.Status.MERGED, null, message, ChangeMessagesUtil.TAG_MERGED, true);
239+
affectedChanges, Change.Status.MERGED, Change.Status.INTEGRATING, message, ChangeMessagesUtil.TAG_MERGED, true);
240240

241241
logger.atInfo().log(
242242
"qtcodereview: staging-approve build %s merged into branch %s", buildBranch, destBranchKey);
@@ -273,7 +273,7 @@ private void rejectBuildChanges()
273273

274274
private void updateChanges(
275275
List<Entry<ChangeData, RevCommit>> list,
276-
Change.Status status,
276+
Change.Status newStatus,
277277
Change.Status oldStatus,
278278
String changeMessage,
279279
String tag,
@@ -284,14 +284,13 @@ private void updateChanges(
284284
new ArrayList<Map.Entry<ChangeData, RevCommit>>();
285285

286286
// do the db update
287-
QtChangeUpdateOp op = qtUpdateFactory.create(status, oldStatus, changeMessage, null, tag, null);
287+
QtChangeUpdateOp op = qtUpdateFactory.create(newStatus, oldStatus, changeMessage, null, tag, null);
288288
try (BatchUpdate u = updateFactory.create(projectKey, user, TimeUtil.nowTs())) {
289289
for (Entry<ChangeData, RevCommit> item : list) {
290290
ChangeData cd = item.getKey();
291291
Change change = cd.change();
292-
if ((oldStatus == null || change.getStatus() == oldStatus)
293-
&& change.getStatus() != Change.Status.MERGED) {
294-
if (status == Change.Status.MERGED) {
292+
if (change.getStatus() == oldStatus) {
293+
if (newStatus == Change.Status.MERGED) {
295294
ObjectId obj = git.resolve(cd.currentPatchSet().getRevision().get());
296295
CodeReviewCommit currCommit = new CodeReviewCommit(obj);
297296
currCommit.setPatchsetId(cd.currentPatchSet().getId());
@@ -303,7 +302,7 @@ private void updateChanges(
303302
}
304303
u.addOp(
305304
changeId,
306-
qtUpdateFactory.create(status, oldStatus, changeMessage, null, tag, currCommit));
305+
qtUpdateFactory.create(newStatus, oldStatus, changeMessage, null, tag, currCommit));
307306
} else {
308307
u.addOp(change.getId(), op);
309308
}

src/test/java/com/googlesource/gerrit/plugins/qtcodereview/QtCodeReviewIT.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.google.gerrit.acceptance.TestAccount;
1515
import com.google.gerrit.acceptance.TestPlugin;
1616
import com.google.gerrit.common.FooterConstants;
17+
import com.google.gerrit.extensions.api.changes.CherryPickInput;
1718
import com.google.gerrit.extensions.client.ChangeStatus;
1819
import com.google.gerrit.extensions.common.ApprovalInfo;
1920
import com.google.gerrit.extensions.common.ChangeInfo;
@@ -103,6 +104,24 @@ protected RestResponse call_REST_API_Stage(String changeId, String revisionId) t
103104
return response;
104105
}
105106

107+
protected ChangeInfo cherryPick(final PushOneCommit.Result c, final String branch) throws Exception {
108+
// If the commit message does not specify a Change-Id, a new one is picked for the destination change.
109+
final CherryPickInput input = new CherryPickInput();
110+
input.message = "CHERRY" + c.getCommit().getFullMessage();
111+
input.destination = branch;
112+
113+
final RestResponse response = call_REST_API_CherryPick(c.getChangeId(), c.getCommit().getName(), input);
114+
response.assertOK();
115+
return newGson().fromJson(response.getReader(), ChangeInfo.class);
116+
}
117+
118+
protected RestResponse call_REST_API_CherryPick(
119+
final String changeId, final String revisionId, final CherryPickInput input)
120+
throws Exception {
121+
final String url = "/changes/" + changeId + "/revisions/" + revisionId + "/cherrypick";
122+
return userRestSession.post(url, input);
123+
}
124+
106125
protected void QtUnStage(PushOneCommit.Result c) throws Exception {
107126
RestResponse response = call_REST_API_UnStage(c.getChangeId(), getCurrentPatchId(c));
108127
response.assertOK();

src/test/java/com/googlesource/gerrit/plugins/qtcodereview/QtCommandBuildApproveIT.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
package com.googlesource.gerrit.plugins.qtcodereview;
44

55
import static com.google.common.truth.Truth.assertThat;
6+
import static com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION;
67
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
78

9+
import com.google.common.collect.ImmutableList;
810
import com.google.gerrit.acceptance.PushOneCommit;
911
import com.google.gerrit.acceptance.TestPlugin;
1012
import com.google.gerrit.acceptance.UseSsh;
1113
import com.google.gerrit.common.data.Permission;
14+
import com.google.gerrit.extensions.api.changes.Changes;
15+
import com.google.gerrit.extensions.client.ChangeStatus;
16+
import com.google.gerrit.extensions.common.ChangeInfo;
17+
import com.google.gerrit.reviewdb.client.Branch;
1218
import com.google.gerrit.reviewdb.client.Change;
1319
import com.google.gerrit.reviewdb.client.ChangeMessage;
1420
import java.io.StringBufferInputStream;
@@ -29,7 +35,10 @@ public class QtCommandBuildApproveIT extends QtCodeReviewIT {
2935

3036
@Before
3137
public void SetDefaultPermissions() throws Exception {
38+
createBranch(new Branch.NameKey(project, "feature"));
39+
3240
grant(project, "refs/heads/master", Permission.QT_STAGE, false, REGISTERED_USERS);
41+
grant(project, "refs/heads/feature", Permission.QT_STAGE, false, REGISTERED_USERS);
3342
grant(project, "refs/staging/*", Permission.PUSH, false, adminGroupUuid());
3443
grant(project, "refs/builds/*", Permission.CREATE, false, adminGroupUuid());
3544
}
@@ -79,6 +88,48 @@ public void singleChange_New_Staged_Integrating_Fail() throws Exception {
7988
RevCommit updatedHead = qtFailBuild("master", "test-build-200", c, initialHead);
8089
}
8190

91+
@Test
92+
public void cherryPicked_Stays_Intact_After_Merge_And_Build() throws Exception {
93+
// make a change on feature branch
94+
final PushOneCommit.Result f1 = pushCommit("feature", "f1-commitmsg", "f1-file", "f1-content");
95+
approve(f1.getChangeId());
96+
gApi.changes().id(f1.getCommit().getName()).current().submit();
97+
98+
// cherry pick it to the master branch (now there are two changes with same change-id)
99+
final ChangeInfo cp = cherryPick(f1, "master");
100+
101+
// make another change on feature branch
102+
final PushOneCommit.Result f2 = pushCommit("feature", "f2-commitmsg", "f2-file", "f2-content");
103+
approve(f2.getChangeId());
104+
QtStage(f2);
105+
QtNewBuild("feature", "feature-build-000");
106+
QtApproveBuild("feature", "feature-build-000");
107+
108+
// make a change on master branch
109+
final PushOneCommit.Result m1 = pushCommit("master", "m1-commitmsg", "m1-file", "m1-content");
110+
approve(m1.getChangeId());
111+
QtStage(m1);
112+
QtNewBuild("master", "master-build-000");
113+
QtApproveBuild("master", "master-build-000");
114+
115+
// merge feature branch into master
116+
final PushOneCommit mm = pushFactory.create(admin.newIdent(), testRepo);
117+
mm.setParents(ImmutableList.of(f2.getCommit(), m1.getCommit()));
118+
final PushOneCommit.Result m = mm.to("refs/for/master");
119+
m.assertOkStatus();
120+
approve(m.getChangeId());
121+
QtStage(m);
122+
QtNewBuild("master", "merge-build-000");
123+
QtApproveBuild("master", "merge-build-000");
124+
125+
final Changes changes = gApi.changes();
126+
assertThat(changes.id(project.get(), "feature", f1.getChangeId()).get(CURRENT_REVISION).status).isEqualTo(ChangeStatus.MERGED);
127+
assertThat(changes.id(project.get(), "feature", f2.getChangeId()).get(CURRENT_REVISION).status).isEqualTo(ChangeStatus.MERGED);
128+
assertThat(changes.id(project.get(), "master", m1.getChangeId()).get(CURRENT_REVISION).status).isEqualTo(ChangeStatus.MERGED);
129+
assertThat(changes.id(project.get(), "master", m.getChangeId()).get(CURRENT_REVISION).status).isEqualTo(ChangeStatus.MERGED);
130+
assertThat(changes.id(project.get(), "master", cp.changeId).get(CURRENT_REVISION).status).isEqualTo(ChangeStatus.NEW);
131+
}
132+
82133
@Test
83134
public void multiChange_New_Staged_Integrating_Failed() throws Exception {
84135
// Push 3 independent commits

0 commit comments

Comments
 (0)