use of com.google.gerrit.extensions.common.MergeableInfo in project gerrit by GerritCodeReview.
the class RevisionIT method assertMergeable.
private void assertMergeable(String id, boolean expected) throws Exception {
MergeableInfo m = gApi.changes().id(id).current().mergeable();
assertThat(m.mergeable).isEqualTo(expected);
assertThat(m.submitType).isEqualTo(SubmitType.MERGE_IF_NECESSARY);
assertThat(m.mergeableInto).isNull();
ChangeInfo c = gApi.changes().id(id).info();
assertThat(c.mergeable).isEqualTo(expected);
}
use of com.google.gerrit.extensions.common.MergeableInfo in project gerrit by GerritCodeReview.
the class RevisionIT method mergeableOtherBranches.
@Test
public void mergeableOtherBranches() throws Exception {
String head = getHead(repo(), HEAD).name();
createBranchWithRevision(BranchNameKey.create(project, "mergeable-other-branch"), head);
createBranchWithRevision(BranchNameKey.create(project, "ignored"), head);
PushOneCommit.Result change1 = createChange();
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().setBranchOrderSection(BranchOrderSection.create(ImmutableList.of("master", "nonexistent", "mergeable-other-branch")));
u.save();
}
MergeableInfo mergeableInfo = gApi.changes().id(change1.getChangeId()).current().mergeableOtherBranches();
assertThat(mergeableInfo.mergeableInto).containsExactly("mergeable-other-branch");
}
use of com.google.gerrit.extensions.common.MergeableInfo in project gerrit by GerritCodeReview.
the class Mergeable method apply.
@Override
public Response<MergeableInfo> apply(RevisionResource resource) throws AuthException, ResourceConflictException, BadRequestException, IOException {
Change change = resource.getChange();
PatchSet ps = resource.getPatchSet();
MergeableInfo result = new MergeableInfo();
if (!change.isNew()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} else if (!ps.id().equals(change.currentPatchSetId())) {
// Only the current revision is mergeable. Others always fail.
return Response.ok(result);
}
ChangeData cd = changeDataFactory.create(resource.getNotes());
result.submitType = getSubmitType(cd);
try (Repository git = gitManager.openRepository(change.getProject())) {
ObjectId commit = ps.commitId();
Ref ref = git.getRefDatabase().exactRef(change.getDest().branch());
ProjectState projectState = projectCache.get(change.getProject()).orElseThrow(illegalState(change.getProject()));
String strategy = mergeUtilFactory.create(projectState).mergeStrategyName();
result.strategy = strategy;
result.mergeable = isMergable(git, change, commit, ref, result.submitType, strategy);
if (otherBranches) {
result.mergeableInto = new ArrayList<>();
Optional<BranchOrderSection> branchOrder = projectState.getBranchOrderSection();
if (branchOrder.isPresent()) {
int prefixLen = Constants.R_HEADS.length();
List<String> names = branchOrder.get().getMoreStable(ref.getName());
Map<String, Ref> refs = git.getRefDatabase().exactRef(names.toArray(new String[names.size()]));
for (String n : names) {
Ref other = refs.get(n);
if (other == null) {
continue;
}
if (cache.get(commit, other, SubmitType.CHERRY_PICK, strategy, change.getDest(), git)) {
result.mergeableInto.add(other.getName().substring(prefixLen));
}
}
}
}
}
return Response.ok(result);
}
use of com.google.gerrit.extensions.common.MergeableInfo in project gerrit by GerritCodeReview.
the class CheckMergeabilityIT method getMergeableInfo.
private MergeableInfo getMergeableInfo(String targetBranch, String source, String strategy) throws Exception {
String url = "/projects/" + project.get() + "/branches/" + targetBranch;
url += "/mergeable?source=" + source;
if (!Strings.isNullOrEmpty(strategy)) {
url += "&strategy=" + strategy;
}
RestResponse r = userRestSession.get(url);
r.assertOK();
MergeableInfo result = newGson().fromJson(r.getReader(), MergeableInfo.class);
r.consume();
return result;
}
use of com.google.gerrit.extensions.common.MergeableInfo in project gerrit by GerritCodeReview.
the class CheckMergeabilityIT method assertCommitMerged.
private void assertCommitMerged(String targetBranch, String source, String strategy) throws Exception {
MergeableInfo mergeableInfo = getMergeableInfo(targetBranch, source, strategy);
assertThat(mergeableInfo.mergeable).isTrue();
assertThat(mergeableInfo.commitMerged).isTrue();
}
Aggregations