diff --git a/.github/actions/getMergeCommitForPullRequest/action.yml b/.github/actions/getPullRequestDetails/action.yml similarity index 71% rename from .github/actions/getMergeCommitForPullRequest/action.yml rename to .github/actions/getPullRequestDetails/action.yml index 6ffcb5888598..dbb3e2283686 100644 --- a/.github/actions/getMergeCommitForPullRequest/action.yml +++ b/.github/actions/getPullRequestDetails/action.yml @@ -1,5 +1,5 @@ -name: 'Get merge commit for a pull request' -description: 'Get the merge_commit_sha for a pull request' +name: 'Get the details of a pull request' +description: 'Get the details of a pull request' inputs: GITHUB_TOKEN: description: Auth token for New Expensify Github @@ -12,10 +12,12 @@ inputs: required: false USER: description: The creator of the pull request - required: false + required: true outputs: MERGE_COMMIT_SHA: description: 'The merge_commit_sha of the given pull request' + MERGE_ACTOR: + description: 'The actor who merged the pull request' runs: using: 'node12' main: './index.js' diff --git a/.github/actions/getMergeCommitForPullRequest/getMergeCommitForPullRequest.js b/.github/actions/getPullRequestDetails/getPullRequestDetails.js similarity index 71% rename from .github/actions/getMergeCommitForPullRequest/getMergeCommitForPullRequest.js rename to .github/actions/getPullRequestDetails/getPullRequestDetails.js index 7d0e0b1f0e17..a83f5ae70683 100644 --- a/.github/actions/getMergeCommitForPullRequest/getMergeCommitForPullRequest.js +++ b/.github/actions/getPullRequestDetails/getPullRequestDetails.js @@ -9,7 +9,7 @@ const DEFAULT_PAYLOAD = { }; const pullRequestNumber = ActionUtils.getJSONInput('PULL_REQUEST_NUMBER', {required: false}, null); -const user = core.getInput('USER', {required: false}); +const user = core.getInput('USER', {required: true}); let titleRegex = core.getInput('TITLE_REGEX', {required: false}); if (pullRequestNumber) { @@ -41,6 +41,27 @@ function outputMergeCommitHash(PR) { } } +/** + * Process a pull request and outputs it's merge actor + * + * @param {Object} PR + */ +function outputMergeActor(PR) { + if (!_.isEmpty(PR)) { + console.log(`Found matching pull request: ${PR.html_url}`); + + if (user === 'OSBotify') { + core.setOutput('MERGE_ACTOR', PR.merged_by.login); + } else { + core.setOutput('MERGE_ACTOR', user); + } + } else { + const err = new Error('Could not find matching pull request'); + console.error(err); + core.setFailed(err); + } +} + /** * Handle an unknown API error. * @@ -56,7 +77,10 @@ if (pullRequestNumber) { ...DEFAULT_PAYLOAD, pull_number: pullRequestNumber, }) - .then(({data}) => outputMergeCommitHash(data)) + .then(({data}) => { + outputMergeCommitHash(data); + outputMergeActor(data); + }) .catch(handleUnknownError); } else { GithubUtils.octokit.pulls.list({ @@ -66,5 +90,6 @@ if (pullRequestNumber) { .then(({data}) => { const matchingPR = _.find(data, PR => PR.user.login === user && titleRegex.test(PR.title)); outputMergeCommitHash(matchingPR); + outputMergeActor(matchingPR); }); } diff --git a/.github/actions/getMergeCommitForPullRequest/index.js b/.github/actions/getPullRequestDetails/index.js similarity index 99% rename from .github/actions/getMergeCommitForPullRequest/index.js rename to .github/actions/getPullRequestDetails/index.js index b3a71def18a9..6982db60a6e0 100644 --- a/.github/actions/getMergeCommitForPullRequest/index.js +++ b/.github/actions/getPullRequestDetails/index.js @@ -5,7 +5,7 @@ module.exports = /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ 265: +/***/ 1751: /***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => { const _ = __nccwpck_require__(4987); @@ -19,7 +19,7 @@ const DEFAULT_PAYLOAD = { }; const pullRequestNumber = ActionUtils.getJSONInput('PULL_REQUEST_NUMBER', {required: false}, null); -const user = core.getInput('USER', {required: false}); +const user = core.getInput('USER', {required: true}); let titleRegex = core.getInput('TITLE_REGEX', {required: false}); if (pullRequestNumber) { @@ -51,6 +51,27 @@ function outputMergeCommitHash(PR) { } } +/** + * Process a pull request and outputs it's merge actor + * + * @param {Object} PR + */ +function outputMergeActor(PR) { + if (!_.isEmpty(PR)) { + console.log(`Found matching pull request: ${PR.html_url}`); + + if (user === 'OSBotify') { + core.setOutput('MERGE_ACTOR', PR.merged_by.login); + } else { + core.setOutput('MERGE_ACTOR', user); + } + } else { + const err = new Error('Could not find matching pull request'); + console.error(err); + core.setFailed(err); + } +} + /** * Handle an unknown API error. * @@ -66,7 +87,10 @@ if (pullRequestNumber) { ...DEFAULT_PAYLOAD, pull_number: pullRequestNumber, }) - .then(({data}) => outputMergeCommitHash(data)) + .then(({data}) => { + outputMergeCommitHash(data); + outputMergeActor(data); + }) .catch(handleUnknownError); } else { GithubUtils.octokit.pulls.list({ @@ -76,6 +100,7 @@ if (pullRequestNumber) { .then(({data}) => { const matchingPR = _.find(data, PR => PR.user.login === user && titleRegex.test(PR.title)); outputMergeCommitHash(matchingPR); + outputMergeActor(matchingPR); }); } @@ -15063,6 +15088,6 @@ module.exports = require("zlib");; /******/ // module exports must be returned from runtime so entry inlining is disabled /******/ // startup /******/ // Load entry module and return exports -/******/ return __nccwpck_require__(265); +/******/ return __nccwpck_require__(1751); /******/ })() ; diff --git a/.github/scripts/buildActions.sh b/.github/scripts/buildActions.sh index 5b417b094f99..79b80c0704c6 100755 --- a/.github/scripts/buildActions.sh +++ b/.github/scripts/buildActions.sh @@ -13,7 +13,7 @@ declare -r GITHUB_ACTIONS=( "$ACTIONS_DIR/checkDeployBlockers/checkDeployBlockers.js" "$ACTIONS_DIR/createOrUpdateStagingDeploy/createOrUpdateStagingDeploy.js" "$ACTIONS_DIR/getDeployPullRequestList/getDeployPullRequestList.js" - "$ACTIONS_DIR/getMergeCommitForPullRequest/getMergeCommitForPullRequest.js" + "$ACTIONS_DIR/getPullRequestDetails/getPullRequestDetails.js" "$ACTIONS_DIR/getReleaseBody/getReleaseBody.js" "$ACTIONS_DIR/isPullRequestMergeable/isPullRequestMergeable.js" "$ACTIONS_DIR/isStagingDeployLocked/isStagingDeployLocked.js" diff --git a/.github/workflows/cherryPick.yml b/.github/workflows/cherryPick.yml index 8eaef2c1c80b..4f56cadbfa1a 100644 --- a/.github/workflows/cherryPick.yml +++ b/.github/workflows/cherryPick.yml @@ -77,9 +77,10 @@ jobs: - name: Get merge commit for CP pull request id: getCPMergeCommit - uses: Expensify/App/.github/actions/getMergeCommitForPullRequest@main + uses: Expensify/App/.github/actions/getPullRequestDetails@main with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + USER: ${{ github.actor }} PULL_REQUEST_NUMBER: ${{ github.event.inputs.PULL_REQUEST_NUMBER }} - name: Save correct NEW_VERSION to env @@ -94,7 +95,7 @@ jobs: - name: Get merge commit for version-bump pull request id: getVersionBumpMergeCommit - uses: Expensify/App/.github/actions/getMergeCommitForPullRequest@main + uses: Expensify/App/.github/actions/getPullRequestDetails@main with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} USER: OSBotify @@ -151,6 +152,14 @@ jobs: Engineering Hourly + - name: Assign the PR to the deployer + if: ${{ !fromJSON(steps.cherryPick.outputs.SHOULD_AUTOMERGE) || !fromJSON(steps.isPullRequestMergeable.outputs.IS_MERGEABLE) }} + uses: actions-ecosystem/action-add-assignees@a73fcabd82d847c5e7433fcfdd58ef9f7e8a3993 + with: + number: ${{ steps.createPullRequest.outputs.pr_number }} + github_token: ${{ secrets.GITHUB_TOKEN }} + assignees: ${{ steps.getCPMergeCommit.outputs.MERGE_ACTOR }} + - name: If PR has merge conflicts, comment with instructions for assignee if: ${{ steps.cherryPick.outputs.SHOULD_AUTOMERGE == 'false' || steps.isPullRequestMergeable.outputs.IS_MERGEABLE == 'false' }} uses: actions-ecosystem/action-create-comment@cd098164398331c50e7dfdd0dfa1b564a1873fac