#!/bin/bash commit=$(git rev-parse HEAD) pull_request_json=$(gh api \ -H "Accept: application/vnd.github.groot-preview+json" \ "repos/:owner/:repo/commits/$commit/pulls" \ | jq '.[0]') pull_request_url=$(echo "$pull_request_json" | jq -r '.html_url') owner_and_repo=$(echo "$pull_request_json" | jq -r '.base.repo.full_name') while true; do statuses_json=$(gh api "repos/$owner_and_repo/commits/$commit/status") statuses_failed=$(echo "$statuses_json" | jq '.state == "failure"') if [ "$statuses_failed" == "true" ]; then notify-send "GitHub CI pipeline failed" "$pull_request_url" exit 1 fi check_runs_json=$(gh api "repos/$owner_and_repo/commits/$commit/check-runs") check_runs_failed=$(echo "$check_runs_json" \ | jq '[.check_runs[]] | any (.status == "completed" and .conclusion != "success")') if [ "$check_runs_failed" == "true" ]; then notify-send "GitHub CI pipeline failed" "$pull_request_url" exit 1 fi statuses_succeeded=$(echo "$statuses_json" \ | jq '.state == "success" or .total_count == 0') check_runs_succeeded=$(echo "$check_runs_json" \ | jq '[.check_runs[]] | all (.status == "completed" and .conclusion == "success")') if [ "$check_runs_succeeded" == "true" ] && [ "$statuses_succeeded" == "true" ]; then notify-send "GitHub CI pipeline succeeded" "$pull_request_url" exit 0 fi sleep 5 done