From 499f20f7234ac642a6f6299ea7102d7cb289cf80 Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Thu, 8 Feb 2018 13:09:59 +0100 Subject: [PATCH] Use configuration from repo file `.github/github-bot.yml` --- .github/github-bot.yml | 11 +---- bot_scripts/assign-approved-pr-to-test.js | 20 ++++----- bot_scripts/assign-new-pr-to-review.js | 8 ++-- .../assign-to-bounty-awaiting-for-approval.js | 8 ++-- .../bounty-awaiting-approval-slack-ping.js | 10 +++-- bot_scripts/greet-new-contributor.js | 10 ++--- bot_scripts/trigger-automation-test-build.js | 42 ++++++++++--------- 7 files changed, 52 insertions(+), 57 deletions(-) diff --git a/.github/github-bot.yml b/.github/github-bot.yml index 3426e28..e39bd8b 100644 --- a/.github/github-bot.yml +++ b/.github/github-bot.yml @@ -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' diff --git a/bot_scripts/assign-approved-pr-to-test.js b/bot_scripts/assign-approved-pr-to-test.js index 75c4121..76217f1 100644 --- a/bot_scripts/assign-approved-pr-to-test.js +++ b/bot_scripts/assign-approved-pr-to-test.js @@ -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) { diff --git a/bot_scripts/assign-new-pr-to-review.js b/bot_scripts/assign-new-pr-to-review.js index e7aeeaa..ac65b72 100644 --- a/bot_scripts/assign-new-pr-to-review.js +++ b/bot_scripts/assign-new-pr-to-review.js @@ -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 } diff --git a/bot_scripts/assign-to-bounty-awaiting-for-approval.js b/bot_scripts/assign-to-bounty-awaiting-for-approval.js index 170a2df..6402691 100644 --- a/bot_scripts/assign-to-bounty-awaiting-for-approval.js +++ b/bot_scripts/assign-to-bounty-awaiting-for-approval.js @@ -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 diff --git a/bot_scripts/bounty-awaiting-approval-slack-ping.js b/bot_scripts/bounty-awaiting-approval-slack-ping.js index a58758e..95b37c1 100644 --- a/bot_scripts/bounty-awaiting-approval-slack-ping.js +++ b/bot_scripts/bounty-awaiting-approval-slack-ping.js @@ -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 diff --git a/bot_scripts/greet-new-contributor.js b/bot_scripts/greet-new-contributor.js index 3be78e0..618dd9e 100644 --- a/bot_scripts/greet-new-contributor.js +++ b/bot_scripts/greet-new-contributor.js @@ -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 } diff --git a/bot_scripts/trigger-automation-test-build.js b/bot_scripts/trigger-automation-test-build.js index 6995a79..3e006b8 100644 --- a/bot_scripts/trigger-automation-test-build.js +++ b/bot_scripts/trigger-automation-test-build.js @@ -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) }