-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from behaviorbot/spacing
4 -> 2 spaces minor change
- Loading branch information
Showing
3 changed files
with
110 additions
and
108 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,50 @@ | ||
const googleapis = require('googleapis'); | ||
|
||
module.exports = robot => { | ||
robot.on('issue_comment', async context => { | ||
let codeOfConduct; | ||
const config = await context.config('config.yml'); | ||
if (config && config.sentimentBotToxicityThreshold && config.sentimentBotReplyComment && !context.isBot) { | ||
const toxicityThreshold = config.sentimentBotToxicityThreshold; | ||
const body = context.payload.comment.body; | ||
// Check for Code of Conduct | ||
const repoData = await context.github.repos.get(context.repo({ | ||
headers: { | ||
Accept: 'application/vnd.github.scarlet-witch-preview+json' | ||
} | ||
})); | ||
if (repoData.data.code_of_conduct) { | ||
codeOfConduct = Object.assign({}, repoData.data.code_of_conduct); | ||
} | ||
// Attempt to make perspective api requests template from google | ||
const discoveryUrl = 'https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1'; | ||
googleapis.discoverAPI(discoveryUrl, (err, client) => { | ||
if (err) { | ||
throw err; | ||
} | ||
const analyzeRequest = { | ||
comment: {text: body}, | ||
requestedAttributes: {TOXICITY: {}} | ||
}; | ||
client.comments.analyze({key: process.env.PERSPECTIVE_API_KEY, resource: analyzeRequest}, (err, response) => { | ||
if (err) { | ||
throw err; | ||
} | ||
const toxicValue = response.attributeScores.TOXICITY.spanScores[0].score.value; | ||
// If the comment is toxic, comment the comment | ||
if (toxicValue >= toxicityThreshold) { | ||
let comment; | ||
if (codeOfConduct) { | ||
comment = config.sentimentBotReplyComment + 'Keep in mind, this repository uses the [' + codeOfConduct.name + '](' + codeOfConduct.url + ').'; | ||
} else { | ||
comment = config.sentimentBotReplyComment; | ||
} | ||
context.github.issues.createComment(context.issue({body: comment})); | ||
} | ||
}); | ||
}); | ||
robot.on('issue_comment', async context => { | ||
let codeOfConduct; | ||
const config = await context.config('config.yml'); | ||
if (config && !context.isBot) { | ||
if (config.sentimentBotToxicityThreshold && config.sentimentBotReplyComment) { | ||
const toxicityThreshold = config.sentimentBotToxicityThreshold; | ||
const body = context.payload.comment.body; | ||
// Check for Code of Conduct | ||
const repoData = await context.github.repos.get(context.repo({ | ||
headers: { | ||
Accept: 'application/vnd.github.scarlet-witch-preview+json' | ||
} | ||
})); | ||
if (repoData.data.code_of_conduct) { | ||
codeOfConduct = Object.assign({}, repoData.data.code_of_conduct); | ||
} | ||
}); | ||
// Attempt to make perspective api requests template from google | ||
const discoveryUrl = 'https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1'; | ||
googleapis.discoverAPI(discoveryUrl, (err, client) => { | ||
if (err) { | ||
throw err; | ||
} | ||
const analyzeRequest = { | ||
comment: {text: body}, | ||
requestedAttributes: {TOXICITY: {}} | ||
}; | ||
client.comments.analyze({key: process.env.PERSPECTIVE_API_KEY, resource: analyzeRequest}, (err, response) => { | ||
if (err) { | ||
throw err; | ||
} | ||
const toxicValue = response.attributeScores.TOXICITY.spanScores[0].score.value; | ||
// If the comment is toxic, comment the comment | ||
if (toxicValue >= toxicityThreshold) { | ||
let comment; | ||
if (codeOfConduct) { | ||
comment = config.sentimentBotReplyComment + 'Keep in mind, this repository uses the [' + codeOfConduct.name + '](' + codeOfConduct.url + ').'; | ||
} else { | ||
comment = config.sentimentBotReplyComment; | ||
} | ||
context.github.issues.createComment(context.issue({body: comment})); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
}); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ | |
"xo": "^0.18.2" | ||
}, | ||
"xo": { | ||
"space": 4 | ||
"space": 2 | ||
}, | ||
"engines": { | ||
"node": ">= 7.7.0", | ||
|
This file contains 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