-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into marcaaron-addOnfidoSDKs
- Loading branch information
Showing
42 changed files
with
658 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 59 additions & 19 deletions
78
.github/actions/getMergeCommitForPullRequest/getMergeCommitForPullRequest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,66 @@ | ||
const _ = require('underscore'); | ||
const core = require('@actions/core'); | ||
const ActionUtils = require('../../libs/ActionUtils'); | ||
const GithubUtils = require('../../libs/GithubUtils'); | ||
|
||
const pullRequestNumber = ActionUtils.getJSONInput('PULL_REQUEST_NUMBER', {required: true}); | ||
console.log(`Getting merge_commit_sha for PR #${pullRequestNumber}`); | ||
GithubUtils.octokit.pulls.get({ | ||
const DEFAULT_PAYLOAD = { | ||
owner: GithubUtils.GITHUB_OWNER, | ||
repo: GithubUtils.EXPENSIFY_CASH_REPO, | ||
pull_number: pullRequestNumber, | ||
}) | ||
.then(({data}) => { | ||
const mergeCommitHash = data.merge_commit_sha; | ||
if (mergeCommitHash) { | ||
console.log(`PR #${pullRequestNumber} has merge_commit_sha ${mergeCommitHash}`); | ||
core.setOutput('MERGE_COMMIT_SHA', mergeCommitHash); | ||
} else { | ||
const err = new Error(`Could not find merge_commit_sha for pull request ${pullRequestNumber}`); | ||
console.error(err); | ||
core.setFailed(err); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.log(`An unknown error occurred with the GitHub API: ${err}`); | ||
}; | ||
|
||
const pullRequestNumber = ActionUtils.getJSONInput('PULL_REQUEST_NUMBER', {required: false}, null); | ||
const user = ActionUtils.getJSONInput('USER', {required: false}, null); | ||
const titleRegex = ActionUtils.getJSONInput('TITLE_REGEX', {required: false}, null); | ||
|
||
if (pullRequestNumber) { | ||
console.log(`Looking for pull request w/ number: ${pullRequestNumber}`); | ||
} | ||
|
||
if (user) { | ||
console.log(`Looking for pull request w/ user: ${user}`); | ||
} | ||
|
||
if (titleRegex) { | ||
console.log(`Looking for pull request w/ title matching: ${titleRegex.toString()}`); | ||
} | ||
|
||
/** | ||
* Process a pull request and outputs it's merge commit hash. | ||
* | ||
* @param {Object} PR | ||
*/ | ||
function outputMergeCommitHash(PR) { | ||
if (!_.isEmpty(PR)) { | ||
console.log(`Found matching pull request: ${PR.html_url}`); | ||
core.setOutput('MERGE_COMMIT_SHA', PR.merge_commit_sha); | ||
} else { | ||
const err = new Error('Could not find matching pull request'); | ||
console.error(err); | ||
core.setFailed(err); | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Handle an unknown API error. | ||
* | ||
* @param {Error} err | ||
*/ | ||
function handleUnknownError(err) { | ||
console.log(`An unknown error occurred with the GitHub API: ${err}`); | ||
core.setFailed(err); | ||
} | ||
|
||
if (pullRequestNumber) { | ||
GithubUtils.octokit.pulls.get({ | ||
...DEFAULT_PAYLOAD, | ||
pull_number: pullRequestNumber, | ||
}) | ||
.then(({data}) => outputMergeCommitHash(data)) | ||
.catch(handleUnknownError); | ||
} else { | ||
GithubUtils.octokit.pulls.list(DEFAULT_PAYLOAD) | ||
.then(({data}) => { | ||
const matchingPR = _.find(data, PR => PR.user.login === user && titleRegex.test(PR.title)); | ||
outputMergeCommitHash(matchingPR); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.