From 0d14644ed173485929dd6403a0f4d2a8fd579c49 Mon Sep 17 00:00:00 2001 From: Simone Busoli Date: Fri, 9 Feb 2024 16:30:31 +0100 Subject: [PATCH] fix: merge status output not working (#571) * fix: merge status output not working * Dependabot/output doesnot seem to appear#539 (#574) * Fixes dependabot/output-doesnot-seem-to-appear#539 * #539 adding random merge status key to verify * #539 adding random merge status keys * #539 removed log messages. Added workflow id to workflow * #539 added workflow id to action yaml * #539 removed unneeded changes in action yaml file * fix #539 added new merge status for auto merge * #539 added testcase for auto merge (#576) * chore: rename main to approver in workflow --------- Co-authored-by: Phanindra Neralla <158252118+PhanindraNeralla@users.noreply.github.com> --- README.md | 6 +++--- action.yml | 8 +++++++- dist/index.js | 3 ++- src/action.js | 2 +- src/util.js | 1 + test/action.test.js | 5 +++++ 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index af7db120..d275c351 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,9 @@ Error: Resource not accessible by integration ## Output -| outputs | Description | -| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| merge_status | The result status of the merge. It can be one of the following: `approved`, `merged`, `merge_failed`, `skipped:commit_verification_failed`, `skipped:not_a_dependabot_pr`, `skipped:cannot_update_major`, `skipped:bump_higher_than_target`, `skipped:packaged_excluded` | +| outputs | Description | +| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| merge_status | The result status of the merge. It can be one of the following: `approved`, `merged`, `auto_merge`, `merge_failed`, `skipped:commit_verification_failed`, `skipped:not_a_dependabot_pr`, `skipped:cannot_update_major`, `skipped:bump_higher_than_target`, `skipped:packaged_excluded` | ## Examples diff --git a/action.yml b/action.yml index 1ce60519..64966fc1 100644 --- a/action.yml +++ b/action.yml @@ -47,6 +47,11 @@ inputs: description: 'If true, the action will not validate the user or the commit verification status' default: false +outputs: + merge_status: + description: 'Merge status' + value: ${{ steps.approver.outputs.merge_status }} + runs: using: 'composite' steps: @@ -56,9 +61,10 @@ runs: if: github.event_name == 'pull_request' && (github.actor == 'dependabot[bot]' || inputs.skip-verification == 'true') with: skip-commit-verification: ${{ inputs.skip-commit-verification }} - skip-verification : ${{ inputs.skip-verification }} + skip-verification: ${{ inputs.skip-verification }} - name: Merge/approve PR uses: actions/github-script@v7 + id: approver with: github-token: ${{ inputs.github-token }} script: | diff --git a/dist/index.js b/dist/index.js index abb6d244..f18f6294 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2906,7 +2906,6 @@ module.exports = async function run({ toolkit.logActionRefWarning() const { pull_request } = context.payload - if (!pull_request && !PR_NUMBER) { core.setOutput(MERGE_STATUS_KEY, MERGE_STATUS.skippedNotADependabotPr) return logError( @@ -3005,6 +3004,7 @@ ${changedExcludedPackages.join(', ')}. Skipping.`) if (USE_GITHUB_AUTO_MERGE) { await client.enableAutoMergePullRequest(pr.node_id, MERGE_METHOD) + core.setOutput(MERGE_STATUS_KEY, MERGE_STATUS.autoMerge) return logInfo('USE_GITHUB_AUTO_MERGE set, PR was marked as auto-merge') } @@ -3281,6 +3281,7 @@ exports.getTarget = ( exports.MERGE_STATUS = { approved: 'approved', merged: 'merged', + autoMerge: 'auto_merge', mergeFailed: 'merge_failed', skippedCommitVerificationFailed: 'skipped:commit_verification_failed', skippedNotADependabotPr: 'skipped:not_a_dependabot_pr', diff --git a/src/action.js b/src/action.js index c2e48f7f..82b0b7dd 100644 --- a/src/action.js +++ b/src/action.js @@ -47,7 +47,6 @@ module.exports = async function run({ toolkit.logActionRefWarning() const { pull_request } = context.payload - if (!pull_request && !PR_NUMBER) { core.setOutput(MERGE_STATUS_KEY, MERGE_STATUS.skippedNotADependabotPr) return logError( @@ -146,6 +145,7 @@ ${changedExcludedPackages.join(', ')}. Skipping.`) if (USE_GITHUB_AUTO_MERGE) { await client.enableAutoMergePullRequest(pr.node_id, MERGE_METHOD) + core.setOutput(MERGE_STATUS_KEY, MERGE_STATUS.autoMerge) return logInfo('USE_GITHUB_AUTO_MERGE set, PR was marked as auto-merge') } diff --git a/src/util.js b/src/util.js index 08b133ad..45e40f72 100644 --- a/src/util.js +++ b/src/util.js @@ -71,6 +71,7 @@ exports.getTarget = ( exports.MERGE_STATUS = { approved: 'approved', merged: 'merged', + autoMerge: 'auto_merge', mergeFailed: 'merge_failed', skippedCommitVerificationFailed: 'skipped:commit_verification_failed', skippedNotADependabotPr: 'skipped:not_a_dependabot_pr', diff --git a/test/action.test.js b/test/action.test.js index 0391cf92..801e6b80 100644 --- a/test/action.test.js +++ b/test/action.test.js @@ -631,6 +631,11 @@ tap.test('should review and enable github auto-merge', async () => { sinon.assert.notCalled(stubs.coreStub.setFailed) sinon.assert.calledOnce(stubs.approveStub) sinon.assert.calledOnce(stubs.enableAutoMergeStub) + sinon.assert.calledWith( + stubs.coreStub.setOutput, + MERGE_STATUS_KEY, + MERGE_STATUS.autoMerge, + ) }) tap.test('should forbid major when target is minor', async () => {