Skip to content

Commit 2d0e67a

Browse files
Merge pull request #3223 from balena-io/vipulgupta2048/add-errors
patch: Add errors for rate limited URLs
2 parents e4122dd + f159160 commit 2d0e67a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

tools/fetch-external.sh

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,29 @@ curl --fail --show-error -o pages/learn/more/masterclasses/docker-masterclass.md
7676
cd shared/projects/ && {
7777
echo "Name|Description
7878
---|---" | tee balena-labs-projects.md balena-example-projects.md >/dev/null
79-
curl --fail --show-error https://api.github.com/orgs/balena-labs-projects/repos?per_page=30 | $JQ -r 'sort_by(-.stargazers_count) | (.[] | [.name,.html_url,.description] | "[\(.[0])](\(.[1]))|\(.[2] // "")") ' >>balena-labs-projects.md
80-
curl --fail --show-error https://api.github.com/orgs/balena-io-examples/repos?per_page=100 | $JQ -r 'sort_by(-.stargazers_count) | (.[] | [.name,.html_url,.description] | "[\(.[0])](\(.[1]))|\(.[2] // "")") ' >>balena-example-projects.md
79+
80+
# Set up authentication headers if GITHUB_TOKEN is available
81+
if [ -n "${GITHUB_TOKEN:-}" ]; then
82+
AUTH_HEADER="Authorization: token $GITHUB_TOKEN"
83+
else
84+
AUTH_HEADER=""
85+
echo "Warning: GITHUB_TOKEN not set. GitHub API calls may be rate limited."
86+
fi
87+
88+
# Fetch balena-labs-projects with error handling
89+
if [ -n "$AUTH_HEADER" ]; then
90+
curl --fail --show-error -H "$AUTH_HEADER" https://api.github.com/orgs/balena-labs-projects/repos?per_page=30 | $JQ -r 'sort_by(-.stargazers_count) | (.[] | [.name,.html_url,.description] | "[\(.[0])](\(.[1]))|\(.[2] // "")") ' >>balena-labs-projects.md || echo "Failed to fetch balena-labs-projects" >&2
91+
else
92+
curl --fail --show-error https://api.github.com/orgs/balena-labs-projects/repos?per_page=30 | $JQ -r 'sort_by(-.stargazers_count) | (.[] | [.name,.html_url,.description] | "[\(.[0])](\(.[1]))|\(.[2] // "")") ' >>balena-labs-projects.md || echo "Failed to fetch balena-labs-projects (rate limited)" >&2
93+
fi
94+
95+
# Fetch balena-io-examples with error handling
96+
if [ -n "$AUTH_HEADER" ]; then
97+
curl --fail --show-error -H "$AUTH_HEADER" https://api.github.com/orgs/balena-io-examples/repos?per_page=100 | $JQ -r 'sort_by(-.stargazers_count) | (.[] | [.name,.html_url,.description] | "[\(.[0])](\(.[1]))|\(.[2] // "")") ' >>balena-example-projects.md || echo "Failed to fetch balena-io-examples" >&2
98+
else
99+
curl --fail --show-error https://api.github.com/orgs/balena-io-examples/repos?per_page=100 | $JQ -r 'sort_by(-.stargazers_count) | (.[] | [.name,.html_url,.description] | "[\(.[0])](\(.[1]))|\(.[2] // "")") ' >>balena-example-projects.md || echo "Failed to fetch balena-io-examples (rate limited)" >&2
100+
fi
101+
81102
cd -
82103
} &
83104

0 commit comments

Comments
 (0)