Created
February 9, 2019 20:49
-
-
Save haacked/16752966b46d7ca80d2d56f8ad8c2d5e to your computer and use it in GitHub Desktop.
Probot handler for the Why Not Both app
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
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: '' | |
}) | |
// 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