From 374f036b790e11caf735bbad9d182a8f6d5cb840 Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.uk>
Date: Wed, 11 Nov 2020 07:18:05 +0000
Subject: [PATCH] git: Refactor to be based on the gh CLI tool

---
 bin/git-close-pull-request | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/bin/git-close-pull-request b/bin/git-close-pull-request
index ad06ed06..67f3673d 100755
--- a/bin/git-close-pull-request
+++ b/bin/git-close-pull-request
@@ -22,10 +22,6 @@ class ClosesPullRequests
     private $localBranch;
     private $remoteBranch;
 
-    private const CI_ERROR = 'error';
-    private const CI_PENDING = 'pending';
-    private const CI_SUCCESS = 'success';
-
     private const RUN_TYPE_COMMAND = 'command';
     private const RUN_TYPE_QUERY = 'query';
 
@@ -89,20 +85,11 @@ class ClosesPullRequests
 
         echo 'Confirming ci-status on PR is green...' . PHP_EOL;
 
-        // TODO: Check for failures, or skip if there is no CI.
-        $errors = [
-            self::CI_ERROR => 'Aborting: CI error',
-            self::CI_PENDING => 'Aborting: CI pending',
-        ];
+        $passedCi = $this->run('gh pr checks', self::RUN_TYPE_COMMAND);
 
-        $ciStatus = $this->run('hub ci-status', self::RUN_TYPE_QUERY);
-
-        switch ($ciStatus) {
-            case self::CI_PENDING:
-                $this->exitWithWarning($errors[$ciStatus]);
-
-            case self::CI_ERROR:
-                $this->dieWithMessage($errors[$ciStatus]);
+        // TODO: Check if there are no CI checks. Does this return `true` as well?
+        if (!$passedCi) {
+            $this->dieWithMessage('CI pending or failed.');
         }
     }