Created
August 13, 2020 21:19
-
-
Save g1stavo/19a772ccb698d5437c7e750cc5cfdabd to your computer and use it in GitHub Desktop.
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
const { context, getOctokit } = require('@actions/github') | |
/** | |
* Creates Octokit instance and assign. | |
* | |
* @param {string} token - GitHub token | |
*/ | |
const handle = async (token) => { | |
if (context.eventName === 'pull_request') { | |
const octokit = getOctokit(token) | |
await assign(octokit) | |
} else { | |
throw new Error('Sorry, this Action only works with pull requests.') | |
} | |
} | |
/** | |
* Auto assign pull requests. | |
* | |
* @param {Octokit} octokit - Octokit instance | |
*/ | |
const assign = async (octokit) => { | |
try { | |
const { owner, repo, number } = context.issue | |
await octokit.issues.addAssignees({ | |
owner: owner, | |
repo: repo, | |
issue_number: number, | |
assignees: [context.actor] | |
}) | |
} catch (err) { | |
throw new Error(`Couldn't assign pull request.\\n Error: ${err}`) | |
} | |
} | |
module.exports = { handle } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment