Skip to content

Commit d36790b

Browse files
authored
add option for passing github token (#4)
1 parent a51c615 commit d36790b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: "Changed files detection"
22
description: "Find the added and modified files due to a github event"
3+
inputs:
4+
github-token:
5+
description: "Github access token."
6+
required: false
37
outputs:
48
files:
59
description: "Paths of all added or modified files"
@@ -16,4 +20,6 @@ runs:
1620
run: |
1721
set -x
1822
${{ github.action_path }}/find_changed_files.sh
23+
env:
24+
GITHUB_TOKEN: ${{ inputs.github-token }}
1925

find_changed_files.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ echo "compare: |$COMPARE|"
2222
echo "PR: |$PR|"
2323
echo "------"
2424

25+
if [[ -z "${GITHUB_TOKEN}" ]]; then
26+
TOKEN_HEADER=""
27+
else
28+
TOKEN_HEADER="Authorization: token $GITHUB_TOKEN"
29+
fi
30+
31+
FORMAT_HEADER="Accept: application/vnd.github.v3+json"
32+
2533
if [[ $COMPARE != null ]]
2634
then
2735
# compare might be a compare url or a commit url (single commit case)
@@ -37,14 +45,14 @@ then
3745
exit 1
3846
fi
3947
# TODO paginate to support more than 100 files
40-
COMPARE_RESPONSE=$(curl -H "Accept: application/vnd.github.v3+json" "$COMPARE_API?per_page=100")
48+
COMPARE_RESPONSE=$(curl -H $FORMAT_HEADER -H "$TOKEN_HEADER" "$COMPARE_API?per_page=100")
4149
FILES_JSON=$(echo $COMPARE_RESPONSE | jq -r '.files')
4250
elif [[ $PR != null ]]
4351
then
4452
#this is a PR, using its files API
4553
PR_FILES_API="$PR/files"
4654
# TODO paginate to support more than 100 files
47-
FILES_JSON=$(curl -H "Accept: application/vnd.github.v3+json" "$PR_FILES_API?per_page=100")
55+
FILES_JSON=$(curl -H $FORMAT_HEADER -H "$TOKEN_HEADER" "$PR_FILES_API?per_page=100")
4856
else
4957
echo "CANNOT FIND CHANGED FILES"
5058
exit 1

0 commit comments

Comments
 (0)