Skip to content

Commit

Permalink
Merge pull request #221 from gm3dmo/issue220
Browse files Browse the repository at this point in the history
Adding scripts to summarize check suite/run to csv close #220
  • Loading branch information
gm3dmo authored Dec 14, 2024
2 parents dd10701 + 25ba65b commit eb93a59
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 18 deletions.
34 changes: 34 additions & 0 deletions list-check-runs-for-a-git-reference-csv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference
# GET /repos/{owner}/{repo}/commits/{ref}/check-runs

branch_for_ref=${branch_name}

# If the script is passed an argument $1 use that as the name
if [ -z "$1" ]
then
ref=${branch_for_ref}
else
ref=$1
fi

response_file=tmp/list-check-runs-for-a-git-reference.json

curl ${curl_custom_flags} \
-H "X-GitHub-Api-Version: ${github_api_version}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/commits/${ref}/check-runs" > ${response_file}

jq -r '
["Cnt","Check Suite ID","Check Run ID","Name","Head SHA","App Name"],
( .check_runs | to_entries[] |
[ ( .key | tonumber + 1 | tostring ),
( .value.check_suite.id | tostring ),
( .value.id | tostring ),
.value.name,
.value.head_sha,
.value.app.name ] )
| @csv' ${response_file} | csvlook --no-inference

10 changes: 3 additions & 7 deletions list-check-runs-for-a-git-reference.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference
# https://docs.github.com/en/enterprise-cloud@latest/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference
# GET /repos/{owner}/{repo}/commits/{ref}/check-runs

branch_for_ref=${branch_name}

# If the script is passed an argument $1 use that as the name
if [ -z "$1" ]
then
ref=${branch_for_ref}
ref=${branch_name}
else
ref=$1
fi


curl ${curl_custom_flags} \
-H "X-GitHub-Api-Version: ${github_api_version}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/commits/${ref}/check-runs"


# use the jq below to get just the id out:
# | jq -r '.check_runs | last | .id'
33 changes: 33 additions & 0 deletions list-check-suites-for-a-git-reference-csv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/checks/suites?apiVersion=2022-11-28#list-check-suites-for-a-git-reference
# GET /repos/{owner}/{repo}/commits/{ref}/check-suites


if [ -z "$1" ]
then
ref=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs/heads/${branch_name}| jq -r '.object.sha')
else
ref=$1
fi

response_file=tmp/list-check-suites-for-a-git-reference.json

curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/commits/${ref}/check-suites" > ${response_file}

jq -r '
["Cnt","ID","Head Branch","Head SHA","Status","PR","App Name","Created At","Updated At"],
( .check_suites | to_entries[] |
[ ( .key | tonumber + 1 | tostring ),
( .value.id | tostring ),
.value.head_branch,
.value.head_sha,
.value.status,
( .value.pull_requests | map(.number | tostring) | join(";") ),
.value.app.name,
.value.created_at,
.value.updated_at ] )
| @csv' tmp/response.json | csvlook --no-inference
14 changes: 10 additions & 4 deletions list-check-suites-for-a-git-reference.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/checks/suites#list-check-suites-for-a-git-reference
# https://docs.github.com/en/enterprise-cloud@latest/rest/checks/suites?apiVersion=2022-11-28#list-check-suites-for-a-git-reference
# GET /repos/{owner}/{repo}/commits/{ref}/check-suites

ref=$1

if [ -z "$1" ]
then
ref=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs/heads/${branch_name}| jq -r '.object.sha')
else
ref=$1
fi


curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/commits/${ref}/check-suites

"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/commits/${ref}/check-suites"

11 changes: 5 additions & 6 deletions tiny-create-a-check-suite.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/checks/suites#create-a-check-suite
# https://docs.github.com/en/enterprise-cloud@latest/rest/checks/suites?apiVersion=2022-11-28#create-a-check-suite
# POST /repos/{owner}/{repo}/check-suites
#
# This script probably needs to run also:
# update-repository-preferences-for-check-suites.sh

# If the script is passed an argument $1 use that as the name

if [ -z "$1" ]
then
head_sha=$head_sha
head_sha=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs/heads/${branch_name}| jq -r '.object.sha')
else
head_sha=$1
fi

json_file=tmp/create-a-check-suite.json

json_file=tmp/create-a-check-suite.json
jq -n \
--arg head_sha "${head_sha}" \
'{
Expand All @@ -32,6 +32,5 @@ set -x
curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/check-suites --data @${json_file}

"${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/check-suites" --data @${json_file}

3 changes: 2 additions & 1 deletion tiny-create-check-run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/reference/checks#create-a-check-run
# https://docs.github.com/en/enterprise-cloud@latest/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run
# POST /repos/{owner}/{repo}/check-runs


Expand Down Expand Up @@ -36,3 +36,4 @@ curl ${curl_custom_flags} \
-H "Authorization: Bearer ${GITHUB_APP_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/check-runs" --data @${json_file}

0 comments on commit eb93a59

Please sign in to comment.