generated from actions/container-action
-
Notifications
You must be signed in to change notification settings - Fork 4
/
entrypoint.sh
executable file
·52 lines (41 loc) · 1.36 KB
/
entrypoint.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
45
46
47
48
49
50
51
52
#!/bin/bash
format_args=$1
bot_email=$2
bot_username=$3
message=$4
token=$5
if ! git status > /dev/null 2>&1
then
echo "In case of any errors, please consider having actions/checkout before this workflow step."
git init
fi
if [[ -z "$GITHUB_HEAD_REF" ]]; then
echo "Unknown source branch of the pull request."
exit 0
fi
set -o xtrace
PR_NUMBER=$(jq -r ".pull_request.number" "$GITHUB_EVENT_PATH")
URI=https://api.github.com
API_HEADER="Accept: application/vnd.github.v3+json"
# AUTH_HEADER="Authorization: token $token"
# pr_resp=$(curl -X GET -s -H "${API_HEADER}" -H "${AUTH_HEADER}" "${URI}/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER")
pr_resp=$(curl -X GET -s -H "${API_HEADER}" "${URI}/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER")
HEAD_REPO=$(echo "$pr_resp" | jq -r .head.repo.full_name)
HEAD_BRANCH=$(echo "$pr_resp" | jq -r .head.ref)
if [[ "$HEAD_REPO" == "null" ]]; then
echo "Unknown source repo"
exit 0
fi
if [[ "$HEAD_BRANCH" == "null" ]]; then
echo "Unknown source branch"
exit 0
fi
git remote add fork https://x-access-token:"$token"@github.com/"$HEAD_REPO".git
git fetch fork "$HEAD_BRANCH"
git checkout -b "$HEAD_BRANCH" fork/"$HEAD_BRANCH"
git config --global user.email "$bot_email"
git config --global user.name "$bot_username"
bash -c "black $format_args"
git add .
git commit -m "$message" || true
git push --force-with-lease fork "$HEAD_BRANCH"