From 39be615b2e696382a02290da075d1fafd2d3de79 Mon Sep 17 00:00:00 2001 From: xrkffgg Date: Wed, 24 Feb 2021 16:49:50 +0800 Subject: [PATCH] feat: add `skip-run-names` --- CHANGELOG.md | 6 ++++++ README.md | 4 +++- action.yml | 3 +++ dist/index.js | 9 +++++---- package.json | 2 +- src/octokit.js | 9 +++++---- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c123f1..e851a1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v1.2.0 + +`2021.02.24` + +- feat: add `skip-run-names`. + ## v1.1.0 `2021.02.23` diff --git a/README.md b/README.md index 42b1fe6..570207f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ jobs: check: runs-on: ubuntu-latest steps: - - uses: actions-cool/check-pr-ci@v1.1.0 + - uses: actions-cool/check-pr-ci@v1.2.0 with: token: ${{ secrets.GITHUB_TOKEN }} filter-label: 'check-ci' @@ -46,6 +46,7 @@ jobs: | filter-creator-authority | Filter PR by creator authority. | string | ✖ | | filter-head-ref | Filter PR head ref branch. | string | ✖ | | filter-support-fork | Filter PR come from. Default `true`. | boolean | ✖ | +| skip-run-names | Skip some run names. | string | ✖ | | success-review | Whether to approve when success. | boolean | ✖ | | success-review-body | Review body. | string | ✖ | | success-merge | Whether to merge when success. | boolean | ✖ | @@ -58,6 +59,7 @@ jobs: - `merge-title`: `${number}` will be replaced with the current PR number - `failure-review`: When use this, the `failure-review-body` is necessary +- `skip-run-names`: [GitHub Doc](https://docs.github.com/en/rest/reference/checks#list-check-runs-for-a-git-reference) `check_runs` `name` ## ⚡ Feedback diff --git a/action.yml b/action.yml index 22f9f1c..f63c969 100644 --- a/action.yml +++ b/action.yml @@ -24,6 +24,9 @@ inputs: description: Filter PR head ref branch. filter-support-fork: description: Filter PR come from. + # check + skip-run-names: + description: Skip some run names. # resule ## success success-review: diff --git a/dist/index.js b/dist/index.js index 091266d..eb68585 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6088,7 +6088,7 @@ run(); const core = __nccwpck_require__(186); const { Octokit } = __nccwpck_require__(375); -const { checkPermission } = __nccwpck_require__(55); +const { dealStringToArr, checkPermission } = __nccwpck_require__(55); const token = core.getInput('token'); const octokit = new Octokit({ auth: `token ${token}` }); @@ -6141,6 +6141,7 @@ async function checkAuthority(owner, repo, username, filterCreatorAuthority) { } async function getPRStatus(owner, repo, number) { + const skipRunNames = core.getInput('skip-run-names'); const { data: pr } = await octokit.pulls.get({ owner, repo, @@ -6163,16 +6164,16 @@ async function getPRStatus(owner, repo, number) { let ifCICompleted = true; let ifCIHasFailure = false; runs.forEach(it => { - if (it.status !== 'completed') { + if (it.status == 'in_progress') { ifCICompleted = false; } - if (it.conclusion === 'failure') { + if (it.conclusion === 'failure' && !dealStringToArr(skipRunNames).includes(it.name)) { ifCIHasFailure = true; } }); core.info( - `[getPRStatus] [number: ${number}] [commitState: ${commitState}] [ifCICompleted: ${ifCICompleted}] [ifCIHasFailure: ${ifCIHasFailure}]`, + `[getPRStatus] [number: ${number}/${runs.length}] [commit: ${commit}] [commitState: ${commitState}] [ifCICompleted: ${ifCICompleted}] [ifCIHasFailure: ${ifCIHasFailure}]`, ); return { diff --git a/package.json b/package.json index 5172f08..92ff451 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "check-pr-ci", - "version": "1.1.0", + "version": "1.2.0", "private": true, "description": "Check the PR CI status and perform some operation after success or failure.", "main": "src/main.js", diff --git a/src/octokit.js b/src/octokit.js index b0ba0d6..5872aa9 100644 --- a/src/octokit.js +++ b/src/octokit.js @@ -1,7 +1,7 @@ const core = require('@actions/core'); const { Octokit } = require('@octokit/rest'); -const { checkPermission } = require('actions-util'); +const { dealStringToArr, checkPermission } = require('actions-util'); const token = core.getInput('token'); const octokit = new Octokit({ auth: `token ${token}` }); @@ -54,6 +54,7 @@ async function checkAuthority(owner, repo, username, filterCreatorAuthority) { } async function getPRStatus(owner, repo, number) { + const skipRunNames = core.getInput('skip-run-names'); const { data: pr } = await octokit.pulls.get({ owner, repo, @@ -76,16 +77,16 @@ async function getPRStatus(owner, repo, number) { let ifCICompleted = true; let ifCIHasFailure = false; runs.forEach(it => { - if (it.status !== 'completed') { + if (it.status == 'in_progress') { ifCICompleted = false; } - if (it.conclusion === 'failure') { + if (it.conclusion === 'failure' && !dealStringToArr(skipRunNames).includes(it.name)) { ifCIHasFailure = true; } }); core.info( - `[getPRStatus] [number: ${number}] [commitState: ${commitState}] [ifCICompleted: ${ifCICompleted}] [ifCIHasFailure: ${ifCIHasFailure}]`, + `[getPRStatus] [number: ${number}/${runs.length}] [commit: ${commit}] [commitState: ${commitState}] [ifCICompleted: ${ifCICompleted}] [ifCIHasFailure: ${ifCIHasFailure}]`, ); return {