Last active
November 10, 2018 08:35
-
-
Save UncannyBingo/28a5232d5fc45512bebfb76bb0c30f71 to your computer and use it in GitHub Desktop.
Snippets for Craftwork V2
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
const recastai = require('recastai').default | |
const GphApiClient = require('giphy-js-sdk-core') | |
const giphy_client = GphApiClient(process.env.GIPHY_KEY) | |
module.exports = (app) => { | |
// Your code here | |
app.log('Yay! The app was loaded!') | |
// example of probot responding 'Hello World' to a new issue being opened | |
app.on('issues.opened', async context => { | |
// `context` extracts information from the event, which can be passed to | |
// GitHub API calls. This will return: | |
// {owner: 'yourname', repo: 'yourrepo', number: 123, body: 'Hello World!} | |
app.log('Got an event') | |
app.log(context.payload.issue.title) | |
// You can get a token from https://recast.ai | |
// Don't forget to add it to the .env file! | |
const request = new recastai.request(process.env.RECASTAI_TOKEN) | |
request.analyseText(context.payload.issue.title) | |
.then((result) => { | |
// Is this an assertion, a question, or a command. | |
if (result.isAssert()) { | |
// This is an assertion. Let's file this as a bug report | |
var label = 'bug' | |
} else if (result.isCommand()) { | |
// This is a command. Let's file this as a feature request | |
var label = 'enhancement' | |
} else if (result.isWhQuery() || result.isYnQuery()) { | |
// This is a question, let's label it as such | |
var label = 'question' | |
} | |
if (label) { | |
const gh_params = context.issue({ | |
labels: [label] | |
}) | |
context.github.issues.addLabels(gh_params) | |
} | |
}).catch((err) => { | |
app.log('******recast.ai error******') | |
app.log(err) | |
}) | |
giphy_client.random('gifs', { | |
"q": "welcome", | |
"rating": "g" | |
}) | |
.then((response) => { | |
const body = ` | |
Howdy! Thanks for opening an issue! | |
 | |
` | |
const gph_params = context.issue({ | |
body: body | |
}) | |
// Post a comment on the issue | |
context.github.issues.createComment(gph_params) | |
}) | |
.catch((err) => { | |
app.log('******giphy error******') | |
app.log(err) | |
}) | |
}) | |
} |
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
const GphApiClient = require('giphy-js-sdk-core') | |
const giphy_client = GphApiClient(process.env.GIPHY_KEY) |
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
giphy_client.random('gifs', { | |
"q": "welcome", | |
"rating": "g" | |
}) | |
.then((response) => { | |
const body = ` | |
Howdy! Thanks for opening an issue! | |
 | |
` | |
const params = context.issue({ | |
body: body | |
}) | |
// Post a comment on the issue | |
context.github.issues.createComment(params) | |
}) | |
.catch((err) => { | |
app.log('******giphy error******') | |
app.log(err) | |
}) |
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
const recastai = require('recastai').default |
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
app.log(context.payload.issue.title) | |
// You can get a token from https://recast.ai | |
// Don't forget to add it to the .env file! | |
const request = new recastai.request(process.env.RECASTAI_TOKEN) | |
request.analyseText(context.payload.issue.title) | |
.then((result) => { | |
// Is this an assertion, a question, or a command. | |
if(result.isAssert()) { | |
// This is an assertion. Let's file this as a bug report | |
var label = 'bug' | |
} | |
else if (result.isCommand()) { | |
// This is a command. Let's file this as a feature request | |
var label = 'enhancement' | |
} | |
else if (result.isWhQuery() || result.isYnQuery()) { | |
// This is a question, let's label it as such | |
var label = 'question' | |
} | |
if(label) { | |
const params = context.issue({ | |
labels: [label] | |
}) | |
context.github.issues.addLabels(params) | |
} | |
}).catch((err) => { | |
app.log('******recast.ai error******') | |
app.log(err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment