This repository has been archived by the owner on Jul 4, 2024. It is now read-only.
forked from kbrashears5/github-action-auto-accept-collabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
59 lines (44 loc) · 1.42 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
53
54
55
56
57
58
59
#!/bin/bash
STATUS=0
# remember last error code
trap 'STATUS=$?' ERR
# problem matcher must exist in workspace
cp /error-matcher.json $HOME/accept-collabs-error-matcher.json
echo "::add-matcher::$HOME/accept-collabs-error-matcher.json"
echo "Repository: [$GITHUB_REPOSITORY]"
# log inputs
echo "Inputs"
echo "---------------------------------------------"
GITHUB_TOKEN="$INPUT_TOKEN"
# set temp path
TEMP_PATH="/ghaaac/"
cd /
mkdir "$TEMP_PATH"
cd "$TEMP_PATH"
echo "Temp Path : $TEMP_PATH"
echo "---------------------------------------------"
echo " "
# find username and repo name
REPO_INFO=($(echo $GITHUB_REPOSITORY | tr "/" "\n"))
USERNAME=${REPO_INFO[0]}
echo "Username: [$USERNAME]"
echo " "
# get all invites
echo "Getting all repository invites for [${USERNAME}]"
INVITES_STRING=$(curl -X GET -H "Accept: application/vnd.github.v3+json" -u ${USERNAME}:${GITHUB_TOKEN} --silent ${GITHUB_API_URL}/user/repository_invitations | jq '.[].id')
readarray -t INVITES <<< "$INVITES_STRING"
# loop through all the invites
for invite in "${INVITES[@]}"; do
echo "::group::$invite"
# trim the quotes
invite="${invite//\"}"
echo "Accepting invite id: [$invite]"
curl -d @- \
-X PATCH \
-H "Accept: application/vnd.github.v3+json" \
-u ${USERNAME}:${GITHUB_TOKEN} \
--silent \
${GITHUB_API_URL}/user/repository_invitations/${invite}
echo "::endgroup::"
done
exit $STATUS