Last active
August 21, 2018 01:14
-
-
Save dariye/a6051ff5621e6729f4b3631cabc916a7 to your computer and use it in GitHub Desktop.
Handler for 'labeled' event on a github issue
This file contains hidden or 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
/** | |
* 'labeled' event handler | |
* @param {Object} payload Github event payload | |
*/ | |
const { query } = require('../graphql') | |
const { | |
graphqlClient, | |
addProjectCard, | |
moveProjectCard, | |
baseVariables | |
} = require('../lib/github') | |
module.exports = async (payload) => { | |
const { issue: { number }, label: { name } } = payload | |
const variables = Object.assign({}, baseVariables, { | |
number, projectName: name | |
}) | |
const [issue, project] = await Promise.all([ | |
graphqlClient.request(query.findIssue, variables), | |
graphqlClient.request(query.findProject, variables) | |
]) | |
const label = issue.repository.issue.labels.edges | |
.find(label => label.node.name === name) | |
const { description } = label.node | |
switch(description) { | |
case 'project': | |
await addProjectCard({ label, project, issue, variables }) | |
break | |
case 'status': | |
await moveProjectCard({ label, issue, variables }) | |
break | |
default: | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment