Open
Description
Hi, @srggrs
I can reproduce the problem with following script, the get_next_utl_from_headers
would result in an empty string:
get_next_url_from_headers() {
_HEADERS_FILE=$1
grep -i '^link' "$_HEADERS_FILE" | tr ',' '\n'| grep \"next\" | sed 's/.*<\(.*\)>.*/\1/'
}
find_project_id() {
_PROJECT_TYPE="$1"
_PROJECT_URL="$2"
case "$_PROJECT_TYPE" in
org)
_ORG_NAME=$(echo "$_PROJECT_URL" | sed -e 's@https://github.com/orgs/\([^/]\+\)/projects/[0-9]\+@\1@')
_ENDPOINT="https://api.github.com/orgs/$_ORG_NAME/projects?per_page=100"
;;
user)
_USER_NAME=$(echo "$_PROJECT_URL" | sed -e 's@https://github.com/users/\([^/]\+\)/projects/[0-9]\+@\1@')
_ENDPOINT="https://api.github.com/users/$_USER_NAME/projects?per_page=100"
;;
repo)
_ENDPOINT="https://api.github.com/repos/$GITHUB_REPOSITORY/projects?per_page=100"
;;
esac
_NEXT_URL="$_ENDPOINT"
while : ; do
_PROJECTS=$(curl -s -X GET -u "$GITHUB_ACTOR:$TOKEN" --retry 3 \
-H 'Accept: application/vnd.github.inertia-preview+json' \
-D /tmp/headers \
"$_NEXT_URL")
_PROJECTID=$(echo "$_PROJECTS" | jq -r ".[] | select(.html_url == \"$_PROJECT_URL\").id")
_NEXT_URL=$(get_next_url_from_headers '/tmp/headers')
if [ "$_PROJECTID" != "" ]; then
echo "$_PROJECTID"
elif [ "$_NEXT_URL" == "" ]; then
echo "No project was found." >&2
exit 1
fi
done
unset _PROJECT_TYPE _PROJECT_URL _ORG_NAME _USER_NAME _ENDPOINT _PROJECTS _PROJECTID _NEXT_URL
}
find_project_id "org" "https://github.com/orgs/openresty/projects/1"
the content of /tmp/headers
is:
HTTP/2 200
server: GitHub.com
date: Mon, 25 Oct 2021 07:00:23 GMT
content-type: application/json; charset=utf-8
content-length: 1646
cache-control: public, max-age=60, s-maxage=60
vary: Accept
etag: "75aa4315bf12c4814a229ad32207937de51f039b41eb2ab7746085551dfd67f2"
x-github-media-type: github.v3; param=inertia-preview; format=json
x-ratelimit-limit: 60
x-ratelimit-remaining: 56
x-ratelimit-reset: 1635148646
x-ratelimit-used: 4
x-ratelimit-resource: core
access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
access-control-allow-origin: *
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'
vary: Accept-Encoding, Accept, X-Requested-With
x-github-request-id: 592C:28A4:56BB0D:676DB9:61765607
Activity