Skip to content
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

Assign CP PRs to the deployer that triggered them #4602

Merged
merged 7 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
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);
});
}
29 changes: 27 additions & 2 deletions .github/actions/getMergeCommitForPullRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions .github/workflows/cherryPick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
uses: Expensify/App/.github/actions/getMergeCommitForPullRequest@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 Down Expand Up @@ -151,6 +152,14 @@ jobs:
Engineering
Hourly

- name: Assign the PR to the deployer
if: ${{ steps.cherryPick.outputs.SHOULD_AUTOMERGE == 'false' || steps.isPullRequestMergeable.outputs.IS_MERGEABLE == 'false' }}
HorusGoul marked this conversation as resolved.
Show resolved Hide resolved
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