Skip to content

Commit 4ebf70e

Browse files
authored
finding project is now paginated
close #55
1 parent 42352f3 commit 4ebf70e

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

entrypoint.sh

+26-14
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,50 @@ get_project_type() {
2828
unset _PROJECT_URL
2929
}
3030

31+
get_next_url_from_headers() {
32+
_HEADERS_FILE=$1
33+
grep -i '^link' "$_HEADERS_FILE" | tr ',' '\n'| grep \"next\" | sed 's/.*<\(.*\)>.*/\1/'
34+
}
35+
3136
find_project_id() {
3237
_PROJECT_TYPE="$1"
3338
_PROJECT_URL="$2"
3439

3540
case "$_PROJECT_TYPE" in
3641
org)
3742
_ORG_NAME=$(echo "$_PROJECT_URL" | sed -e 's@https://github.com/orgs/\([^/]\+\)/projects/[0-9]\+@\1@')
38-
_ENDPOINT="https://api.github.com/orgs/$_ORG_NAME/projects"
43+
_ENDPOINT="https://api.github.com/orgs/$_ORG_NAME/projects?per_page=100"
3944
;;
4045
user)
4146
_USER_NAME=$(echo "$_PROJECT_URL" | sed -e 's@https://github.com/users/\([^/]\+\)/projects/[0-9]\+@\1@')
42-
_ENDPOINT="https://api.github.com/users/$_USER_NAME/projects"
47+
_ENDPOINT="https://api.github.com/users/$_USER_NAME/projects?per_page=100"
4348
;;
4449
repo)
45-
_ENDPOINT="https://api.github.com/repos/$GITHUB_REPOSITORY/projects"
50+
_ENDPOINT="https://api.github.com/repos/$GITHUB_REPOSITORY/projects?per_page=100"
4651
;;
4752
esac
53+
54+
_NEXT_URL="$_ENDPOINT"
4855

49-
_PROJECTS=$(curl -s -X GET -u "$GITHUB_ACTOR:$TOKEN" --retry 3 \
50-
-H 'Accept: application/vnd.github.inertia-preview+json' \
51-
"$_ENDPOINT")
56+
while : ; do
5257

53-
_PROJECTID=$(echo "$_PROJECTS" | jq -r ".[] | select(.html_url == \"$_PROJECT_URL\").id")
58+
_PROJECTS=$(curl -s -X GET -u "$GITHUB_ACTOR:$TOKEN" --retry 3 \
59+
-H 'Accept: application/vnd.github.inertia-preview+json' \
60+
-D /tmp/headers \
61+
"$_NEXT_URL")
5462

55-
if [ "$_PROJECTID" != "" ]; then
56-
echo "$_PROJECTID"
57-
else
58-
echo "No project was found." >&2
59-
exit 1
60-
fi
63+
_PROJECTID=$(echo "$_PROJECTS" | jq -r ".[] | select(.html_url == \"$_PROJECT_URL\").id")
64+
_NEXT_URL=$(get_next_url_from_headers '/tmp/headers')
65+
66+
if [ "$_PROJECTID" != "" ]; then
67+
echo "$_PROJECTID"
68+
elif [ "$_NEXT_URL" == "" ]; then
69+
echo "No project was found." >&2
70+
exit 1
71+
fi
72+
done
6173

62-
unset _PROJECT_TYPE _PROJECT_URL _ORG_NAME _USER_NAME _ENDPOINT _PROJECTS _PROJECTID
74+
unset _PROJECT_TYPE _PROJECT_URL _ORG_NAME _USER_NAME _ENDPOINT _PROJECTS _PROJECTID _NEXT_URL
6375
}
6476

6577
find_column_id() {

0 commit comments

Comments
 (0)