Use configuration from repo file `.github/github-bot.yml`

This commit is contained in:
Pedro Pombeiro 2018-02-08 13:09:59 +01:00
parent 38d8fce885
commit 499f20f723
No known key found for this signature in database
GPG Key ID: A65DEB11E4BBC647
7 changed files with 52 additions and 57 deletions

View File

@ -1,22 +1,13 @@
project-board:
name: 'Pipeline for QA'
contributor-column-name: 'CONTRIBUTOR'
review-column-name: 'REVIEW'
test-column-name: 'TO TEST'
bounty-project-board:
name: 'Status SOB Swarm'
awaiting-approval-label-name: 'bounty-awaiting-approval'
bounty-label-name: 'bounty'
awaiting-approval-column-name: 'bounty-awaiting-approval'
owner: 'andytudhope'
welcome-bot:
message: 'Thanks for making your first PR here!'
automated-tests:
repo-full-name: 'status-im/status-react'
job-full-name: 'end-to-end-tests/status-app-end-to-end-tests'
slack:
notification:
room: 'status-probot'

View File

@ -11,11 +11,12 @@
// Author:
// PombeirP
// const getConfig = require('probot-config')
const createScheduler = require('probot-scheduler')
const getConfig = require('probot-config')
const Slack = require('probot-slack-status')
const defaultConfig = require('../lib/config')
const gitHubHelpers = require('../lib/github-helpers')
const createScheduler = require('probot-scheduler')
const Slack = require('probot-slack-status')
const slackHelper = require('../lib/slack')
let slackClient = null
@ -42,16 +43,15 @@ async function getProjectFromName (github, ownerName, repoName, projectBoardName
}
async function checkOpenPullRequests (robot, context) {
const github = context.github
const repo = context.payload.repository
const { github, payload } = context
const repo = payload.repository
const ownerName = repo.owner.login
const repoName = repo.name
// const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
const config = defaultConfig(robot, '.github/github-bot.yml')
const projectBoardConfig = config['project-board']
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
const projectBoardConfig = config ? config['project-board'] : null
if (!projectBoardConfig) {
robot.log.debug(`Project board not configured in repo ${ownerName}/${repoName}, ignoring`)
return
}
@ -115,7 +115,7 @@ async function checkOpenPullRequests (robot, context) {
)
// And make sure they are assigned to the correct project column
for (var pullRequest of allPullRequests) {
for (const pullRequest of allPullRequests) {
try {
await assignPullRequestToCorrectColumn(github, robot, repo, pullRequest, contributorColumn, reviewColumn, testColumn, config.slack.notification.room)
} catch (err) {

View File

@ -10,8 +10,9 @@
// Author:
// PombeirP
// const getConfig = require('probot-config')
const defaultConfig = require('../lib/config')
const getConfig = require('probot-config')
const Slack = require('probot-slack-status')
let slackClient = null
@ -34,13 +35,12 @@ module.exports = (robot) => {
async function assignPullRequestToReview (context, robot) {
const { github, payload } = context
// const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
const config = defaultConfig(robot, '.github/github-bot.yml')
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
const ownerName = payload.repository.owner.login
const repoName = payload.repository.name
const prNumber = payload.pull_request.number
const projectBoardConfig = config['project-board']
const projectBoardConfig = config ? config['project-board'] : null
if (!projectBoardConfig) {
return
}

View File

@ -10,10 +10,11 @@
// Author:
// PombeirP
// const getConfig = require('probot-config')
const slackHelper = require('../lib/slack')
const gitHubHelpers = require('../lib/github-helpers')
const defaultConfig = require('../lib/config')
const getConfig = require('probot-config')
const Slack = require('probot-slack-status')
let slackClient = null
@ -45,9 +46,8 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) {
const { github, payload } = context
const ownerName = payload.repository.owner.login
const repoName = payload.repository.name
// const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
const config = defaultConfig(robot, '.github/github-bot.yml')
const projectBoardConfig = config['bounty-project-board']
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
const projectBoardConfig = config ? config['bounty-project-board'] : null
if (!projectBoardConfig) {
return

View File

@ -11,6 +11,8 @@
// Max Tyrrell (ImFeelingDucky/mac/yung_mac)
const Slack = require('probot-slack-status')
const getConfig = require('probot-config')
const defaultConfig = require('../lib/config')
const slackHelper = require('../lib/slack')
@ -37,14 +39,14 @@ async function notifyCollaborators (context, robot, slackClient, getSlackMention
const { github, payload } = context
const ownerName = payload.repository.owner.login
const repoName = payload.repository.name
const config = defaultConfig(robot, '.github/github-bot.yml')
const projectBoardConfig = config['bounty-project-board']
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
const bountyProjectBoardConfig = config['bounty-project-board']
if (!projectBoardConfig) {
if (!bountyProjectBoardConfig) {
return
}
const watchedLabelName = projectBoardConfig['awaiting-approval-label-name']
const watchedLabelName = bountyProjectBoardConfig['awaiting-approval-label-name']
if (payload.label.name !== watchedLabelName) {
robot.log.debug(`bountyAwaitingApprovalSlackPing - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`)
return null

View File

@ -10,10 +10,11 @@
// Author:
// PombeirP
// const getConfig = require('probot-config')
const defaultConfig = require('../lib/config')
const getConfig = require('probot-config')
const Slack = require('probot-slack-status')
const defaultConfig = require('../lib/config')
let slackClient = null
module.exports = (robot) => {
@ -34,13 +35,12 @@ module.exports = (robot) => {
async function greetNewContributor (context, robot) {
const { github, payload } = context
// const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
const config = defaultConfig(robot, '.github/github-bot.yml')
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
const ownerName = payload.repository.owner.login
const repoName = payload.repository.name
const prNumber = payload.pull_request.number
const welcomeBotConfig = config['welcome-bot']
const welcomeBotConfig = config ? config['welcome-bot'] : null
if (!welcomeBotConfig) {
return
}

View File

@ -10,35 +10,38 @@
// Author:
// PombeirP
const defaultConfig = require('../lib/config')
const gitHubHelpers = require('../lib/github-helpers')
const getConfig = require('probot-config')
const jenkins = require('jenkins')({ baseUrl: process.env.JENKINS_URL, crumbIssuer: true, promisify: true })
const HashMap = require('hashmap')
const defaultConfig = require('../lib/config')
const gitHubHelpers = require('../lib/github-helpers')
const pendingPullRequests = new HashMap()
module.exports = (robot) => {
const config = defaultConfig(robot, '.github/github-bot.yml')
const projectBoardConfig = config['project-board']
const automatedTestsConfig = config['automated-tests']
if (!process.env.JENKINS_URL) {
robot.log.info('trigger-automation-test-build - Jenkins is not configured, not loading script')
return
}
if (projectBoardConfig && automatedTestsConfig) {
setInterval(checkPendingPullRequests, 5 * 1000 * 60, robot)
registerForRelevantCardEvents(robot, { projectBoardConfig: projectBoardConfig, automatedTestingConfig: automatedTestsConfig })
setInterval(checkPendingPullRequests, 5 * 1000 * 60, robot)
registerForRelevantCardEvents(robot)
}
function registerForRelevantCardEvents (robot) {
robot.on('project_card.created', context => processChangedProjectCard(robot, context))
robot.on('project_card.moved', context => processChangedProjectCard(robot, context))
}
async function processChangedProjectCard (robot, context) {
const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
const projectBoardConfig = config ? config['project-board'] : null
const automatedTestsConfig = config ? config['automated-tests'] : null
if (!projectBoardConfig || !automatedTestsConfig) {
return
}
}
function registerForRelevantCardEvents (robot, config) {
robot.on('project_card.created', context => processChangedProjectCard(robot, context, config))
robot.on('project_card.moved', context => processChangedProjectCard(robot, context, config))
}
async function processChangedProjectCard (robot, context, config) {
const { github, payload } = context
if (payload.project_card.note) {
@ -46,13 +49,12 @@ async function processChangedProjectCard (robot, context, config) {
return
}
const { projectBoardConfig, automatedTestingConfig } = config
const projectBoardName = projectBoardConfig['name']
const testColumnName = projectBoardConfig['test-column-name']
const repo = payload.repository
if (repo.full_name !== automatedTestingConfig['repo-full-name']) {
robot.log.trace(`trigger-automation-test-build - Pull request project doesn't match watched repo, exiting`, repo.full_name, automatedTestingConfig['repo-full-name'])
if (repo.full_name !== automatedTestsConfig['repo-full-name']) {
robot.log.trace(`trigger-automation-test-build - Pull request project doesn't match watched repo, exiting`, repo.full_name, automatedTestsConfig['repo-full-name'])
return
}
@ -91,7 +93,7 @@ async function processChangedProjectCard (robot, context, config) {
}
const prNumber = last(payload.project_card.content_url.split('/'), -1)
const fullJobName = automatedTestingConfig['job-full-name']
const fullJobName = automatedTestsConfig['job-full-name']
await processPullRequest(github, robot, repo.owner.login, repo.name, prNumber, fullJobName)
}