From 1ff344f6a026cf8ba6558282e3973bda38dbbc33 Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Wed, 6 Dec 2023 12:20:27 -0600 Subject: [PATCH] Allow for the PR number to be mocked for tests Signed-off-by: Peter Nied --- .github/workflows/test.yml | 7 +++++++ dist/index.js | 2 +- index.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1902de1..1d6b2eb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,6 +17,7 @@ jobs: required-approvers-list: peternied min-required: 1 mock-approvers: 'peternied' + mock-pr-number: 42 - if: steps.approved-by-required-users.outcome != 'success' || steps.approved-by-required-users.outputs.maintainer-approvals != 'peternied' run: echo "Unexpected outcome:${{ steps.approved-by-required-users.outcome }} or maintainer-approvals:${{steps.approved-by-required-users.outputs.maintainer-approvals}}" @@ -33,6 +34,7 @@ jobs: required-approvers-list: peternied min-required: 1 mock-approvers: 'peternied greengiant' + mock-pr-number: 42 - if: steps.approved-by-required-users.outcome != 'success' || steps.approved-by-required-users.outputs.maintainer-approvals != 'peternied' run: echo "Unexpected outcome:${{ steps.approved-by-required-users.outcome }} or maintainer-approvals:${{steps.approved-by-required-users.outputs.maintainer-approvals}}" @@ -50,6 +52,7 @@ jobs: required-approvers-list: peternied min-required: 1 mock-approvers: ' ' + mock-pr-number: 42 - if: steps.approved-by-required-users.outcome != 'failure' || steps.approved-by-required-users.outputs.maintainer-approvals != '' run: echo "Unexpected outcome:${{ steps.approved-by-required-users.outcome }} or maintainer-approvals:${{steps.approved-by-required-users.outputs.maintainer-approvals}}" @@ -67,6 +70,7 @@ jobs: required-approvers-list: peternied min-required: 1 mock-approvers: 'greengiant' + mock-pr-number: 42 - if: steps.approved-by-required-users.outcome != 'failure' || steps.approved-by-required-users.outputs.maintainer-approvals != '' run: echo "Unexpected outcome:${{ steps.approved-by-required-users.outcome }} or maintainer-approvals:${{steps.approved-by-required-users.outputs.maintainer-approvals}}" @@ -84,6 +88,7 @@ jobs: required-approvers-list: 'peternied, greengiant' min-required: 2 mock-approvers: 'peternied' + mock-pr-number: 42 - if: steps.approved-by-required-users.outcome != 'failure' || steps.approved-by-required-users.outputs.maintainer-approvals != 'peternied' run: echo "Unexpected outcome:${{ steps.approved-by-required-users.outcome }} or maintainer-approvals:${{steps.approved-by-required-users.outputs.maintainer-approvals}}" @@ -101,6 +106,7 @@ jobs: required-approvers-list: 'peternied, greengiant, austin, billyjean robert' min-required: 4 mock-approvers: 'peternied greengiant austin billyjean robert' + mock-pr-number: 42 - if: steps.approved-by-required-users.outcome != 'failure' || steps.approved-by-required-users.outputs.maintainer-approvals != 'peternied' run: echo "Unexpected outcome:${{ steps.approved-by-required-users.outcome }} or maintainer-approvals:${{steps.approved-by-required-users.outputs.maintainer-approvals}}" @@ -116,6 +122,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} min-required: 2 mock-approvers: 'peternied bob kelly' + mock-pr-number: 42 - if: steps.approved-by-required-users.outcome != 'failure' || steps.approved-by-required-users.outputs.maintainer-approvals != 'peternied bob kelly' run: echo "Unexpected outcome:${{ steps.approved-by-required-users.outcome }} or maintainer-approvals:${{steps.approved-by-required-users.outputs.maintainer-approvals}}" diff --git a/dist/index.js b/dist/index.js index 5b78705..205072f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36724,7 +36724,7 @@ async function run() { } const minRequired = parseInt(minRequiredStr); - const pullRequestId = github.context.payload.pull_request?.number; + const pullRequestId = github.context.payload.pull_request?.number || core.getInput('mock-pr-number', { required: false }); if (!pullRequestId) { core.setFailed(`Unable to find associated pull request from the context: ${JSON.stringify(github.context)}`); return; diff --git a/index.js b/index.js index 019b80f..da1561e 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,7 @@ async function run() { } const minRequired = parseInt(minRequiredStr); - const pullRequestId = github.context.payload.pull_request?.number; + const pullRequestId = github.context.payload.pull_request?.number || core.getInput('mock-pr-number', { required: false }); if (!pullRequestId) { core.setFailed(`Unable to find associated pull request from the context: ${JSON.stringify(github.context)}`); return;