-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathcreate-a-commit.sh
executable file
·32 lines (25 loc) · 1.19 KB
/
create-a-commit.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
. ./.gh-api-examples.conf
# https://docs.github.com/en/rest/reference/git#create-a-commit
# POST /repos/:owner/:repo/git/commits
if [ -z "$1" ]
then
tree_sha=$tree_sha
else
tree_sha=$1
fi
json_file=tmp/create-commit.json
rm -f ${json_file}
last_commit_sha=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${base_branch} | jq -r '.commit.sha')
jq -n \
--arg name "${default_committer}" \
--arg message "test commit message ${RANDOM}" \
--arg email "${USER}+${default_committer}@${mail_domain}" \
--arg date "$(date +%Y-%m-%dT%H:%M:%SZ)" \
--arg tree_sha "${tree_sha}" \
--arg last_commit_sha "${last_commit_sha}" \
'{message: $message, "author":{ "name" : $name, "email": $email , "date": $date}, "parents": [ $last_commit_sha ], "tree": $tree_sha }' > ${json_file}
curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/commits --data @${json_file}
rm -f ${json_file}