Harmonize logging messages

This commit is contained in:
Pedro Pombeiro 2018-02-09 10:17:50 +01:00
parent 80078b4314
commit 9148a8c8ad
No known key found for this signature in database
GPG Key ID: A65DEB11E4BBC647
4 changed files with 59 additions and 59 deletions

View File

@ -24,7 +24,7 @@ let slackClient = null
module.exports = robot => {
// robot.on('slack.connected', ({ slack }) => {
Slack(robot, (slack) => {
robot.log.trace('Connected, assigned slackClient')
robot.log.trace('assign-approved-pr-to-test - Connected, assigned slackClient')
slackClient = slack
})
@ -51,7 +51,7 @@ async function checkOpenPullRequests (robot, context) {
const projectBoardConfig = config ? config['project-board'] : null
if (!projectBoardConfig) {
robot.log.debug(`Project board not configured in repo ${ownerName}/${repoName}, ignoring`)
robot.log.debug(`assign-approved-pr-to-test - Project board not configured in repo ${ownerName}/${repoName}, ignoring`)
return
}
@ -67,13 +67,13 @@ async function checkOpenPullRequests (robot, context) {
// Find 'Pipeline for QA' project
project = await getProjectFromName(github, ownerName, repoName, projectBoardConfig.name)
if (!project) {
robot.log.error(`Couldn't find project ${projectBoardConfig.name} in repo ${ownerName}/${repoName}`)
robot.log.error(`assign-approved-pr-to-test - Couldn't find project ${projectBoardConfig.name} in repo ${ownerName}/${repoName}`)
return
}
robot.log.debug(`Fetched ${project.name} project (${project.id})`)
robot.log.debug(`assign-approved-pr-to-test - Fetched ${project.name} project (${project.id})`)
} catch (err) {
robot.log.error(`Couldn't fetch the github projects for repo: ${err}`, ownerName, repoName)
robot.log.error(`assign-approved-pr-to-test - Couldn't fetch the github projects for repo: ${err}`, ownerName, repoName)
return
}
@ -83,29 +83,29 @@ async function checkOpenPullRequests (robot, context) {
const ghcolumnsPayload = await github.projects.getProjectColumns({ project_id: project.id })
ghcolumns = ghcolumnsPayload.data
} catch (err) {
robot.log.error(`Couldn't fetch the github columns for project: ${err}`, ownerName, repoName, project.id)
robot.log.error(`assign-approved-pr-to-test - 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(`Couldn't find ${contributorColumnName} column in project ${project.name}`)
robot.log.error(`assign-approved-pr-to-test - Couldn't find ${contributorColumnName} column in project ${project.name}`)
return
}
const reviewColumn = ghcolumns.find(c => c.name === reviewColumnName)
if (!reviewColumn) {
robot.log.error(`Couldn't find ${reviewColumnName} column in project ${project.name}`)
robot.log.error(`assign-approved-pr-to-test - Couldn't find ${reviewColumnName} column in project ${project.name}`)
return
}
const testColumn = ghcolumns.find(c => c.name === testColumnName)
if (!testColumn) {
robot.log.error(`Couldn't find ${testColumnName} column in project ${project.name}`)
robot.log.error(`assign-approved-pr-to-test - Couldn't find ${testColumnName} column in project ${project.name}`)
return
}
robot.log.debug(`Fetched ${contributorColumn.name} (${contributorColumn.id}), ${reviewColumn.name} (${reviewColumn.id}), ${testColumn.name} (${testColumn.id}) columns`)
robot.log.debug(`assign-approved-pr-to-test - Fetched ${contributorColumn.name} (${contributorColumn.id}), ${reviewColumn.name} (${reviewColumn.id}), ${testColumn.name} (${testColumn.id}) columns`)
try {
// Gather all open PRs in this repo
@ -119,11 +119,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(`Unhandled exception while processing PR: ${err}`, ownerName, repoName)
robot.log.error(`assign-approved-pr-to-test - Unhandled exception while processing PR: ${err}`, ownerName, repoName)
}
}
} catch (err) {
robot.log.error(`Couldn't fetch the github pull requests for repo: ${err}`, ownerName, repoName)
robot.log.error(`assign-approved-pr-to-test - Couldn't fetch the github pull requests for repo: ${err}`, ownerName, repoName)
}
}
@ -136,7 +136,7 @@ async function assignPullRequestToCorrectColumn (github, robot, repo, pullReques
try {
state = await gitHubHelpers.getReviewApprovalState(github, robot, repoOwner, repoName, prNumber)
} catch (err) {
robot.log.error(`Couldn't calculate the PR approval state: ${err}`, repoOwner, repoName, prNumber)
robot.log.error(`assign-approved-pr-to-test - Couldn't calculate the PR approval state: ${err}`, repoOwner, repoName, prNumber)
}
let srcColumns, dstColumn
@ -161,7 +161,7 @@ async function assignPullRequestToCorrectColumn (github, robot, repo, pullReques
return
}
robot.log.debug(`assignPullRequestToTest - Handling Pull Request #${prNumber} on repo ${repoOwner}/${repoName}. PR should be in ${dstColumn.name} column`)
robot.log.debug(`assign-approved-pr-to-test - 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 +174,7 @@ async function assignPullRequestToCorrectColumn (github, robot, repo, pullReques
break
}
} catch (err) {
robot.log.error(`Failed to retrieve project card for the PR, aborting: ${err}`, c.id, pullRequest.issue_url)
robot.log.error(`assign-approved-pr-to-test - Failed to retrieve project card for the PR, aborting: ${err}`, c.id, pullRequest.issue_url)
return
}
}
@ -182,39 +182,39 @@ async function assignPullRequestToCorrectColumn (github, robot, repo, pullReques
if (existingGHCard) {
// Move PR card to the destination column
try {
robot.log.trace(`Found card in source column ${srcColumn.name}`, existingGHCard.id, srcColumn.id)
robot.log.trace(`assign-approved-pr-to-test - 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(`Would have moved card ${existingGHCard.id} to ${dstColumn.name} for PR #${prNumber}`)
robot.log.info(`assign-approved-pr-to-test - 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(`Moved card ${existingGHCard.id} to ${dstColumn.name} for PR #${prNumber}`)
robot.log.info(`assign-approved-pr-to-test - 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(`Couldn't move project card for the PR: ${err}`, srcColumn.id, dstColumn.id, pullRequest.id)
robot.log.error(`assign-approved-pr-to-test - 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(`Didn't find card in source column(s)`, srcColumns.map(c => c.id))
robot.log.debug(`assign-approved-pr-to-test - 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(`Found card in target column, ignoring`, existingGHCard.id, dstColumn.id)
robot.log.trace(`assign-approved-pr-to-test - Found card in target column, ignoring`, existingGHCard.id, dstColumn.id)
return
}
} catch (err) {
robot.log.error(`Failed to retrieve project card for the PR, aborting: ${err}`, dstColumn.id, pullRequest.issue_url)
robot.log.error(`assign-approved-pr-to-test - Failed to retrieve project card for the PR, aborting: ${err}`, dstColumn.id, pullRequest.issue_url)
return
}
@ -228,11 +228,11 @@ async function assignPullRequestToCorrectColumn (github, robot, repo, pullReques
content_id: pullRequest.id
})
robot.log.info(`Created card ${ghcardPayload.data.id} in ${dstColumn.name} for PR #${prNumber}`)
robot.log.info(`assign-approved-pr-to-test - 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(`Couldn't create project card for the PR: ${err}`, dstColumn.id, pullRequest.id)
robot.log.debug(`assign-approved-pr-to-test - Couldn't create project card for the PR: ${err}`, dstColumn.id, pullRequest.id)
}
}
}

View File

@ -20,7 +20,7 @@ let slackClient = null
module.exports = (robot) => {
// robot.on('slack.connected', ({ slack }) => {
Slack(robot, (slack) => {
robot.log.trace('Connected, assigned slackClient')
robot.log.trace('assign-new-pr-to-review - Connected, assigned slackClient')
slackClient = slack
})
@ -45,7 +45,7 @@ async function assignPullRequestToReview (context, robot) {
return
}
robot.log(`assignPullRequestToReview - Handling Pull Request #${prNumber} on repo ${ownerName}/${repoName}`)
robot.log(`assign-new-pr-to-review - Handling Pull Request #${prNumber} on repo ${ownerName}/${repoName}`)
// Fetch repo projects
// TODO: The repo project and project column info should be cached
@ -63,11 +63,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(`Couldn't find project ${projectBoardName} in repo ${ownerName}/${repoName}`)
robot.log.error(`assign-new-pr-to-review - Couldn't find project ${projectBoardName} in repo ${ownerName}/${repoName}`)
return
}
robot.log.debug(`Fetched ${project.name} project (${project.id})`)
robot.log.debug(`assign-new-pr-to-review - Fetched ${project.name} project (${project.id})`)
// Fetch REVIEW column ID
try {
@ -75,24 +75,24 @@ async function assignPullRequestToReview (context, robot) {
column = ghcolumnsPayload.data.find(c => c.name === reviewColumnName)
if (!column) {
robot.log.error(`Couldn't find ${reviewColumnName} column in project ${project.name}`)
robot.log.error(`assign-new-pr-to-review - Couldn't find ${reviewColumnName} column in project ${project.name}`)
return
}
robot.log.debug(`Fetched ${column.name} column (${column.id})`)
robot.log.debug(`assign-new-pr-to-review - Fetched ${column.name} column (${column.id})`)
} catch (err) {
robot.log.error(`Couldn't fetch the github columns for project: ${err}`, ownerName, repoName, project.id)
robot.log.error(`assign-new-pr-to-review - Couldn't fetch the github columns for project: ${err}`, ownerName, repoName, project.id)
return
}
} catch (err) {
robot.log.error(`Couldn't fetch the github projects for repo: ${err}`, ownerName, repoName)
robot.log.error(`assign-new-pr-to-review - 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('Would have created card', column.id, payload.pull_request.id)
robot.log.debug('assign-new-pr-to-review - Would have created card', column.id, payload.pull_request.id)
} else {
const ghcardPayload = await github.projects.createProjectCard({
column_id: column.id,
@ -100,13 +100,13 @@ async function assignPullRequestToReview (context, robot) {
content_id: payload.pull_request.id
})
robot.log.debug(`Created card: ${ghcardPayload.data.url}`, ghcardPayload.data.id)
robot.log.debug(`assign-new-pr-to-review - 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(`Couldn't create project card for the PR: ${err}`, column.id, payload.pull_request.id)
robot.log.error(`assign-new-pr-to-review - Couldn't create project card for the PR: ${err}`, column.id, payload.pull_request.id)
}
}

View File

@ -22,7 +22,7 @@ let slackClient = null
module.exports = (robot) => {
// robot.on('slack.connected', ({ slack }) => {
Slack(robot, (slack) => {
robot.log.trace('Connected, assigned slackClient')
robot.log.trace('assign-to-bounty-awaiting-for-approval - Connected, assigned slackClient')
slackClient = slack
})
@ -55,14 +55,14 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) {
const watchedLabelName = projectBoardConfig['awaiting-approval-label-name']
if (payload.label.name !== watchedLabelName) {
robot.log.debug(`assignIssueToBountyAwaitingForApproval - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`)
robot.log.debug(`assign-to-bounty-awaiting-for-approval - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`)
return
}
if (assign) {
robot.log(`assignIssueToBountyAwaitingForApproval - Handling labeling of #${payload.issue.number} with ${payload.label.name} on repo ${ownerName}/${repoName}`)
robot.log(`assign-to-bounty-awaiting-for-approval - Handling labeling of #${payload.issue.number} with ${payload.label.name} on repo ${ownerName}/${repoName}`)
} else {
robot.log(`assignIssueToBountyAwaitingForApproval - Handling unlabeling of #${payload.issue.number} with ${payload.label.name} on repo ${ownerName}/${repoName}`)
robot.log(`assign-to-bounty-awaiting-for-approval - Handling unlabeling of #${payload.issue.number} with ${payload.label.name} on repo ${ownerName}/${repoName}`)
}
// Fetch org projects
@ -82,11 +82,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(`Couldn't find project ${projectBoardName} in ${orgName} org`)
robot.log.error(`assign-to-bounty-awaiting-for-approval - Couldn't find project ${projectBoardName} in ${orgName} org`)
return
}
robot.log.debug(`Fetched ${project.name} project (${project.id})`)
robot.log.debug(`assign-to-bounty-awaiting-for-approval - Fetched ${project.name} project (${project.id})`)
// Fetch bounty-awaiting-approval column ID
try {
@ -94,17 +94,17 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) {
column = ghcolumnsPayload.data.find(c => c.name === approvalColumnName)
if (!column) {
robot.log.error(`Couldn't find ${approvalColumnName} column in project ${project.name}`)
robot.log.error(`assign-to-bounty-awaiting-for-approval - Couldn't find ${approvalColumnName} column in project ${project.name}`)
return
}
robot.log.debug(`Fetched ${column.name} column (${column.id})`)
robot.log.debug(`assign-to-bounty-awaiting-for-approval - Fetched ${column.name} column (${column.id})`)
} catch (err) {
robot.log.error(`Couldn't fetch the github columns for project: ${err}`, ownerName, repoName, project.id)
robot.log.error(`assign-to-bounty-awaiting-for-approval - Couldn't fetch the github columns for project: ${err}`, ownerName, repoName, project.id)
return
}
} catch (err) {
robot.log.error(`Couldn't fetch the github projects for repo: ${err}`, ownerName, repoName)
robot.log.error(`assign-to-bounty-awaiting-for-approval - Couldn't fetch the github projects for repo: ${err}`, ownerName, repoName)
return
}
@ -113,9 +113,9 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) {
if (process.env.DRY_RUN) {
if (assign) {
robot.log.info(`Would have created card for issue`, column.id, payload.issue.id)
robot.log.info(`assign-to-bounty-awaiting-for-approval - Would have created card for issue`, column.id, payload.issue.id)
} else {
robot.log.info(`Would have deleted card for issue`, column.id, payload.issue.id)
robot.log.info(`assign-to-bounty-awaiting-for-approval - Would have deleted card for issue`, column.id, payload.issue.id)
}
} else {
if (assign) {
@ -128,19 +128,19 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) {
})
const ghcard = ghcardPayload.data
robot.log(`Created card: ${ghcard.url}`, ghcard.id)
robot.log(`assign-to-bounty-awaiting-for-approval - Created card: ${ghcard.url}`, ghcard.id)
} catch (err) {
robot.log.error(`Couldn't create project card for the issue: ${err}`, column.id, payload.issue.id)
robot.log.error(`assign-to-bounty-awaiting-for-approval - 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(`Deleted card: ${ghcard.url}`, ghcard.id)
robot.log(`assign-to-bounty-awaiting-for-approval - Deleted card: ${ghcard.url}`, ghcard.id)
}
} catch (err) {
robot.log.error(`Couldn't delete project card for the issue: ${err}`, column.id, payload.issue.id)
robot.log.error(`assign-to-bounty-awaiting-for-approval - Couldn't delete project card for the issue: ${err}`, column.id, payload.issue.id)
}
}
}

View File

@ -19,10 +19,10 @@ const defaultConfig = require('../lib/config')
const slackHelper = require('../lib/slack')
module.exports = (robot, getSlackMentionFromGitHubId) => {
robot.log('Connected to bounty-awaiting-approval-slack-ping')
robot.log('bounty-awaiting-approval-slack-ping - Connected to bounty-awaiting-approval-slack-ping')
Slack(robot, (slack) => {
robot.log.trace('Connected to Slack')
robot.log.trace('bounty-awaiting-approval-slack-ping - 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 project board not configured in repo ${ownerName}/${repoName}, ignoring`)
robot.log.debug(`bounty-awaiting-approval-slack-ping - Bounty project board not configured in repo ${ownerName}/${repoName}, ignoring`)
return
}
if (!gitHubTeamConfig) {
robot.log.debug(`GitHub team not configured in repo ${ownerName}/${repoName}, ignoring`)
robot.log.debug(`bounty-awaiting-approval-slack-ping - 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(`bountyAwaitingApprovalSlackPing - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`)
robot.log.debug(`bounty-awaiting-approval-slack-ping - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`)
return null
}
robot.log(`bountyAwaitingApprovalSlackPing - issue #${payload.issue.number} on ${ownerName}/${repoName} was labeled as a bounty awaiting approval. Pinging slack...`)
robot.log(`bounty-awaiting-approval-slack-ping - 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(`GitHub team slug not configured in repo ${ownerName}/${repoName}, ignoring`)
robot.log.debug(`bounty-awaiting-approval-slack-ping - 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(`bountyAwaitingApprovalSlackPing - GitHub team with slug ${teamSlug} was not found. Ignoring`)
robot.log.debug(`bounty-awaiting-approval-slack-ping - GitHub team with slug ${teamSlug} was not found. Ignoring`)
return
}