use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.
the class CreateChangeIT method createNewChangeSignedOffByFooterWithChangeId.
@Test
public void createNewChangeSignedOffByFooterWithChangeId() throws Exception {
setSignedOffByFooter(true);
try {
ChangeInput ci = newChangeInput(ChangeStatus.NEW);
String changeId = "I1234000000000000000000000000000000000000";
String changeIdLine = "Change-Id: " + changeId;
ci.subject = "Subject\n\n" + changeIdLine;
ChangeInfo info = assertCreateSucceeds(ci);
assertThat(info.changeId).isEqualTo(changeId);
String message = info.revisions.get(info.currentRevision).commit.message;
assertThat(message).contains(changeIdLine);
assertThat(message).contains(String.format("%sAdministrator <%s>", SIGNED_OFF_BY_TAG, admin.newIdent().getEmailAddress()));
} finally {
setSignedOffByFooter(false);
}
}
use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.
the class QueryChanges method query.
private List<List<ChangeInfo>> query() throws QueryParseException, PermissionBackendException {
ChangeQueryProcessor queryProcessor = queryProcessorProvider.get();
if (queryProcessor.isDisabled()) {
throw new QueryParseException("query disabled");
}
if (limit != null) {
queryProcessor.setUserProvidedLimit(limit);
}
if (start != null) {
queryProcessor.setStart(start);
}
if (noLimit != null) {
queryProcessor.setNoLimit(noLimit);
}
if (skipVisibility != null) {
queryProcessor.enforceVisibility(!skipVisibility);
}
dynamicBeans.forEach((p, b) -> queryProcessor.setDynamicBean(p, b));
if (queries == null || queries.isEmpty()) {
queries = Collections.singletonList("status:open");
} else if (queries.size() > 10) {
// users from submitting too much to the server in a single call.
throw new QueryParseException("limit of 10 queries");
}
int cnt = queries.size();
List<QueryResult<ChangeData>> results = queryProcessor.query(qb.parse(queries));
List<List<ChangeInfo>> res = json.create(options, queryProcessor.getInfosFactory()).format(results);
for (int n = 0; n < cnt; n++) {
List<ChangeInfo> info = res.get(n);
if (results.get(n).more() && !info.isEmpty()) {
Iterables.getLast(info)._moreChanges = true;
}
}
return res;
}
use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.
the class Rebase method apply.
@Override
public Response<ChangeInfo> apply(RevisionResource rsrc, RebaseInput input) throws UpdateException, RestApiException, IOException, PermissionBackendException {
// Not allowed to rebase if the current patch set is locked.
patchSetUtil.checkPatchSetNotLocked(rsrc.getNotes());
rsrc.permissions().check(ChangePermission.REBASE);
projectCache.get(rsrc.getProject()).orElseThrow(illegalState(rsrc.getProject())).checkStatePermitsWrite();
Change change = rsrc.getChange();
try (Repository repo = repoManager.openRepository(change.getProject());
ObjectInserter oi = repo.newObjectInserter();
ObjectReader reader = oi.newReader();
RevWalk rw = CodeReviewCommit.newRevWalk(reader);
BatchUpdate bu = updateFactory.create(change.getProject(), rsrc.getUser(), TimeUtil.now())) {
if (!change.isNew()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} else if (!hasOneParent(rw, rsrc.getPatchSet())) {
throw new ResourceConflictException("cannot rebase merge commits or commit with no ancestor");
}
RebaseChangeOp rebaseOp = rebaseFactory.create(rsrc.getNotes(), rsrc.getPatchSet(), findBaseRev(repo, rw, rsrc, input)).setForceContentMerge(true).setAllowConflicts(input.allowConflicts).setValidationOptions(getValidateOptionsAsMultimap(input.validationOptions)).setFireRevisionCreated(true);
// TODO(dborowitz): Why no notification? This seems wrong; dig up blame.
bu.setNotify(NotifyResolver.Result.none());
bu.setRepository(repo, rw, oi);
bu.addOp(change.getId(), rebaseOp);
bu.execute();
ChangeInfo changeInfo = json.create(OPTIONS).format(change.getProject(), change.getId());
changeInfo.containsGitConflicts = !rebaseOp.getRebasedCommit().getFilesWithGitConflicts().isEmpty() ? true : null;
return Response.ok(changeInfo);
}
}
use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.
the class AbstractPushForReview method testPushInitialCommitSeriesForMasterBranch.
private void testPushInitialCommitSeriesForMasterBranch() throws Exception {
RevCommit c = testRepo.commit().message("Initial commit").insertChangeId().create();
String id = GitUtil.getChangeId(testRepo, c).get();
testRepo.reset(c);
RevCommit c2 = testRepo.commit().parent(c).message("Second commit").insertChangeId().create();
String id2 = GitUtil.getChangeId(testRepo, c2).get();
testRepo.reset(c2);
String r = "refs/for/master";
PushResult pr = pushHead(testRepo, r, false);
assertPushOk(pr, r);
ChangeInfo change = gApi.changes().id(id).info();
assertThat(change.branch).isEqualTo("master");
assertThat(change.status).isEqualTo(ChangeStatus.NEW);
ChangeInfo change2 = gApi.changes().id(id2).info();
assertThat(change2.branch).isEqualTo("master");
assertThat(change2.status).isEqualTo(ChangeStatus.NEW);
try (Repository repo = repoManager.openRepository(project)) {
assertThat(repo.resolve("master")).isNull();
}
gApi.changes().id(change.id).current().review(ReviewInput.approve());
gApi.changes().id(change.id).current().submit();
try (Repository repo = repoManager.openRepository(project)) {
assertThat(repo.resolve("master")).isEqualTo(c);
}
gApi.changes().id(change2.id).current().review(ReviewInput.approve());
gApi.changes().id(change2.id).current().submit();
try (Repository repo = repoManager.openRepository(project)) {
assertThat(repo.resolve("master")).isEqualTo(c2);
}
}
use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushForMasterWithInvalidPercentEncodedMessage.
@Test
public void pushForMasterWithInvalidPercentEncodedMessage() throws Exception {
PushOneCommit.Result r = pushTo("refs/for/master%m=not_percent_decodable_%%oops%20");
r.assertOkStatus();
r.assertChange(Change.Status.NEW, null);
ChangeInfo ci = get(r.getChangeId(), MESSAGES, ALL_REVISIONS);
Collection<ChangeMessageInfo> changeMessages = ci.messages;
assertThat(changeMessages).hasSize(1);
for (ChangeMessageInfo cm : changeMessages) {
assertThat(cm.message).isEqualTo("Uploaded patch set 1.\nnot percent decodable %%oops%20");
}
Collection<RevisionInfo> revisions = ci.revisions.values();
assertThat(revisions).hasSize(1);
for (RevisionInfo ri : revisions) {
assertThat(ri.description).isEqualTo("not percent decodable %%oops%20");
}
}
Aggregations