diff --git a/bot_scripts/assign-approved-pr-to-test.js b/bot_scripts/assign-approved-pr-to-test.js index 8623cea..64d71e9 100644 --- a/bot_scripts/assign-approved-pr-to-test.js +++ b/bot_scripts/assign-approved-pr-to-test.js @@ -19,12 +19,13 @@ const defaultConfig = require('../lib/config') const gitHubHelpers = require('../lib/github-helpers') const slackHelper = require('../lib/slack') +const botName = 'assign-approved-pr-to-test' let slackClient = null module.exports = robot => { // robot.on('slack.connected', ({ slack }) => { Slack(robot, (slack) => { - robot.log.trace('assign-approved-pr-to-test - Connected, assigned slackClient') + robot.log.trace(`${botName} - Connected, assigned slackClient`) slackClient = slack }) @@ -51,7 +52,7 @@ async function checkOpenPullRequests (robot, context) { const projectBoardConfig = config ? config['project-board'] : null if (!projectBoardConfig) { - robot.log.debug(`assign-approved-pr-to-test - Project board not configured in repo ${ownerName}/${repoName}, ignoring`) + robot.log.debug(`${botName} - Project board not configured in repo ${ownerName}/${repoName}, ignoring`) return } @@ -67,13 +68,13 @@ async function checkOpenPullRequests (robot, context) { // Find 'Pipeline for QA' project project = await getProjectFromName(github, ownerName, repoName, projectBoardConfig.name) if (!project) { - robot.log.error(`assign-approved-pr-to-test - Couldn't find project ${projectBoardConfig.name} in repo ${ownerName}/${repoName}`) + robot.log.error(`${botName} - Couldn't find project ${projectBoardConfig.name} in repo ${ownerName}/${repoName}`) return } - robot.log.debug(`assign-approved-pr-to-test - Fetched ${project.name} project (${project.id})`) + robot.log.debug(`${botName} - Fetched ${project.name} project (${project.id})`) } catch (err) { - robot.log.error(`assign-approved-pr-to-test - Couldn't fetch the github projects for repo: ${err}`, ownerName, repoName) + robot.log.error(`${botName} - Couldn't fetch the github projects for repo: ${err}`, ownerName, repoName) return } @@ -83,29 +84,29 @@ async function checkOpenPullRequests (robot, context) { const ghcolumnsPayload = await github.projects.getProjectColumns({ project_id: project.id }) ghcolumns = ghcolumnsPayload.data } catch (err) { - robot.log.error(`assign-approved-pr-to-test - Couldn't fetch the github columns for project: ${err}`, ownerName, repoName, project.id) + robot.log.error(`${botName} - Couldn't fetch the github columns for project: ${err}`, ownerName, repoName, project.id) return } const contributorColumn = ghcolumns.find(c => c.name === contributorColumnName) if (!contributorColumn) { - robot.log.error(`assign-approved-pr-to-test - Couldn't find ${contributorColumnName} column in project ${project.name}`) + robot.log.error(`${botName} - Couldn't find ${contributorColumnName} column in project ${project.name}`) return } const reviewColumn = ghcolumns.find(c => c.name === reviewColumnName) if (!reviewColumn) { - robot.log.error(`assign-approved-pr-to-test - Couldn't find ${reviewColumnName} column in project ${project.name}`) + robot.log.error(`${botName} - Couldn't find ${reviewColumnName} column in project ${project.name}`) return } const testColumn = ghcolumns.find(c => c.name === testColumnName) if (!testColumn) { - robot.log.error(`assign-approved-pr-to-test - Couldn't find ${testColumnName} column in project ${project.name}`) + robot.log.error(`${botName} - Couldn't find ${testColumnName} column in project ${project.name}`) return } - robot.log.debug(`assign-approved-pr-to-test - Fetched ${contributorColumn.name} (${contributorColumn.id}), ${reviewColumn.name} (${reviewColumn.id}), ${testColumn.name} (${testColumn.id}) columns`) + robot.log.debug(`${botName} - Fetched ${contributorColumn.name} (${contributorColumn.id}), ${reviewColumn.name} (${reviewColumn.id}), ${testColumn.name} (${testColumn.id}) columns`) try { // Gather all open PRs in this repo @@ -119,11 +120,11 @@ async function checkOpenPullRequests (robot, context) { try { await assignPullRequestToCorrectColumn(github, robot, repo, pullRequest, contributorColumn, reviewColumn, testColumn, config.slack.notification.room) } catch (err) { - robot.log.error(`assign-approved-pr-to-test - Unhandled exception while processing PR: ${err}`, ownerName, repoName) + robot.log.error(`${botName} - Unhandled exception while processing PR: ${err}`, ownerName, repoName) } } } catch (err) { - robot.log.error(`assign-approved-pr-to-test - Couldn't fetch the github pull requests for repo: ${err}`, ownerName, repoName) + robot.log.error(`${botName} - Couldn't fetch the github pull requests for repo: ${err}`, ownerName, repoName) } } @@ -136,7 +137,7 @@ async function assignPullRequestToCorrectColumn (github, robot, repo, pullReques try { state = await gitHubHelpers.getReviewApprovalState(github, robot, repoOwner, repoName, prNumber) } catch (err) { - robot.log.error(`assign-approved-pr-to-test - Couldn't calculate the PR approval state: ${err}`, repoOwner, repoName, prNumber) + robot.log.error(`${botName} - Couldn't calculate the PR approval state: ${err}`, repoOwner, repoName, prNumber) } let srcColumns, dstColumn @@ -161,7 +162,7 @@ async function assignPullRequestToCorrectColumn (github, robot, repo, pullReques return } - robot.log.debug(`assign-approved-pr-to-test - Handling Pull Request #${prNumber} on repo ${repoOwner}/${repoName}. PR should be in ${dstColumn.name} column`) + robot.log.debug(`${botName} - Handling Pull Request #${prNumber} on repo ${repoOwner}/${repoName}. PR should be in ${dstColumn.name} column`) // Look for PR card in source column(s) let existingGHCard = null @@ -174,7 +175,7 @@ async function assignPullRequestToCorrectColumn (github, robot, repo, pullReques break } } catch (err) { - robot.log.error(`assign-approved-pr-to-test - Failed to retrieve project card for the PR, aborting: ${err}`, c.id, pullRequest.issue_url) + robot.log.error(`${botName} - Failed to retrieve project card for the PR, aborting: ${err}`, c.id, pullRequest.issue_url) return } } @@ -182,39 +183,39 @@ async function assignPullRequestToCorrectColumn (github, robot, repo, pullReques if (existingGHCard) { // Move PR card to the destination column try { - robot.log.trace(`assign-approved-pr-to-test - Found card in source column ${srcColumn.name}`, existingGHCard.id, srcColumn.id) + robot.log.trace(`${botName} - Found card in source column ${srcColumn.name}`, existingGHCard.id, srcColumn.id) if (dstColumn === srcColumn) { return } if (process.env.DRY_RUN || process.env.DRY_RUN_PR_TO_TEST) { - robot.log.info(`assign-approved-pr-to-test - Would have moved card ${existingGHCard.id} to ${dstColumn.name} for PR #${prNumber}`) + robot.log.info(`${botName} - Would have moved card ${existingGHCard.id} to ${dstColumn.name} for PR #${prNumber}`) } else { // Found in the source column, let's move it to the destination column await github.projects.moveProjectCard({id: existingGHCard.id, position: 'bottom', column_id: dstColumn.id}) - robot.log.info(`assign-approved-pr-to-test - Moved card ${existingGHCard.id} to ${dstColumn.name} for PR #${prNumber}`) + robot.log.info(`${botName} - Moved card ${existingGHCard.id} to ${dstColumn.name} for PR #${prNumber}`) } slackHelper.sendMessage(robot, slackClient, room, `Assigned PR to ${dstColumn.name} column\n${pullRequest.html_url}`) } catch (err) { - robot.log.error(`assign-approved-pr-to-test - Couldn't move project card for the PR: ${err}`, srcColumn.id, dstColumn.id, pullRequest.id) + robot.log.error(`${botName} - Couldn't move project card for the PR: ${err}`, srcColumn.id, dstColumn.id, pullRequest.id) slackHelper.sendMessage(robot, slackClient, room, `I couldn't move the PR to ${dstColumn.name} column :confused:\n${pullRequest.html_url}`) } } else { try { - robot.log.debug(`assign-approved-pr-to-test - Didn't find card in source column(s)`, srcColumns.map(c => c.id)) + robot.log.debug(`${botName} - Didn't find card in source column(s)`, srcColumns.map(c => c.id)) // Look for PR card in destination column try { const existingGHCard = await gitHubHelpers.getProjectCardForIssue(github, dstColumn.id, pullRequest.issue_url) if (existingGHCard) { - robot.log.trace(`assign-approved-pr-to-test - Found card in target column, ignoring`, existingGHCard.id, dstColumn.id) + robot.log.trace(`${botName} - Found card in target column, ignoring`, existingGHCard.id, dstColumn.id) return } } catch (err) { - robot.log.error(`assign-approved-pr-to-test - Failed to retrieve project card for the PR, aborting: ${err}`, dstColumn.id, pullRequest.issue_url) + robot.log.error(`${botName} - Failed to retrieve project card for the PR, aborting: ${err}`, dstColumn.id, pullRequest.issue_url) return } @@ -228,11 +229,11 @@ async function assignPullRequestToCorrectColumn (github, robot, repo, pullReques content_id: pullRequest.id }) - robot.log.info(`assign-approved-pr-to-test - Created card ${ghcardPayload.data.id} in ${dstColumn.name} for PR #${prNumber}`) + robot.log.info(`${botName} - Created card ${ghcardPayload.data.id} in ${dstColumn.name} for PR #${prNumber}`) } } catch (err) { // We normally arrive here because there is already a card for the PR in another column - robot.log.debug(`assign-approved-pr-to-test - Couldn't create project card for the PR: ${err}`, dstColumn.id, pullRequest.id) + robot.log.debug(`${botName} - Couldn't create project card for the PR: ${err}`, dstColumn.id, pullRequest.id) } } } diff --git a/bot_scripts/assign-new-pr-to-review.js b/bot_scripts/assign-new-pr-to-review.js index 8eb0512..3c1b0ff 100644 --- a/bot_scripts/assign-new-pr-to-review.js +++ b/bot_scripts/assign-new-pr-to-review.js @@ -14,13 +14,15 @@ const defaultConfig = require('../lib/config') const getConfig = require('probot-config') const Slack = require('probot-slack-status') +const slackHelper = require('../lib/slack') +const botName = 'assign-new-pr-to-review' let slackClient = null module.exports = (robot) => { // robot.on('slack.connected', ({ slack }) => { Slack(robot, (slack) => { - robot.log.trace('assign-new-pr-to-review - Connected, assigned slackClient') + robot.log.trace(`${botName} - Connected, assigned slackClient`) slackClient = slack }) @@ -45,7 +47,7 @@ async function assignPullRequestToReview (context, robot) { return } - robot.log(`assign-new-pr-to-review - Handling Pull Request #${prNumber} on repo ${ownerName}/${repoName}`) + robot.log(`${botName} - Handling Pull Request #${prNumber} on repo ${ownerName}/${repoName}`) // Fetch repo projects // TODO: The repo project and project column info should be cached @@ -63,11 +65,11 @@ async function assignPullRequestToReview (context, robot) { // Find 'Pipeline for QA' project const project = ghprojectsPayload.data.find(p => p.name === projectBoardName) if (!project) { - robot.log.error(`assign-new-pr-to-review - Couldn't find project ${projectBoardName} in repo ${ownerName}/${repoName}`) + robot.log.error(`${botName} - Couldn't find project ${projectBoardName} in repo ${ownerName}/${repoName}`) return } - robot.log.debug(`assign-new-pr-to-review - Fetched ${project.name} project (${project.id})`) + robot.log.debug(`${botName} - Fetched ${project.name} project (${project.id})`) // Fetch REVIEW column ID try { @@ -75,24 +77,24 @@ async function assignPullRequestToReview (context, robot) { column = ghcolumnsPayload.data.find(c => c.name === reviewColumnName) if (!column) { - robot.log.error(`assign-new-pr-to-review - Couldn't find ${reviewColumnName} column in project ${project.name}`) + robot.log.error(`${botName} - Couldn't find ${reviewColumnName} column in project ${project.name}`) return } - robot.log.debug(`assign-new-pr-to-review - Fetched ${column.name} column (${column.id})`) + robot.log.debug(`${botName} - Fetched ${column.name} column (${column.id})`) } catch (err) { - robot.log.error(`assign-new-pr-to-review - Couldn't fetch the github columns for project: ${err}`, ownerName, repoName, project.id) + robot.log.error(`${botName} - Couldn't fetch the github columns for project: ${err}`, ownerName, repoName, project.id) return } } catch (err) { - robot.log.error(`assign-new-pr-to-review - Couldn't fetch the github projects for repo: ${err}`, ownerName, repoName) + robot.log.error(`${botName} - Couldn't fetch the github projects for repo: ${err}`, ownerName, repoName) return } // Create project card for the PR in the REVIEW column try { if (process.env.DRY_RUN) { - robot.log.debug('assign-new-pr-to-review - Would have created card', column.id, payload.pull_request.id) + robot.log.debug(`${botName} - Would have created card`, column.id, payload.pull_request.id) } else { const ghcardPayload = await github.projects.createProjectCard({ column_id: column.id, @@ -100,13 +102,12 @@ async function assignPullRequestToReview (context, robot) { content_id: payload.pull_request.id }) - robot.log.debug(`assign-new-pr-to-review - Created card: ${ghcardPayload.data.url}`, ghcardPayload.data.id) + robot.log.debug(`${botName} - Created card: ${ghcardPayload.data.url}`, ghcardPayload.data.id) } // Send message to Slack - const slackHelper = require('../lib/slack') slackHelper.sendMessage(robot, slackClient, config.slack.notification.room, `Assigned PR to ${reviewColumnName} in ${projectBoardName} project\n${payload.pull_request.html_url}`) } catch (err) { - robot.log.error(`assign-new-pr-to-review - Couldn't create project card for the PR: ${err}`, column.id, payload.pull_request.id) + robot.log.error(`${botName} - Couldn't create project card for the PR: ${err}`, column.id, payload.pull_request.id) } } diff --git a/bot_scripts/assign-to-bounty-awaiting-for-approval.js b/bot_scripts/assign-to-bounty-awaiting-for-approval.js index c50eac8..1b35f19 100644 --- a/bot_scripts/assign-to-bounty-awaiting-for-approval.js +++ b/bot_scripts/assign-to-bounty-awaiting-for-approval.js @@ -17,12 +17,13 @@ const defaultConfig = require('../lib/config') const getConfig = require('probot-config') const Slack = require('probot-slack-status') +const botName = 'assign-to-bounty-awaiting-for-approval' let slackClient = null module.exports = (robot) => { // robot.on('slack.connected', ({ slack }) => { Slack(robot, (slack) => { - robot.log.trace('assign-to-bounty-awaiting-for-approval - Connected, assigned slackClient') + robot.log.trace(`${botName} - Connected, assigned slackClient`) slackClient = slack }) @@ -55,14 +56,14 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { const watchedLabelName = projectBoardConfig['awaiting-approval-label-name'] if (payload.label.name !== watchedLabelName) { - robot.log.debug(`assign-to-bounty-awaiting-for-approval - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`) + robot.log.debug(`${botName} - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`) return } if (assign) { - robot.log(`assign-to-bounty-awaiting-for-approval - Handling labeling of #${payload.issue.number} with ${payload.label.name} on repo ${ownerName}/${repoName}`) + robot.log(`${botName} - Handling labeling of #${payload.issue.number} with ${payload.label.name} on repo ${ownerName}/${repoName}`) } else { - robot.log(`assign-to-bounty-awaiting-for-approval - Handling unlabeling of #${payload.issue.number} with ${payload.label.name} on repo ${ownerName}/${repoName}`) + robot.log(`${botName} - Handling unlabeling of #${payload.issue.number} with ${payload.label.name} on repo ${ownerName}/${repoName}`) } // Fetch org projects @@ -82,11 +83,11 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { // Find 'Status SOB Swarm' project const project = ghprojectsPayload.data.find(p => p.name === projectBoardName) if (!project) { - robot.log.error(`assign-to-bounty-awaiting-for-approval - Couldn't find project ${projectBoardName} in ${orgName} org`) + robot.log.error(`${botName} - Couldn't find project ${projectBoardName} in ${orgName} org`) return } - robot.log.debug(`assign-to-bounty-awaiting-for-approval - Fetched ${project.name} project (${project.id})`) + robot.log.debug(`${botName} - Fetched ${project.name} project (${project.id})`) // Fetch bounty-awaiting-approval column ID try { @@ -94,17 +95,17 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { column = ghcolumnsPayload.data.find(c => c.name === approvalColumnName) if (!column) { - robot.log.error(`assign-to-bounty-awaiting-for-approval - Couldn't find ${approvalColumnName} column in project ${project.name}`) + robot.log.error(`${botName} - Couldn't find ${approvalColumnName} column in project ${project.name}`) return } - robot.log.debug(`assign-to-bounty-awaiting-for-approval - Fetched ${column.name} column (${column.id})`) + robot.log.debug(`${botName} - Fetched ${column.name} column (${column.id})`) } catch (err) { - robot.log.error(`assign-to-bounty-awaiting-for-approval - Couldn't fetch the github columns for project: ${err}`, ownerName, repoName, project.id) + robot.log.error(`${botName} - Couldn't fetch the github columns for project: ${err}`, ownerName, repoName, project.id) return } } catch (err) { - robot.log.error(`assign-to-bounty-awaiting-for-approval - Couldn't fetch the github projects for repo: ${err}`, ownerName, repoName) + robot.log.error(`${botName} - Couldn't fetch the github projects for repo: ${err}`, ownerName, repoName) return } @@ -113,9 +114,9 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { if (process.env.DRY_RUN) { if (assign) { - robot.log.info(`assign-to-bounty-awaiting-for-approval - Would have created card for issue`, column.id, payload.issue.id) + robot.log.info(`${botName} - Would have created card for issue`, column.id, payload.issue.id) } else { - robot.log.info(`assign-to-bounty-awaiting-for-approval - Would have deleted card for issue`, column.id, payload.issue.id) + robot.log.info(`${botName} - Would have deleted card for issue`, column.id, payload.issue.id) } } else { if (assign) { @@ -128,19 +129,19 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { }) const ghcard = ghcardPayload.data - robot.log(`assign-to-bounty-awaiting-for-approval - Created card: ${ghcard.url}`, ghcard.id) + robot.log(`${botName} - Created card: ${ghcard.url}`, ghcard.id) } catch (err) { - robot.log.error(`assign-to-bounty-awaiting-for-approval - Couldn't create project card for the issue: ${err}`, column.id, payload.issue.id) + robot.log.error(`${botName} - Couldn't create project card for the issue: ${err}`, column.id, payload.issue.id) } } else { try { const ghcard = await gitHubHelpers.getProjectCardForIssue(github, column.id, payload.issue.url) if (ghcard) { await github.projects.deleteProjectCard({id: ghcard.id}) - robot.log(`assign-to-bounty-awaiting-for-approval - Deleted card: ${ghcard.url}`, ghcard.id) + robot.log(`${botName} - Deleted card: ${ghcard.url}`, ghcard.id) } } catch (err) { - robot.log.error(`assign-to-bounty-awaiting-for-approval - Couldn't delete project card for the issue: ${err}`, column.id, payload.issue.id) + robot.log.error(`${botName} - Couldn't delete project card for the issue: ${err}`, column.id, payload.issue.id) } } } diff --git a/bot_scripts/bounty-awaiting-approval-slack-ping.js b/bot_scripts/bounty-awaiting-approval-slack-ping.js index 84892f6..ada382f 100644 --- a/bot_scripts/bounty-awaiting-approval-slack-ping.js +++ b/bot_scripts/bounty-awaiting-approval-slack-ping.js @@ -18,11 +18,11 @@ const HashSet = require('hashset') const defaultConfig = require('../lib/config') const slackHelper = require('../lib/slack') -module.exports = (robot, getSlackMentionFromGitHubId) => { - robot.log('bounty-awaiting-approval-slack-ping - Connected to bounty-awaiting-approval-slack-ping') +const botName = 'bounty-awaiting-approval-slack-ping' +module.exports = (robot, getSlackMentionFromGitHubId) => { Slack(robot, (slack) => { - robot.log.trace('bounty-awaiting-approval-slack-ping - Connected to Slack') + robot.log.trace(`${botName} - Connected to Slack`) registerForNewBounties(robot, slack, getSlackMentionFromGitHubId) }) @@ -46,22 +46,22 @@ async function notifyCollaborators (context, robot, slackClient, getSlackMention const gitHubTeamConfig = config ? config['github-team'] : null if (!bountyProjectBoardConfig) { - robot.log.debug(`bounty-awaiting-approval-slack-ping - Bounty project board not configured in repo ${ownerName}/${repoName}, ignoring`) + robot.log.debug(`${botName} - Bounty project board not configured in repo ${ownerName}/${repoName}, ignoring`) return } if (!gitHubTeamConfig) { - robot.log.debug(`bounty-awaiting-approval-slack-ping - GitHub team not configured in repo ${ownerName}/${repoName}, ignoring`) + robot.log.debug(`${botName} - GitHub team not configured in repo ${ownerName}/${repoName}, ignoring`) return } const watchedLabelName = bountyProjectBoardConfig['awaiting-approval-label-name'] if (payload.label.name !== watchedLabelName) { - robot.log.debug(`bounty-awaiting-approval-slack-ping - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`) + robot.log.debug(`${botName} - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`) return null } - robot.log(`bounty-awaiting-approval-slack-ping - issue #${payload.issue.number} on ${ownerName}/${repoName} was labeled as a bounty awaiting approval. Pinging slack...`) + robot.log(`${botName} - issue #${payload.issue.number} on ${ownerName}/${repoName} was labeled as a bounty awaiting approval. Pinging slack...`) const slackCollaborators = await getSlackCollaborators(ownerName, repoName, github, robot, gitHubTeamConfig, getSlackMentionFromGitHubId) @@ -92,7 +92,7 @@ function randomInt (low, high) { async function getSlackCollaborators (ownerName, repoName, github, robot, gitHubTeamConfig, getSlackMentionFromGitHubId) { const teamSlug = gitHubTeamConfig['slug'] if (!teamSlug) { - robot.log.debug(`bounty-awaiting-approval-slack-ping - GitHub team slug not configured in repo ${ownerName}/${repoName}, ignoring`) + robot.log.debug(`${botName} - GitHub team slug not configured in repo ${ownerName}/${repoName}, ignoring`) return } @@ -100,7 +100,7 @@ async function getSlackCollaborators (ownerName, repoName, github, robot, gitHub const teams = await github.paginate(github.orgs.getTeams({org: ownerName}), res => res.data) const team = teams.find(t => t.slug === teamSlug) if (!team) { - robot.log.debug(`bounty-awaiting-approval-slack-ping - GitHub team with slug ${teamSlug} was not found. Ignoring`) + robot.log.debug(`${botName} - GitHub team with slug ${teamSlug} was not found. Ignoring`) return } diff --git a/bot_scripts/greet-new-contributor.js b/bot_scripts/greet-new-contributor.js index 618dd9e..f1a9a74 100644 --- a/bot_scripts/greet-new-contributor.js +++ b/bot_scripts/greet-new-contributor.js @@ -15,12 +15,13 @@ const Slack = require('probot-slack-status') const defaultConfig = require('../lib/config') +const botName = 'greet-new-contributor' let slackClient = null module.exports = (robot) => { // robot.on('slack.connected', ({ slack }) => { Slack(robot, (slack) => { - robot.log.trace('Connected, assigned slackClient') + robot.log.trace(`${botName} - Connected, assigned slackClient`) slackClient = slack }) @@ -45,7 +46,7 @@ async function greetNewContributor (context, robot) { return } - robot.log(`greetNewContributor - Handling Pull Request #${prNumber} on repo ${ownerName}/${repoName}`) + robot.log(`${botName} - Handling Pull Request #${prNumber} on repo ${ownerName}/${repoName}`) try { const ghissuesPayload = await github.issues.getForRepo({ @@ -60,7 +61,7 @@ async function greetNewContributor (context, robot) { try { const welcomeMessage = welcomeBotConfig.message if (process.env.DRY_RUN) { - robot.log('Would have created comment in GHI', ownerName, repoName, prNumber, welcomeMessage) + robot.log(`${botName} - Would have created comment in GHI`, ownerName, repoName, prNumber, welcomeMessage) } else { await github.issues.createComment({ owner: ownerName, @@ -75,13 +76,13 @@ async function greetNewContributor (context, robot) { slackHelper.sendMessage(robot, slackClient, config.slack.notification.room, `Greeted ${payload.pull_request.user.login} on his first PR in the ${repoName} repo\n${payload.pull_request.html_url}`) } catch (err) { if (err.code !== 404) { - robot.log.error(`Couldn't create comment on PR: ${err}`, ownerName, repoName) + robot.log.error(`${botName} - Couldn't create comment on PR: ${err}`, ownerName, repoName) } } } else { - robot.log.debug('This is not the user\'s first PR on the repo, ignoring', ownerName, repoName, payload.pull_request.user.login) + robot.log.debug(`${botName} - This is not the user's first PR on the repo, ignoring`, ownerName, repoName, payload.pull_request.user.login) } } catch (err) { - robot.log.error(`Couldn't fetch the user's github issues for repo: ${err}`, ownerName, repoName) + robot.log.error(`${botName} - Couldn't fetch the user's github issues for repo: ${err}`, ownerName, repoName) } } diff --git a/bot_scripts/trigger-automation-test-build.js b/bot_scripts/trigger-automation-test-build.js index 7e6c23e..f84df5d 100644 --- a/bot_scripts/trigger-automation-test-build.js +++ b/bot_scripts/trigger-automation-test-build.js @@ -17,11 +17,12 @@ const HashMap = require('hashmap') const defaultConfig = require('../lib/config') const gitHubHelpers = require('../lib/github-helpers') +const botName = 'trigger-automation-test-build' const pendingPullRequests = new HashMap() module.exports = (robot) => { if (!process.env.JENKINS_URL) { - robot.log.info('trigger-automation-test-build - Jenkins is not configured, not loading script') + robot.log.info(`${botName} - Jenkins is not configured, not loading script`) return } @@ -37,7 +38,7 @@ async function processChangedProjectCard (robot, context) { const { github, payload } = context const repo = payload.repository if (!repo) { - robot.log.debug(`trigger-automation-test-build - Repository info is not present in payload, ignoring`) + robot.log.debug(`${botName} - Repository info is not present in payload, ignoring`) return } @@ -49,7 +50,7 @@ async function processChangedProjectCard (robot, context) { } if (payload.project_card.note) { - robot.log.trace(`trigger-automation-test-build - Card is a note, ignoring`) + robot.log.trace(`${botName} - Card is a note, ignoring`) return } @@ -57,7 +58,7 @@ async function processChangedProjectCard (robot, context) { const testColumnName = projectBoardConfig['test-column-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']) + robot.log.trace(`${botName} - Pull request project doesn't match watched repo, exiting`, repo.full_name, automatedTestsConfig['repo-full-name']) return } @@ -66,13 +67,13 @@ async function processChangedProjectCard (robot, context) { const columnPayload = await github.projects.getProjectColumn({ id: payload.project_card.column_id }) if (columnPayload.data.name !== testColumnName) { - robot.log.trace(`trigger-automation-test-build - Card column name doesn't match watched column name, exiting`, columnPayload.data.name, testColumnName) + robot.log.trace(`${botName} - Card column name doesn't match watched column name, exiting`, columnPayload.data.name, testColumnName) return } inTestColumn = columnPayload.data } catch (error) { - robot.log.warn(`trigger-automation-test-build - Error while fetching project column`, payload.project_card.column_id, error) + robot.log.warn(`${botName} - Error while fetching project column`, payload.project_card.column_id, error) return } @@ -87,11 +88,11 @@ async function processChangedProjectCard (robot, context) { project = projectPayload.data if (project.name !== projectBoardName) { - robot.log.trace(`trigger-automation-test-build - Card column name doesn't match watched column name, exiting`, project.name, projectBoardName) + robot.log.trace(`${botName} - Card column name doesn't match watched column name, exiting`, project.name, projectBoardName) return } } catch (error) { - robot.log.warn(`trigger-automation-test-build - Error while fetching project column`, payload.project_card.column_id, error) + robot.log.warn(`${botName} - Error while fetching project column`, payload.project_card.column_id, error) return } @@ -113,16 +114,16 @@ async function processPullRequest (github, robot, repoOwner, repoName, prNumber, case 'awaiting_reviewers': case 'changes_requested': pendingPullRequests.set(prNumber, { github: github, repoOwner: repoOwner, repoName: repoName, fullJobName: fullJobName }) - robot.log.debug(`trigger-automation-test-build - State is '${state}', adding to backlog to check periodically`, prNumber) + robot.log.debug(`${botName} - State is '${state}', adding to backlog to check periodically`, prNumber) return case 'failed': - robot.log.debug(`trigger-automation-test-build - State is '${state}', exiting`, prNumber) + robot.log.debug(`${botName} - State is '${state}', exiting`, prNumber) return case 'approved': - robot.log.debug(`trigger-automation-test-build - State is '${state}', proceeding`, prNumber) + robot.log.debug(`${botName} - State is '${state}', proceeding`, prNumber) break default: - robot.log.warn(`trigger-automation-test-build - State is '${state}', ignoring`, prNumber) + robot.log.warn(`${botName} - State is '${state}', ignoring`, prNumber) return } } catch (err) { @@ -134,14 +135,14 @@ async function processPullRequest (github, robot, repoOwner, repoName, prNumber, const args = { parameters: { pr_id: prNumber, apk: `--apk=${prNumber}.apk` } } if (process.env.DRY_RUN) { - robot.log(`trigger-automation-test-build - Would start ${fullJobName} job in Jenkins`, prNumber, args) + robot.log(`${botName} - Would start ${fullJobName} job in Jenkins`, prNumber, args) } else { - robot.log(`trigger-automation-test-build - Starting ${fullJobName} job in Jenkins`, prNumber, args) + robot.log(`${botName} - Starting ${fullJobName} job in Jenkins`, prNumber, args) const buildId = await jenkins.job.build(fullJobName, args) - robot.log(`trigger-automation-test-build - Started job in Jenkins`, prNumber, buildId) + robot.log(`${botName} - Started job in Jenkins`, prNumber, buildId) } } catch (error) { - robot.log.error(`trigger-automation-test-build - Error while triggering Jenkins build. Will retry later`, prNumber, error) + robot.log.error(`${botName} - Error while triggering Jenkins build. Will retry later`, prNumber, error) pendingPullRequests.set(prNumber, { github: github, repoOwner: repoOwner, repoName: repoName, fullJobName: fullJobName }) } @@ -150,7 +151,7 @@ async function processPullRequest (github, robot, repoOwner, repoName, prNumber, async function checkPendingPullRequests (robot) { const _pendingPullRequests = pendingPullRequests.clone() - robot.log.trace(`trigger-automation-test-build - Processing ${_pendingPullRequests.size} pending PRs`) + robot.log.trace(`${botName} - Processing ${_pendingPullRequests.size} pending PRs`) for (const kvp of _pendingPullRequests.entries()) { const prNumber = kvp[0] @@ -159,5 +160,5 @@ async function checkPendingPullRequests (robot) { await processPullRequest(github, robot, repoOwner, repoName, prNumber, fullJobName) } - robot.log.trace(`trigger-automation-test-build - Finished processing ${_pendingPullRequests.size} pending PRs`) + robot.log.trace(`${botName} - Finished processing ${_pendingPullRequests.size} pending PRs`) }