Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Status check ignoring #10

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
|ignore_authors|no|`tom, renovate`|Usernames of PR creators who's PRs will be ignored|
|ignore_draft_prs|no|`false`|Whether we should ignore draft PRs when checking reviews, defaults to false|
|ignore_labels|no|`do not merge, blocked`|If provided any PRs with these labels will skip the review reminder check|
|ignore_prs_with_failing_checks|no|`false`|If the PR has any pending or failing status checks, ignore it|
|ignore_prs_with_failing_checks|no|`false`|If the PR has any failing or errored status checks, ignore it|

## Development

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inputs:
description: 'If provided any PRs with these labels will skip the review reminder check'
required: false
ignore_prs_with_failing_checks:
description: 'If the PR has any pending or failing status checks, ignore it'
description: 'If the PR has any failing or errored status checks, ignore it'
required: true
default: false
runs:
Expand Down
18 changes: 10 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9565,8 +9565,8 @@ function run() {
continue;
}
if (IGNORE_PRS_WITH_FAILING_CHECKS) {
const prPassingStatusChecks = yield (0, pullrequest_1.isPRPassingStatusChecks)(GITHUB_TOKEN, GITHUB_REPO_OWNER, GITHUB_REPO, pullRequest);
if (prPassingStatusChecks === false) {
const prFailingStatusChecks = yield (0, pullrequest_1.isPRFailingStatusChecks)(GITHUB_TOKEN, GITHUB_REPO_OWNER, GITHUB_REPO, pullRequest);
if (prFailingStatusChecks) {
core.info(`Ignoring #${pullRequest.number} "${pullRequest.title} as the status checks are failing"`);
continue;
}
Expand Down Expand Up @@ -9629,7 +9629,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isMissingReview = exports.isPRPassingStatusChecks = exports.shouldIgnore = exports.fetchPullRequests = void 0;
exports.isMissingReview = exports.isPRFailingStatusChecks = exports.shouldIgnore = exports.fetchPullRequests = void 0;
const github = __importStar(__nccwpck_require__(5438));
/**
* Get a list of all currently open pull requests in a repository
Expand Down Expand Up @@ -9685,14 +9685,16 @@ function shouldIgnore(pullRequest, ignoreAuthors, ignoreDraftPRs, ignoreLabels)
}
exports.shouldIgnore = shouldIgnore;
/**
* Returns whether the passed in PR has all it's status checks passing.
* Returns whether the provided PR is failing it's status checks
* @param gitHubToken The token used to authenticate with GitHub to access the repo
* @param repoOwner The owner of the repo
* @param repo The name of the repo
* @param pullRequest The pull request to check.
* @returns True if the status checks are passing, false if they are in progress or failing.
* @returns
* True if any status checks are in error or failing state,
* false if checks are pending or have succeeded.
*/
function isPRPassingStatusChecks(gitHubToken, repoOwner, repo, pullRequest) {
function isPRFailingStatusChecks(gitHubToken, repoOwner, repo, pullRequest) {
return __awaiter(this, void 0, void 0, function* () {
const octokit = github.getOctokit(gitHubToken);
const { data } = yield octokit.rest.repos.getCombinedStatusForRef({
Expand All @@ -9701,10 +9703,10 @@ function isPRPassingStatusChecks(gitHubToken, repoOwner, repo, pullRequest) {
ref: pullRequest.head.ref,
});
// Possible values are `success,pending,error,failure`
return data.state === 'success';
return ['error', 'failure'].includes(data.state);
});
}
exports.isPRPassingStatusChecks = isPRPassingStatusChecks;
exports.isPRFailingStatusChecks = isPRFailingStatusChecks;
/**
* Identifies whether the PR being passed in has not had any review activity in the last 24 hours.
*
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as github from '@actions/github'
import {
fetchPullRequests,
isMissingReview,
isPRPassingStatusChecks,
isPRFailingStatusChecks,
shouldIgnore,
} from './pullrequest'
import { sendReminder } from './reminder'
Expand Down Expand Up @@ -32,14 +32,14 @@ async function run(): Promise<void> {
}

if (IGNORE_PRS_WITH_FAILING_CHECKS) {
const prPassingStatusChecks = await isPRPassingStatusChecks(
const prFailingStatusChecks = await isPRFailingStatusChecks(
GITHUB_TOKEN,
GITHUB_REPO_OWNER,
GITHUB_REPO,
pullRequest,
)

if (prPassingStatusChecks === false) {
if (prFailingStatusChecks) {
core.info(
`Ignoring #${pullRequest.number} "${pullRequest.title} as the status checks are failing"`,
)
Expand Down
10 changes: 6 additions & 4 deletions src/pullrequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ export function shouldIgnore(
}

/**
* Returns whether the passed in PR has all it's status checks passing.
* Returns whether the provided PR is failing it's status checks
* @param gitHubToken The token used to authenticate with GitHub to access the repo
* @param repoOwner The owner of the repo
* @param repo The name of the repo
* @param pullRequest The pull request to check.
* @returns True if the status checks are passing, false if they are in progress or failing.
* @returns
* True if any status checks are in error or failing state,
* false if checks are pending or have succeeded.
*/
export async function isPRPassingStatusChecks(
export async function isPRFailingStatusChecks(
gitHubToken: string,
repoOwner: string,
repo: string,
Expand All @@ -90,7 +92,7 @@ export async function isPRPassingStatusChecks(
})

// Possible values are `success,pending,error,failure`
return data.state === 'success'
return ['error', 'failure'].includes(data.state)
}

/**
Expand Down