Skip to content

Instantly share code, notes, and snippets.

@dariye
Last active August 21, 2018 01:14
Show Gist options
  • Save dariye/a6051ff5621e6729f4b3631cabc916a7 to your computer and use it in GitHub Desktop.
Save dariye/a6051ff5621e6729f4b3631cabc916a7 to your computer and use it in GitHub Desktop.
Handler for 'labeled' event on a github issue
/**
* '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