mirror of
https://github.com/status-im/status-github-bot.git
synced 2025-02-16 15:17:18 +00:00
easy-config first pass, #19
This commit is contained in:
parent
8a388db71c
commit
00147b08a5
6
bot-config.yml
Normal file
6
bot-config.yml
Normal file
@ -0,0 +1,6 @@
|
||||
notify-reviewers-via-slack:
|
||||
globallyEnabled: true
|
||||
repoConfig:
|
||||
status-im/status-react:
|
||||
disabled-users: ["flexsurfer"]
|
||||
disabled: true
|
@ -8,6 +8,7 @@
|
||||
// Martin Klepsch (martinklepsch)
|
||||
|
||||
const slackHelper = require('../lib/slack')
|
||||
const config = require('../lib/config')
|
||||
|
||||
const botName = 'notify-reviewers-via-slack'
|
||||
|
||||
@ -21,7 +22,13 @@ function registerForNewReviewRequests (robot) {
|
||||
// Make sure we don't listen to our own messages
|
||||
if (context.isBot) return null
|
||||
|
||||
await notifyReviewer(context, robot)
|
||||
const repoName = `${context.payload.repository.owner.login}/${context.payload.repository.name}`
|
||||
|
||||
if (config.enabledForRepo(botName, repoName)) {
|
||||
await notifyReviewer(context, robot)
|
||||
} else {
|
||||
robot.log.info(`${botName} not runing for repo: ${repoName}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
33
doc/README.md
Normal file
33
doc/README.md
Normal file
@ -0,0 +1,33 @@
|
||||
# Status Bot Documentation
|
||||
|
||||
### Configuration
|
||||
|
||||
All bots should have a global identifier (string). Configuration for each Bot and repository pairing will be stored in `bot-config.yml`.
|
||||
|
||||
#### Recipe — Getting configuration in bots:
|
||||
|
||||
```js
|
||||
TODO
|
||||
```
|
||||
|
||||
#### Recipe — Disabling a bot for a specific repository:
|
||||
|
||||
Edit the configuration for the bot in [`bot-config.yml`](/bot-config.yml):
|
||||
|
||||
```yml
|
||||
notify-reviewers-via-slack:
|
||||
globallyEnabled: true
|
||||
repoConfig:
|
||||
status-im/status-react:
|
||||
# disables bot for status-im/status-react
|
||||
disabled: true
|
||||
```
|
||||
|
||||
#### Recipe — Disabling a bot globally:
|
||||
|
||||
Edit the configuration for the bot in [`bot-config.yml`](/bot-config.yml):
|
||||
|
||||
```yml
|
||||
notify-reviewers-via-slack:
|
||||
globallyEnabled: false
|
||||
```
|
@ -5,18 +5,47 @@
|
||||
// js-yaml: "^3.10.0"
|
||||
//
|
||||
// Author:
|
||||
// PombeirP
|
||||
// PombeirP + martinklepsch
|
||||
|
||||
function readYaml (fileName) {
|
||||
const yaml = require('js-yaml')
|
||||
const fs = require('fs')
|
||||
|
||||
return yaml.safeLoad(fs.readFileSync(fileName, 'utf8'))
|
||||
}
|
||||
|
||||
function getConfig () {
|
||||
return readYaml('config.yml')
|
||||
}
|
||||
|
||||
module.exports = (robot, fileName) => {
|
||||
// Get document, or throw exception on error
|
||||
try {
|
||||
const yaml = require('js-yaml')
|
||||
const fs = require('fs')
|
||||
|
||||
return yaml.safeLoad(fs.readFileSync(fileName, 'utf8'))
|
||||
return readYaml(fileName)
|
||||
} catch (e) {
|
||||
robot.log.error(e)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
module.exports.enabled = (botName) => {
|
||||
return getConfig()[botName]['defaultEnabled']
|
||||
}
|
||||
|
||||
module.exports.forRepo = (botName, repoName) => {
|
||||
return getConfig()[botName]['repoConfig'][repoName]
|
||||
}
|
||||
|
||||
module.exports.enabledForRepo = (botName, repoName) => {
|
||||
let config = getConfig()
|
||||
|
||||
// TODO: how to use `forRepo` here?
|
||||
if (config[botName]['repoConfig'][repoName]['disabled']) {
|
||||
return false
|
||||
} else if (config[botName]['defaultEnabled']) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user