Skip to content

Instantly share code, notes, and snippets.

@haacked
Created February 9, 2019 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haacked/16752966b46d7ca80d2d56f8ad8c2d5e to your computer and use it in GitHub Desktop.
Save haacked/16752966b46d7ca80d2d56f8ad8c2d5e to your computer and use it in GitHub Desktop.
Probot handler for the Why Not Both app
module.exports = (app) => {
// Respond to new issue comments
app.on('issue_comment.created', async context => {
const message = context.payload.comment.body
// The following does a rough approximation of
// trying to find a question that proposes two
// alternatives. It's not very smart about it,
// but good enough for our case.
const dichotomy = message.toLowerCase()
.split(/[!.?] /)
.find(function(sentence) {
return sentence.indexOf(' or ') > -1
&& sentence.endsWith('?')
}) != undefined
if (dichotomy) {
context.log('And it contains a dichotomy!')
const params = context.issue({
body: '![The why not both girl](https://media3.giphy.com/media/3o85xIO33l7RlmLR4I/giphy.gif)'
})
// This creates a comment with our favorite why not both meme animated gif
return context.github.issues.createComment(params)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment