diff --git a/bot_scripts/assign-to-bounty-awaiting-for-approval.js b/bot_scripts/assign-to-bounty-awaiting-for-approval.js index 9fbf47c..245cc62 100644 --- a/bot_scripts/assign-to-bounty-awaiting-for-approval.js +++ b/bot_scripts/assign-to-bounty-awaiting-for-approval.js @@ -66,9 +66,9 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { return } - const bountyLabelName = projectBoardConfig['bounty-label-name'] - const isOfficialBounty = !!payload.issue.labels.find(l => l.name === bountyLabelName) - const bountySize = getBountySize(payload.issue.labels, projectBoardConfig) + // const bountyLabelName = projectBoardConfig['bounty-label-name'] + // const isOfficialBounty = !!payload.issue.labels.find(l => l.name === bountyLabelName) + // const bountySize = getBountySize(payload.issue.labels, projectBoardConfig) if (process.env.DRY_RUN) { if (assign) { @@ -119,33 +119,33 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { // } } -function getSlackMessage (projectBoardName, approvalColumnName, payload, assign, isOfficialBounty, bountySize) { - if (assign) { - return `Assigned issue to ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}` - } +// function getSlackMessage (projectBoardName, approvalColumnName, payload, assign, isOfficialBounty, bountySize) { +// if (assign) { +// return `Assigned issue to ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}` +// } - if (!isOfficialBounty) { - return `Unassigned issue from ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}` - } +// if (!isOfficialBounty) { +// return `Unassigned issue from ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}` +// } - if (bountySize) { - return `${payload.issue.html_url} has been approved as an official bounty (size: ${bountySize})!` - } - return `${payload.issue.html_url} has been approved as an official bounty!` -} +// if (bountySize) { +// return `${payload.issue.html_url} has been approved as an official bounty (size: ${bountySize})!` +// } +// return `${payload.issue.html_url} has been approved as an official bounty!` +// } -function getBountySize (labels, projectBoardConfig) { - const regexString = projectBoardConfig['bounty-size-label-name-regex'] - if (!regexString) { - return null - } +// function getBountySize (labels, projectBoardConfig) { +// const regexString = projectBoardConfig['bounty-size-label-name-regex'] +// if (!regexString) { +// return null +// } - const bountySizeLabelRegex = new RegExp(regexString) +// const bountySizeLabelRegex = new RegExp(regexString) - const match = labels.map(l => bountySizeLabelRegex.exec(l.name)).find(m => m != null) - if (match) { - return match[1] - } +// const match = labels.map(l => bountySizeLabelRegex.exec(l.name)).find(m => m != null) +// if (match) { +// return match[1] +// } - return null -} +// return null +// } diff --git a/bot_scripts/manage-pr-checklist.js b/bot_scripts/manage-pr-checklist.js index 887c392..543920f 100644 --- a/bot_scripts/manage-pr-checklist.js +++ b/bot_scripts/manage-pr-checklist.js @@ -13,6 +13,7 @@ const fetch = require('node-fetch') const getConfig = require('probot-config') const defaultConfig = require('../lib/config') +const gitHubHelpers = require('../lib/github-helpers') const botName = 'manage-pr-checklist' module.exports = (robot) => { @@ -50,7 +51,7 @@ async function handlePullRequest (context, robot) { } if (settings.title == null) settings.title = '' if (settings.checklist == null) settings.checklist = {} - const currentStatus = await getCurrentStatus(context) + const currentStatus = await gitHubHelpers.getPullRequestCurrentStatusForContext(context, 'PRChecklist') const { isChecklistComplete, firstCheck } = await verifyChecklist(context, settings) const newStatus = isChecklistComplete ? 'success' : 'pending' const hasChange = firstCheck || currentStatus !== newStatus @@ -83,14 +84,6 @@ async function handlePullRequest (context, robot) { } } -async function getCurrentStatus (context) { - const { data: { statuses } } = await context.github.repos.getCombinedStatusForRef(context.repo({ - ref: context.payload.pull_request.head.sha - })) - - return (statuses.find(status => status.context === 'PRChecklist') || {}).state -} - async function createOrEditChecklist (context, checkList, header) { const owner = context.payload.repository.owner.login const repo = context.payload.repository.name diff --git a/bot_scripts/trigger-automation-test-build.js b/bot_scripts/trigger-automation-test-build.js index ba8c24e..1ed2f7e 100644 --- a/bot_scripts/trigger-automation-test-build.js +++ b/bot_scripts/trigger-automation-test-build.js @@ -98,31 +98,41 @@ async function processChangedProjectCard (robot, context) { const prNumber = last(payload.project_card.content_url.split('/'), -1) const fullJobName = automatedTestsConfig['job-full-name'] - await processPullRequest(github, robot, { ...repoInfo, number: prNumber }, fullJobName) + await processPullRequest(context, robot, { ...repoInfo, number: prNumber }, fullJobName) } -async function processPullRequest (github, robot, prInfo, fullJobName) { +async function processPullRequest (context, robot, prInfo, fullJobName) { + const { github } = context + // Remove the PR from the pending PR list, if it is there pendingPullRequests.delete(prInfo.number) try { - const state = await gitHubHelpers.getReviewApprovalState(github, robot, prInfo, null) + // Get detailed pull request + const pullRequestPayload = await github.pullRequests.get(prInfo) + const pullRequest = pullRequestPayload.data + if (!pullRequest) { + robot.log.warn(`${botName} - Could not find PR`, prInfo) + return + } - switch (state) { - case 'unstable': - case 'awaiting_reviewers': - case 'changes_requested': + const statusContext = 'jenkins/prs/android-e2e' + const currentStatus = await gitHubHelpers.getPullRequestCurrentStatusForContext(context, statusContext, pullRequest) + + switch (currentStatus) { + case 'pending': pendingPullRequests.set(prInfo.number, { github: github, prInfo, fullJobName: fullJobName }) - robot.log.debug(`${botName} - State is '${state}', adding to backlog to check periodically`, prInfo) + robot.log.debug(`${botName} - Status for ${statusContext} is '${currentStatus}', adding to backlog to check periodically`, prInfo) return - case 'failed': - robot.log.debug(`${botName} - State is '${state}', exiting`, prInfo) + case 'error': + case 'failure': + robot.log.debug(`${botName} - Status for ${statusContext} is '${currentStatus}', exiting`, prInfo) return - case 'approved': - robot.log.debug(`${botName} - State is '${state}', proceeding`, prInfo) + case 'success': + robot.log.debug(`${botName} - Status for ${statusContext} is '${currentStatus}', proceeding`, prInfo) break default: - robot.log.warn(`${botName} - State is '${state}', ignoring`, prInfo) + robot.log.warn(`${botName} - Status for ${statusContext} is '${currentStatus}', ignoring`, prInfo) return } } catch (err) { diff --git a/lib/github-helpers.js b/lib/github-helpers.js index 63615ce..16b5d1d 100644 --- a/lib/github-helpers.js +++ b/lib/github-helpers.js @@ -13,7 +13,8 @@ module.exports = { getProjectCardForIssue: _getProjectCardForIssue, getOrgProjectByName: _getOrgProjectByName, getRepoProjectByName: _getRepoProjectByName, - getProjectColumnByName: _getProjectColumnByName + getProjectColumnByName: _getProjectColumnByName, + getPullRequestCurrentStatusForContext: _getPullRequestCurrentStatusForContext } async function _getPullRequestReviewStates (github, prInfo) { @@ -166,3 +167,15 @@ async function _getProjectColumnByName (github, robot, project, columnName, botN return null } } + +async function _getPullRequestCurrentStatusForContext (context, statusContext, pullRequest) { + if (!pullRequest) { + pullRequest = context.payload.pull_request + } + + const { data: { statuses } } = await context.github.repos.getCombinedStatusForRef(context.repo({ + ref: pullRequest.head.sha + })) + + return (statuses.find(status => status.context === statusContext) || {}).state +}