From a19582caef7a391d9a2e751887987b2caa8de8d2 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sat, 4 Nov 2017 11:58:04 -0400 Subject: [PATCH] poster: send a Comment in place of an Approve if the PR is closed already --- poster.php | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/poster.php b/poster.php index 1ca252d..ee9e8b3 100644 --- a/poster.php +++ b/poster.php @@ -30,21 +30,38 @@ function runner($msg) { } function reply_to_issue($issue, $output, $success, $system) { + $num = $issue->issue->number; + $owner = $issue->repository->owner->login; + $repo = $issue->repository->name; + $event = $success ? 'APPROVE' : 'COMMENT'; + $passfail = $success ? "Success" : "Failure"; + + echo "Sending $event to $owner/$repo#$num with " . $passfail . " on $system\n"; + $client = gh_client(); $pr = $client->api('pull_request')->show( - $issue->repository->owner->login, - $issue->repository->name, - $issue->issue->number + $owner, + $repo, + $num ); + + if ($pr['state'] == 'closed') { + $event = 'COMMENT'; + } + $sha = $pr['head']['sha']; + echo "Latest sha: $sha\n"; + echo "Body:\n"; + echo $output; + echo "\n\n"; $client->api('pull_request')->reviews()->create( - $issue->repository->owner->login, - $issue->repository->name, - $issue->issue->number, + $owner, + $repo, + $num, array( - 'body' => "For system: $system\n\n```\n$output\n```", - 'event' => $success ? 'APPROVE' : 'COMMENT', + 'body' => "$passfail for system: $system\n\n```\n$output\n```", + 'event' => $event, 'commit_id' => $sha, )); } @@ -53,7 +70,7 @@ function reply_to_issue($issue, $output, $success, $system) { function outrunner($msg) { try { return runner($msg); - } catch (ExecException $e) { + } catch (GHE\ExecException $e) { var_dump($e->getMessage()); var_dump($e->getCode()); var_dump($e->getOutput());