trigger-automation-test-build: only look for Android e2e build result

This commit is contained in:
Pedro Pombeiro 2019-01-10 13:57:39 +01:00
parent ca49877d5d
commit 113578ad1a
No known key found for this signature in database
GPG Key ID: A65DEB11E4BBC647
4 changed files with 66 additions and 50 deletions

View File

@ -66,9 +66,9 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) {
return return
} }
const bountyLabelName = projectBoardConfig['bounty-label-name'] // const bountyLabelName = projectBoardConfig['bounty-label-name']
const isOfficialBounty = !!payload.issue.labels.find(l => l.name === bountyLabelName) // const isOfficialBounty = !!payload.issue.labels.find(l => l.name === bountyLabelName)
const bountySize = getBountySize(payload.issue.labels, projectBoardConfig) // const bountySize = getBountySize(payload.issue.labels, projectBoardConfig)
if (process.env.DRY_RUN) { if (process.env.DRY_RUN) {
if (assign) { if (assign) {
@ -119,33 +119,33 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) {
// } // }
} }
function getSlackMessage (projectBoardName, approvalColumnName, payload, assign, isOfficialBounty, bountySize) { // function getSlackMessage (projectBoardName, approvalColumnName, payload, assign, isOfficialBounty, bountySize) {
if (assign) { // if (assign) {
return `Assigned issue to ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}` // return `Assigned issue to ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}`
} // }
if (!isOfficialBounty) { // if (!isOfficialBounty) {
return `Unassigned issue from ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}` // return `Unassigned issue from ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}`
} // }
if (bountySize) { // 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 (size: ${bountySize})!`
} // }
return `${payload.issue.html_url} has been approved as an official bounty!` // return `${payload.issue.html_url} has been approved as an official bounty!`
} // }
function getBountySize (labels, projectBoardConfig) { // function getBountySize (labels, projectBoardConfig) {
const regexString = projectBoardConfig['bounty-size-label-name-regex'] // const regexString = projectBoardConfig['bounty-size-label-name-regex']
if (!regexString) { // if (!regexString) {
return null // 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) // const match = labels.map(l => bountySizeLabelRegex.exec(l.name)).find(m => m != null)
if (match) { // if (match) {
return match[1] // return match[1]
} // }
return null // return null
} // }

View File

@ -13,6 +13,7 @@
const fetch = require('node-fetch') const fetch = require('node-fetch')
const getConfig = require('probot-config') const getConfig = require('probot-config')
const defaultConfig = require('../lib/config') const defaultConfig = require('../lib/config')
const gitHubHelpers = require('../lib/github-helpers')
const botName = 'manage-pr-checklist' const botName = 'manage-pr-checklist'
module.exports = (robot) => { module.exports = (robot) => {
@ -50,7 +51,7 @@ async function handlePullRequest (context, robot) {
} }
if (settings.title == null) settings.title = '' if (settings.title == null) settings.title = ''
if (settings.checklist == null) settings.checklist = {} 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 { isChecklistComplete, firstCheck } = await verifyChecklist(context, settings)
const newStatus = isChecklistComplete ? 'success' : 'pending' const newStatus = isChecklistComplete ? 'success' : 'pending'
const hasChange = firstCheck || currentStatus !== newStatus 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) { async function createOrEditChecklist (context, checkList, header) {
const owner = context.payload.repository.owner.login const owner = context.payload.repository.owner.login
const repo = context.payload.repository.name const repo = context.payload.repository.name

View File

@ -98,31 +98,41 @@ async function processChangedProjectCard (robot, context) {
const prNumber = last(payload.project_card.content_url.split('/'), -1) const prNumber = last(payload.project_card.content_url.split('/'), -1)
const fullJobName = automatedTestsConfig['job-full-name'] 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 // Remove the PR from the pending PR list, if it is there
pendingPullRequests.delete(prInfo.number) pendingPullRequests.delete(prInfo.number)
try { 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) { const statusContext = 'jenkins/prs/android-e2e'
case 'unstable': const currentStatus = await gitHubHelpers.getPullRequestCurrentStatusForContext(context, statusContext, pullRequest)
case 'awaiting_reviewers':
case 'changes_requested': switch (currentStatus) {
case 'pending':
pendingPullRequests.set(prInfo.number, { github: github, prInfo, fullJobName: fullJobName }) 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 return
case 'failed': case 'error':
robot.log.debug(`${botName} - State is '${state}', exiting`, prInfo) case 'failure':
robot.log.debug(`${botName} - Status for ${statusContext} is '${currentStatus}', exiting`, prInfo)
return return
case 'approved': case 'success':
robot.log.debug(`${botName} - State is '${state}', proceeding`, prInfo) robot.log.debug(`${botName} - Status for ${statusContext} is '${currentStatus}', proceeding`, prInfo)
break break
default: default:
robot.log.warn(`${botName} - State is '${state}', ignoring`, prInfo) robot.log.warn(`${botName} - Status for ${statusContext} is '${currentStatus}', ignoring`, prInfo)
return return
} }
} catch (err) { } catch (err) {

View File

@ -13,7 +13,8 @@ module.exports = {
getProjectCardForIssue: _getProjectCardForIssue, getProjectCardForIssue: _getProjectCardForIssue,
getOrgProjectByName: _getOrgProjectByName, getOrgProjectByName: _getOrgProjectByName,
getRepoProjectByName: _getRepoProjectByName, getRepoProjectByName: _getRepoProjectByName,
getProjectColumnByName: _getProjectColumnByName getProjectColumnByName: _getProjectColumnByName,
getPullRequestCurrentStatusForContext: _getPullRequestCurrentStatusForContext
} }
async function _getPullRequestReviewStates (github, prInfo) { async function _getPullRequestReviewStates (github, prInfo) {
@ -166,3 +167,15 @@ async function _getProjectColumnByName (github, robot, project, columnName, botN
return null 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
}