-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dessant
committed
May 4, 2018
1 parent
195176e
commit 2833846
Showing
8 changed files
with
106 additions
and
26 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
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
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
This file was deleted.
Oops, something went wrong.
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,27 +1,52 @@ | ||
const Support = require('./support'); | ||
const schema = require('./schema'); | ||
|
||
module.exports = robot => { | ||
robot.on('issues.labeled', async context => { | ||
const app = await getSupport(context); | ||
await app.labeled(); | ||
if (app) { | ||
await app.labeled(); | ||
} | ||
}); | ||
|
||
robot.on('issues.unlabeled', async context => { | ||
const app = await getSupport(context); | ||
await app.unlabeled(); | ||
if (app) { | ||
await app.unlabeled(); | ||
} | ||
}); | ||
|
||
robot.on('issues.reopened', async context => { | ||
const app = await getSupport(context); | ||
await app.reopened(); | ||
if (app) { | ||
await app.reopened(); | ||
} | ||
}); | ||
|
||
async function getSupport(context) { | ||
let config = await context.config('support.yml'); | ||
if (!config) { | ||
config = {perform: false}; | ||
const config = await getConfig(context); | ||
if (config) { | ||
return new Support(context, config, robot.log); | ||
} | ||
} | ||
|
||
async function getConfig(context) { | ||
const {owner, repo} = context.issue(); | ||
let config; | ||
try { | ||
let repoConfig = await context.config('support.yml'); | ||
if (!repoConfig) { | ||
repoConfig = {perform: false}; | ||
} | ||
const {error, value} = schema.validate(repoConfig); | ||
if (error) { | ||
throw error; | ||
} | ||
config = value; | ||
} catch (err) { | ||
robot.log.warn({err: new Error(err), owner, repo}, 'Invalid config'); | ||
} | ||
|
||
return new Support(context, config, robot.log); | ||
return config; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const Joi = require('joi'); | ||
|
||
const schema = Joi.object().keys({ | ||
supportLabel: Joi.string() | ||
.default('support') | ||
.description('Label used to mark issues as support requests'), | ||
|
||
supportComment: Joi.alternatives() | ||
.try(Joi.string(), Joi.boolean().only(false)) | ||
.error(() => '"supportComment" must be a string or false') | ||
.default( | ||
'👋 We use the issue tracker exclusively for bug reports ' + | ||
'and feature requests. However, this issue appears to be a support ' + | ||
'request. Please use our support channels to get help with the project.' | ||
) | ||
.description( | ||
'Comment to post on issues marked as support requests. ' + | ||
'Add a link to a support page, or set to `false` to disable' | ||
), | ||
|
||
close: Joi.boolean() | ||
.default(true) | ||
.description('Close issues marked as support requests'), | ||
|
||
lock: Joi.boolean() | ||
.default(false) | ||
.description('Lock issues marked as support requests'), | ||
|
||
perform: Joi.boolean().default(!process.env.DRY_RUN) | ||
}); | ||
|
||
module.exports = schema; |
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
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