From 73b191b6e814d4844be6a8b4a1662f20f7f55093 Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Mon, 24 Sep 2018 15:24:19 +0200 Subject: [PATCH] manage-pr-checklist: Add more useful target URL to status --- bot_scripts/manage-pr-checklist.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/bot_scripts/manage-pr-checklist.js b/bot_scripts/manage-pr-checklist.js index 58a0dcb..21c4648 100644 --- a/bot_scripts/manage-pr-checklist.js +++ b/bot_scripts/manage-pr-checklist.js @@ -63,10 +63,16 @@ async function handlePullRequest (context, robot) { } try { + const {found, comment} = await getCheckListComment(context) + const targetUrl = 'https://github.com/status-im/status-github-bot.git' + if (found) { + targetUrl = comment.url + } + await context.github.repos.createStatus(context.repo({ sha: context.payload.pull_request.head.sha, state: newStatus, - target_url: 'https://github.com/status-im/status-github-bot.git', + target_url: targetUrl, description: isChecklistComplete ? 'ready for merge' : 'PR Checklist is incomplete', context: 'PRChecklist' })) @@ -101,7 +107,7 @@ async function createOrEditChecklist (context, checkList, header) { async function verifyChecklist (context, settings) { let isChecklistComplete = true let firstCheck = false - const {found, body} = await getCheckList(context) + const {found, body} = await getCheckListBody(context) if (found) { if (body) { for (const str of body) { @@ -122,16 +128,16 @@ async function verifyChecklist (context, settings) { return {isChecklistComplete, firstCheck} } -async function getCheckList (context) { +async function getCheckListComment (context) { try { const owner = context.payload.repository.owner.login const repo = context.payload.repository.name const number = context.payload.pull_request.number const comments = await context.github.paginate(context.github.issues.getComments({ owner, repo, number }), res => res.data) for (const comment of comments) { - const {found, body} = checkPRChecklist(comment.body) + const {found} = checkPRChecklist(comment.body) if (found) { - return {found, body} + return {found, comment} } } return false @@ -140,6 +146,17 @@ async function getCheckList (context) { } } +async function getCheckListBody (context) { + const {found, comment} = await getCheckListComment(context) + if (found) { + const {body} = checkPRChecklist(comment.body) + + return {found, body} + } + + return false +} + function checkPRChecklist (str) { let found = false let body = null