From a183bbfe883661fcf63c6e8f7322dfe2def048fd Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Wed, 14 Mar 2018 14:06:59 +0100 Subject: [PATCH] Improve bot so that it doesn't consider issue for IN TEST column if it is labeled as already tested --- bot_scripts/assign-approved-pr-to-test.js | 7 ++++--- bot_scripts/trigger-automation-test-build.js | 2 +- lib/github-helpers.js | 7 ++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bot_scripts/assign-approved-pr-to-test.js b/bot_scripts/assign-approved-pr-to-test.js index 359f0e1..4a6af69 100644 --- a/bot_scripts/assign-approved-pr-to-test.js +++ b/bot_scripts/assign-approved-pr-to-test.js @@ -36,6 +36,7 @@ async function checkOpenPullRequests (robot, context) { return } + const testedPullRequestLabelName = projectBoardConfig['tested-pr-label-name'] const contributorColumnName = projectBoardConfig['contributor-column-name'] const reviewColumnName = projectBoardConfig['review-column-name'] const testColumnName = projectBoardConfig['test-column-name'] @@ -74,7 +75,7 @@ async function checkOpenPullRequests (robot, context) { for (const pullRequest of allPullRequests) { try { const columns = { contributor: contributorColumn, review: reviewColumn, test: testColumn } - await assignPullRequestToCorrectColumn(github, robot, repo, pullRequest, columns, config.slack.notification.room) + await assignPullRequestToCorrectColumn(github, robot, repo, pullRequest, columns, testedPullRequestLabelName, config.slack.notification.room) } catch (err) { robot.log.error(`${botName} - Unhandled exception while processing PR: ${err}`, repoInfo) } @@ -87,12 +88,12 @@ async function checkOpenPullRequests (robot, context) { } } -async function assignPullRequestToCorrectColumn (github, robot, repo, pullRequest, columns, room) { +async function assignPullRequestToCorrectColumn (github, robot, repo, pullRequest, testedPullRequestLabelName, columns, room) { const prInfo = { owner: repo.owner.login, repo: repo.name, number: pullRequest.number } let state = null try { - state = await gitHubHelpers.getReviewApprovalState(github, robot, prInfo) + state = await gitHubHelpers.getReviewApprovalState(github, robot, prInfo, testedPullRequestLabelName) } catch (err) { robot.log.error(`${botName} - Couldn't calculate the PR approval state: ${err}`, prInfo) } diff --git a/bot_scripts/trigger-automation-test-build.js b/bot_scripts/trigger-automation-test-build.js index ac7d581..92e8779 100644 --- a/bot_scripts/trigger-automation-test-build.js +++ b/bot_scripts/trigger-automation-test-build.js @@ -106,7 +106,7 @@ async function processPullRequest (github, robot, prInfo, fullJobName) { pendingPullRequests.delete(prInfo.number) try { - const state = await gitHubHelpers.getReviewApprovalState(github, robot, prInfo) + const state = await gitHubHelpers.getReviewApprovalState(github, robot, prInfo, null) switch (state) { case 'unstable': diff --git a/lib/github-helpers.js b/lib/github-helpers.js index f5b7125..e1754e7 100644 --- a/lib/github-helpers.js +++ b/lib/github-helpers.js @@ -34,7 +34,7 @@ async function _getPullRequestReviewStates (github, prInfo) { return Array.from(finalReviewsMap.values()) } -async function _getReviewApprovalState (github, robot, prInfo) { +async function _getReviewApprovalState (github, robot, prInfo, testedPullRequestLabelName) { // Get detailed pull request const pullRequestPayload = await github.pullRequests.get(prInfo) const pullRequest = pullRequestPayload.data @@ -46,6 +46,11 @@ async function _getReviewApprovalState (github, robot, prInfo) { let state switch (pullRequest.mergeable_state) { case 'clean': + if (testedPullRequestLabelName !== null && pullRequest.labels.find(label => label.name === testedPullRequestLabelName)) { + robot.log.debug(`Pull request is labeled '${testedPullRequestLabelName}', ignoring`) + return null + } + state = 'approved' break case 'dirty':