use of com.atlassian.stash.util.PageRequestImpl in project stashbot by palantir.
the class PullRequestBuildSuccessMergeCheck method check.
@Override
public void check(@Nonnull MergeRequest mr) {
PullRequest pr = mr.getPullRequest();
Repository repo = pr.getToRef().getRepository();
RepositoryConfiguration rc;
try {
rc = cpm.getRepositoryConfigurationForRepository(repo);
} catch (SQLException e) {
throw new RuntimeException("Unable to get RepositoryConfiguration", e);
}
if (!rc.getCiEnabled()) {
return;
}
if (!cpm.getJobTypeStatusMapping(rc, JobType.VERIFY_PR)) {
// speculative merge builds are disabled
return;
}
if (!pr.getToRef().getId().matches(rc.getVerifyBranchRegex())) {
log.debug("Pull Request " + pr.toString() + " ignored, branch " + pr.getToRef().getId() + " doesn't match verify regex");
return;
}
// First, if strict mode is on, we want to veto for each commit in the PR that is missing a successful verify build
if (rc.getStrictVerifyMode()) {
ChangesetsBetweenRequest cbr = new ChangesetsBetweenRequest.Builder(pr).build();
PageRequest pageReq = new PageRequestImpl(0, 500);
Page<? extends Changeset> page = cs.getChangesetsBetween(cbr, pageReq);
while (true) {
for (Changeset c : page.getValues()) {
log.trace("Processing commit " + c.getId());
BuildStats bs = bss.getStats(c.getId());
if (bs.getSuccessfulCount() == 0) {
mr.veto("Commit " + c.getId() + " not verified", "When in strict verification mode, each commit in the PR must have at least one successful build");
}
}
if (page.getIsLastPage()) {
break;
}
pageReq = page.getNextPageRequest();
page = cs.getChangesetsBetween(cbr, pageReq);
}
}
PullRequestMetadata prm = null;
if (!rc.getRebuildOnTargetUpdate()) {
// we want a PRM which simply matches the fromSha and the pull request ID.
Collection<PullRequestMetadata> prms = cpm.getPullRequestMetadataWithoutToRef(pr);
for (PullRequestMetadata cur : prms) {
if (cur.getFromSha().equals(pr.getFromRef().getLatestChangeset()) && (cur.getOverride() || cur.getSuccess())) {
log.debug("Found match PRM");
log.debug("PRM: success " + cur.getSuccess().toString() + " override " + cur.getOverride().toString());
return;
}
}
prm = cpm.getPullRequestMetadata(pr);
} else {
// Then we want to ensure a build that matches exactly succeeded / was overridden
prm = cpm.getPullRequestMetadata(pr);
}
// Override || Success
if (prm.getOverride() || prm.getSuccess()) {
return;
}
// in all other cases, we want to veto for some reason - but figure out the most accurate reason here.
MergeCheckStatus status;
if (prm.getFailed()) {
status = MergeCheckStatus.BUILD_FAILED;
} else if (prm.getBuildStarted()) {
status = MergeCheckStatus.BUILD_IN_PROGRESS;
} else {
status = MergeCheckStatus.NO_BUILD;
}
mr.veto(status.getSummary(), status.getDescription());
}
Aggregations