Skip to content

Instantly share code, notes, and snippets.

@DEGoodmanWilson
Last active November 10, 2018 08:35
Show Gist options
  • Save DEGoodmanWilson/28a5232d5fc45512bebfb76bb0c30f71 to your computer and use it in GitHub Desktop.
Save DEGoodmanWilson/28a5232d5fc45512bebfb76bb0c30f71 to your computer and use it in GitHub Desktop.
Snippets for Craftwork V2
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!
![](${response.data.images.original.gif_url})
`
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)
})
})
}
const GphApiClient = require('giphy-js-sdk-core')
const giphy_client = GphApiClient(process.env.GIPHY_KEY)
giphy_client.random('gifs', {
"q": "welcome",
"rating": "g"
})
.then((response) => {
const body = `
Howdy! Thanks for opening an issue!
![](${response.data.images.original.gif_url})
`
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)
})
const recastai = require('recastai').default
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