diff --git a/bot_scripts/assign-approved-pr-to-test.js b/bot_scripts/assign-approved-pr-to-test.js index d100be4..a19f61f 100644 --- a/bot_scripts/assign-approved-pr-to-test.js +++ b/bot_scripts/assign-approved-pr-to-test.js @@ -27,7 +27,7 @@ module.exports = robot => { async function checkOpenPullRequests (robot, context) { const { github, payload } = context const repo = payload.repository - const repoInfo = { owner: payload.repository.owner.login, repo: payload.repository.name } + const repoInfo = context.repo() const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml')) const projectBoardConfig = config ? config['project-board'] : null @@ -68,14 +68,14 @@ async function checkOpenPullRequests (robot, context) { try { // Gather all open PRs in this repo const allPullRequests = await github.paginate( - github.pullRequests.getAll({ ...repoInfo, per_page: 100 }), + github.pullRequests.getAll(context.repo({ per_page: 100 })), res => res.data ) // And make sure they are assigned to the correct project column for (const pullRequest of allPullRequests) { try { - await assignPullRequestToCorrectColumn(github, robot, repo, pullRequest, testedPullRequestLabelName, columns, config.slack.notification.room) + await assignPullRequestToCorrectColumn(context, robot, repo, pullRequest, testedPullRequestLabelName, columns, config.slack.notification.room) } catch (err) { robot.log.error(`${botName} - Unhandled exception while processing PR: ${err}`, repoInfo) } @@ -88,7 +88,8 @@ async function checkOpenPullRequests (robot, context) { } } -async function assignPullRequestToCorrectColumn (github, robot, repo, pullRequest, testedPullRequestLabelName, columns, room) { +async function assignPullRequestToCorrectColumn (context, robot, repo, pullRequest, testedPullRequestLabelName, columns, room) { + const { github } = context const prInfo = { owner: repo.owner.login, repo: repo.name, number: pullRequest.number } let state = null diff --git a/bot_scripts/assign-new-pr-to-review.js b/bot_scripts/assign-new-pr-to-review.js index b723d03..e28a416 100644 --- a/bot_scripts/assign-new-pr-to-review.js +++ b/bot_scripts/assign-new-pr-to-review.js @@ -30,7 +30,7 @@ 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 repoInfo = { owner: payload.repository.owner.login, repo: payload.repository.name } + const repoInfo = context.repo() const prNumber = payload.pull_request.number const projectBoardConfig = config ? config['project-board'] : null diff --git a/bot_scripts/assign-to-bounty-awaiting-for-approval.js b/bot_scripts/assign-to-bounty-awaiting-for-approval.js index 245cc62..72daf87 100644 --- a/bot_scripts/assign-to-bounty-awaiting-for-approval.js +++ b/bot_scripts/assign-to-bounty-awaiting-for-approval.js @@ -37,7 +37,7 @@ module.exports = (robot) => { async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { const { github, payload } = context - const repoInfo = { owner: payload.repository.owner.login, repo: payload.repository.name } + const repoInfo = context.repo() const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml')) const projectBoardConfig = config ? config['bounty-project-board'] : null diff --git a/bot_scripts/assign-to-bounty-bug-column.js b/bot_scripts/assign-to-bounty-bug-column.js index a8f08b2..8379f36 100644 --- a/bot_scripts/assign-to-bounty-bug-column.js +++ b/bot_scripts/assign-to-bounty-bug-column.js @@ -36,7 +36,7 @@ module.exports = (robot) => { async function assignIssueToBountyBug (context, robot, assign) { const { github, payload } = context - const repoInfo = { owner: payload.repository.owner.login, repo: payload.repository.name } + const repoInfo = context.repo() const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml')) const projectBoardConfig = config ? config['bounty-project-board'] : null diff --git a/bot_scripts/bounty-awaiting-approval-slack-ping.js b/bot_scripts/bounty-awaiting-approval-slack-ping.js index 71c8bf4..b82da20 100644 --- a/bot_scripts/bounty-awaiting-approval-slack-ping.js +++ b/bot_scripts/bounty-awaiting-approval-slack-ping.js @@ -33,7 +33,7 @@ function registerForNewBounties (robot) { async function notifyCollaborators (context, robot) { const { github, payload } = context - const repoInfo = { owner: payload.repository.owner.login, repo: payload.repository.name } + const repoInfo = context.repo() const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml')) const bountyProjectBoardConfig = config ? config['bounty-project-board'] : null const gitHubTeamConfig = config ? config['github-team'] : null diff --git a/bot_scripts/greet-new-contributor.js b/bot_scripts/greet-new-contributor.js index 790012f..eee8507 100644 --- a/bot_scripts/greet-new-contributor.js +++ b/bot_scripts/greet-new-contributor.js @@ -43,8 +43,8 @@ function executeTemplate (templateString, templateVars) { async function greetNewContributor (context, robot) { const { github, payload } = context const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml')) - const repoInfo = { owner: payload.repository.owner.login, repo: payload.repository.name } - const prInfo = { ...repoInfo, number: payload.pull_request.number } + const repoInfo = context.repo() + const prInfo = context.issue() const welcomeBotConfig = config ? config['welcome-bot'] : null if (!welcomeBotConfig) { @@ -68,10 +68,7 @@ async function greetNewContributor (context, robot) { if (process.env.DRY_RUN) { robot.log(`${botName} - Would have created comment in GHI`, prInfo, welcomeMessage) } else { - await github.issues.createComment({ - ...prInfo, - body: welcomeMessage - }) + await github.issues.createComment(context.issue({ body: welcomeMessage })) } // Send message to Slack diff --git a/bot_scripts/trigger-automation-test-build.js b/bot_scripts/trigger-automation-test-build.js index 1ed2f7e..51d6301 100644 --- a/bot_scripts/trigger-automation-test-build.js +++ b/bot_scripts/trigger-automation-test-build.js @@ -42,7 +42,7 @@ async function processChangedProjectCard (robot, context) { return } - const repoInfo = { owner: repo.owner.login, repo: repo.name } + const repoInfo = context.repo() 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