diff --git a/bin/git-close-pull-request b/bin/git-close-pull-request index f5011f3..54dbaee 100755 --- a/bin/git-close-pull-request +++ b/bin/git-close-pull-request @@ -20,6 +20,9 @@ class ClosesPullRequests private $localBranch; private $remoteBranch; + private const CI_PENDING = 'pending'; + private const CI_SUCCESS = 'success'; + public function __construct() { $this->localBranch = exec('git rev-parse --abbrev-ref HEAD'); @@ -28,6 +31,18 @@ class ClosesPullRequests $this->remoteBranch = str_replace('origin/', '', $this->remoteBranch); } + function confirmCiStatusIsPassing(): void + { + echo 'Confirming ci-status on PR is green...' . PHP_EOL; + + // TODO: Check for failures, or skip if there is no CI. + switch (exec('hub ci-status')) { + case self::CI_PENDING: + die('CI pending'); + break; + } + } + function fetchOrigin(): void { print 'Fetching origin to confirm local and remote in sync...' @@ -72,7 +87,7 @@ class ClosesPullRequests public function __invoke(): void { - // TODO: Check the CI status of the branch. Don't merge if it's failing. + $this->confirmCiStatusIsPassing(); // TODO: Check that the current branch has a tracking branch. $this->fetchOrigin(); // TODO: Ensure both branches are up to date.