Skip to content

Instantly share code, notes, and snippets.

@g1stavo
Created August 13, 2020 21:19
Show Gist options
  • Save g1stavo/19a772ccb698d5437c7e750cc5cfdabd to your computer and use it in GitHub Desktop.
Save g1stavo/19a772ccb698d5437c7e750cc5cfdabd to your computer and use it in GitHub Desktop.
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