Skip to content

Assign CP PRs to the deployer that triggered them #4602

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

Merged
merged 7 commits into from
Sep 3, 2021
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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
*
Expand All @@ -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({
Expand All @@ -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);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports =
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ 265:
/***/ 1751:
/***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => {

const _ = __nccwpck_require__(4987);
Expand All @@ -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) {
Expand Down Expand Up @@ -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.
*
Expand All @@ -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({
Expand All @@ -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);
});
}

Expand Down Expand Up @@ -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);
/******/ })()
;
2 changes: 1 addition & 1 deletion .github/scripts/buildActions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/cherryPick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down