Skip to content

Commit

Permalink
refactor(ng-dev/pr): move overall CI pending/failing check to common …
Browse files Browse the repository at this point in the history
…valiations

Move the check of the overall CI pending or failing check to the common validations.
  • Loading branch information
josephperrott committed Sep 27, 2021
1 parent cc3a89b commit 4737402
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
14 changes: 14 additions & 0 deletions ng-dev/pr/common/validation/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ export function assertMergeReady(pullRequest: PullRequestFromGithub, config: Pul
throw PullRequestFailure.notMergeReady();
}

/**
* Assert the pull request has been marked ready for merge by the author.
* @throws {PullRequestFailure} if the pull request is missing the merge ready label.
*/
export function assertPassingCi(pullRequest: PullRequestFromGithub) {
const {combinedStatus} = getStatusesForPullRequest(pullRequest);
if (combinedStatus === PullRequestStatus.PENDING) {
throw PullRequestFailure.pendingCiJobs();
}
if (combinedStatus === PullRequestStatus.FAILING) {
throw PullRequestFailure.failingCiJobs();
}
}

// TODO: Remove need to export this pattern matching utility.
/** Checks whether the specified value matches the given pattern. */
export function matchesPattern(value: string, pattern: RegExp | string): boolean {
Expand Down
20 changes: 6 additions & 14 deletions ng-dev/pr/merge/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ import {
matchesPattern,
assertPendingState,
assertSignedCla,
assertPassingCi,
} from '../common/validation/validations';
import {
fetchPullRequestFromGithub,
getStatusesForPullRequest,
PullRequestStatus,
} from '../common/fetch-pull-request';
import {fetchPullRequestFromGithub} from '../common/fetch-pull-request';

/** Interface that describes a pull request. */
export interface PullRequest {
Expand Down Expand Up @@ -81,6 +78,10 @@ export async function loadAndValidatePullRequest(
assertSignedCla(prData);
assertPendingState(prData);
assertCorrectBreakingChangeLabeling(commitsInPr, labels);

if (!ignoreNonFatalFailures) {
assertPassingCi(prData);
}
} catch (error) {
// If the error is a pull request failure, we pass it through gracefully
// as the tool expects such failures to be returned from the function.
Expand All @@ -90,15 +91,6 @@ export async function loadAndValidatePullRequest(
throw error;
}

/** The combined status of the latest commit in the pull request. */
const {combinedStatus} = getStatusesForPullRequest(prData);
if (combinedStatus === PullRequestStatus.FAILING && !ignoreNonFatalFailures) {
return PullRequestFailure.failingCiJobs();
}
if (combinedStatus === PullRequestStatus.PENDING && !ignoreNonFatalFailures) {
return PullRequestFailure.pendingCiJobs();
}

const requiredBaseSha =
config.pullRequest.requiredBaseCommits &&
config.pullRequest.requiredBaseCommits[githubTargetBranch];
Expand Down

0 comments on commit 4737402

Please sign in to comment.