-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathcreate-commit-status.sh
executable file
·44 lines (33 loc) · 1.37 KB
/
create-commit-status.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
. ./.gh-api-examples.conf
# https://docs.github.com/en/enterprise-cloud@latest/rest/commits/statuses?apiVersion=2022-11-28#create-a-commit-status
# POST /repos/{owner}/{repo}/statuses/{sha}
# The state of the status.
# Can be one of: error, failure, pending, success
# If there is no first argument use a default value of "pending"
if [ -z "$1" ]
then
state="pending"
else
state=$1
fi
if [ -z "$2" ]
then
status_context="ci/pwr-commit-status-required"
else
status_context=$2
fi
target_branch=${branch_name}
timestamp=$(date +%s)
sha=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs/heads/${target_branch}| jq -r '.object.sha')
json_file=tmp/create-commit-status.json
jq -n \
--arg state "${state}" \
--arg target_url "https://example.com/build/status" \
--arg description "The build status was: $status This is completely fake. The status ran at: ${timestamp}" \
--arg context "${status_context}" \
'{ state : $state , target_url : $target_url, description: $description, context: $context }' > ${json_file}
json_string=$(cat $json_file | jq )
curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/statuses/${sha} --data "${json_string}"