use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class PostReviewIT method restrictNumberOfComments.
@Test
@GerritConfig(name = "change.maxComments", value = "7")
public void restrictNumberOfComments() throws Exception {
when(mockCommentValidator.validateComments(any(), any())).thenReturn(ImmutableList.of());
PushOneCommit.Result r = createChange();
String filePath = r.getChange().currentFilePaths().get(0);
CommentInput commentInput = new CommentInput();
commentInput.line = 1;
commentInput.message = "foo";
commentInput.path = filePath;
RobotCommentInput robotCommentInput = TestCommentHelper.createRobotCommentInputWithMandatoryFields(filePath);
ReviewInput reviewInput = new ReviewInput();
reviewInput.comments = ImmutableMap.of(filePath, ImmutableList.of(commentInput));
reviewInput.robotComments = ImmutableMap.of(filePath, ImmutableList.of(robotCommentInput));
gApi.changes().id(r.getChangeId()).current().review(reviewInput);
// Counting change messages plus comments we now have 4.
// reviewInput still has both a user and a robot comment (and deduplication is false). We also
// create a draft, and there's the change message, so that in total there would be 8 comments.
// The limit is set to 7, so this verifies that all new comments are considered.
DraftInput draftInline = testCommentHelper.newDraft(filePath, Side.REVISION, 1, "a draft");
testCommentHelper.addDraft(r.getChangeId(), r.getPatchSetId().getId(), draftInline);
reviewInput.drafts = DraftHandling.PUBLISH;
reviewInput.omitDuplicateComments = false;
BadRequestException exception = assertThrows(BadRequestException.class, () -> gApi.changes().id(r.getChangeId()).current().review(reviewInput));
assertThat(exception).hasMessageThat().contains("Exceeding maximum number of comments: 4 (existing) + 4 (new) > 7");
assertThat(testCommentHelper.getPublishedComments(r.getChangeId())).hasSize(1);
assertThat(getRobotComments(r.getChangeId())).hasSize(1);
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class RevertIT method revertSubmissionMultipleBranches.
@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void revertSubmissionMultipleBranches() throws Exception {
List<PushOneCommit.Result> resultCommits = new ArrayList<>();
String topic = "topic";
resultCommits.add(createChange(testRepo, "master", "first change", "c.txt", "message", topic));
testRepo.reset("HEAD~1");
createBranch(BranchNameKey.create(project, "other"));
resultCommits.add(createChange(testRepo, "other", "second change", "a.txt", "message", topic));
resultCommits.add(createChange(testRepo, "other", "third change", "b.txt", "Other message", topic));
for (PushOneCommit.Result result : resultCommits) {
approve(result.getChangeId());
}
// submit all changes
gApi.changes().id(resultCommits.get(1).getChangeId()).current().submit();
RevertSubmissionInfo revertSubmissionInfo = gApi.changes().id(resultCommits.get(1).getChangeId()).revertSubmission();
assertThat(revertSubmissionInfo.revertChanges.stream().map(change -> change.created).distinct().count()).isEqualTo(1);
List<ChangeApi> revertChanges = getChangeApis(revertSubmissionInfo);
assertThat(revertChanges.get(0).current().files().get("c.txt").linesDeleted).isEqualTo(1);
assertThat(revertChanges.get(1).current().files().get("a.txt").linesDeleted).isEqualTo(1);
assertThat(revertChanges.get(2).current().files().get("b.txt").linesDeleted).isEqualTo(1);
String sha1FirstChange = resultCommits.get(0).getCommit().getName();
String sha1ThirdChange = resultCommits.get(2).getCommit().getName();
String sha1SecondRevert = revertChanges.get(2).current().commit(false).commit;
assertThat(revertChanges.get(0).current().commit(false).parents.get(0).commit).isEqualTo(sha1FirstChange);
assertThat(revertChanges.get(2).current().commit(false).parents.get(0).commit).isEqualTo(sha1ThirdChange);
assertThat(revertChanges.get(1).current().commit(false).parents.get(0).commit).isEqualTo(sha1SecondRevert);
assertThat(revertChanges).hasSize(3);
assertThat(gApi.changes().id(revertChanges.get(1).id()).current().related().changes).hasSize(2);
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class RevertIT method revertSubmissionDependantAndUnrelatedWithMerge.
@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void revertSubmissionDependantAndUnrelatedWithMerge() throws Exception {
String topic = "topic";
PushOneCommit.Result firstResult = createChange(testRepo, "master", "first change", "a.txt", "message", topic);
approve(firstResult.getChangeId());
PushOneCommit.Result secondResult = createChange(testRepo, "master", "second change", "b.txt", "message", topic);
approve(secondResult.getChangeId());
testRepo.reset("HEAD~1");
PushOneCommit.Result thirdResult = createChange(testRepo, "master", "third change", "c.txt", "message", topic);
approve(thirdResult.getChangeId());
gApi.changes().id(firstResult.getChangeId()).current().submit();
// put the head on the merge commit created by submitting the second and third change.
testRepo.git().fetch().setRefSpecs(new RefSpec("refs/heads/master:merge")).call();
testRepo.reset("merge");
// Create another change that should be ignored. The reverts should be rebased on top of the
// merge commit.
PushOneCommit.Result fourthResult = createChange(testRepo, "master", "fourth change", "d.txt", "message", topic);
approve(fourthResult.getChangeId());
gApi.changes().id(fourthResult.getChangeId()).current().submit();
RevertSubmissionInfo revertSubmissionInfo = gApi.changes().id(secondResult.getChangeId()).revertSubmission();
assertThat(revertSubmissionInfo.revertChanges.stream().map(change -> change.created).distinct().count()).isEqualTo(1);
List<ChangeApi> revertChanges = getChangeApis(revertSubmissionInfo);
Collections.reverse(revertChanges);
assertThat(revertChanges.get(0).current().files().get("c.txt").linesDeleted).isEqualTo(1);
assertThat(revertChanges.get(1).current().files().get("b.txt").linesDeleted).isEqualTo(1);
assertThat(revertChanges.get(2).current().files().get("a.txt").linesDeleted).isEqualTo(1);
String sha1FirstRevert = revertChanges.get(0).current().commit(false).commit;
String sha1SecondRevert = revertChanges.get(1).current().commit(false).commit;
// parent of the first revert is the merged change of previous changes.
assertThat(revertChanges.get(0).current().commit(false).parents.get(0).subject).contains("Merge");
// Next reverts would stack on top of the previous ones.
assertThat(revertChanges.get(1).current().commit(false).parents.get(0).commit).isEqualTo(sha1FirstRevert);
assertThat(revertChanges.get(2).current().commit(false).parents.get(0).commit).isEqualTo(sha1SecondRevert);
assertThat(revertChanges).hasSize(3);
assertThat(gApi.changes().id(revertChanges.get(1).id()).current().related().changes).hasSize(3);
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class RevertIT method revertSubmissionUnrelatedWithAnotherDependantChangeWithDifferentTopic.
@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void revertSubmissionUnrelatedWithAnotherDependantChangeWithDifferentTopic() throws Exception {
String topic = "topic";
PushOneCommit.Result firstResult = createChange(testRepo, "master", "first change", "a.txt", "message", topic);
approve(firstResult.getChangeId());
testRepo.reset("HEAD~1");
PushOneCommit.Result secondResult = createChange(testRepo, "master", "second change", "b.txt", "message", topic);
approve(secondResult.getChangeId());
// A non-merged change without the same topic that is related to the second change.
createChange();
gApi.changes().id(firstResult.getChangeId()).current().submit();
RevertSubmissionInfo revertSubmissionInfo = gApi.changes().id(secondResult.getChangeId()).revertSubmission();
List<ChangeApi> revertChanges = getChangeApis(revertSubmissionInfo);
Collections.reverse(revertChanges);
assertThat(revertChanges.get(0).current().files().get("b.txt").linesDeleted).isEqualTo(1);
assertThat(revertChanges.get(1).current().files().get("a.txt").linesDeleted).isEqualTo(1);
// The parent of the first revert is the merge change of the submission.
assertThat(revertChanges.get(0).current().commit(false).parents.get(0).subject).contains("Merge \"second change\"");
// Next revert would base itself on the previous revert.
String sha1FirstRevert = revertChanges.get(0).current().commit(false).commit;
assertThat(revertChanges.get(1).current().commit(false).parents.get(0).commit).isEqualTo(sha1FirstRevert);
assertThat(revertChanges).hasSize(2);
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class QueryChangesIT method aliasQuery.
@Test
@SuppressWarnings("unchecked")
@GerritConfig(name = "operator-alias.change.numberaliastest", value = "change")
public void aliasQuery() throws Exception {
String cId1 = createChange().getChangeId();
String cId2 = createChange().getChangeId();
int numericId1 = gApi.changes().id(cId1).get()._number;
int numericId2 = gApi.changes().id(cId2).get()._number;
QueryChanges queryChanges = queryChangesProvider.get();
queryChanges.addQuery("numberaliastest:12345");
queryChanges.addQuery("numberaliastest:" + numericId1);
queryChanges.addQuery("numberaliastest:" + numericId2);
List<List<ChangeInfo>> result = (List<List<ChangeInfo>>) queryChanges.apply(TopLevelResource.INSTANCE).value();
assertThat(result).hasSize(3);
assertThat(result.get(0)).hasSize(0);
assertThat(result.get(1)).hasSize(1);
assertThat(result.get(2)).hasSize(1);
assertThat(result.get(1).get(0)._number).isEqualTo(numericId1);
assertThat(result.get(2).get(0)._number).isEqualTo(numericId2);
}
Aggregations