From ad3c560a4445351f0d098331167354c610b5f6e9 Mon Sep 17 00:00:00 2001 From: Claude Dioudonnat Date: Thu, 7 Sep 2023 19:43:54 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=82(cli)=20use=20github=20token=20to?= =?UTF-8?q?=20avoid=20rate=20limiting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Github has an API rate limiting. This rate limiting could Be increase if we are authenticated. If the environment variable GITHUB_TOKENiIs defined Arnold will use it to auth. --- CHANGELOG.md | 4 +++- bin/arnold | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec7d6adc..999d8307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,9 @@ Versioning](http://semver.org/spec/v2.0.0.html). ## Unreleased -### Changed +### Added + +- Use Gitlab token when call the Github's API ## [6.19.0] - 2023-09-01 diff --git a/bin/arnold b/bin/arnold index 9b2e18a6..b5d7c4aa 100755 --- a/bin/arnold +++ b/bin/arnold @@ -254,9 +254,14 @@ function _get_log_level_name() { # Get the latest Arnold release by querying Github's API function _get_latest_release() { + local auth_header=() + if [ -n "$GITHUB_TOKEN" ]; then + auth_header=(-H "Authorization: Bearer $GITHUB_TOKEN") + fi + if ! curl \ -s \ - -H "Accept: application/vnd.github.v3+json" \ + -H "Accept: application/vnd.github.v3+json" "${auth_header[@]}" \ "https://api.github.com/repos/openfun/arnold/releases?per_page=1" ; then log debug "Cannot get latest release from GitHub.com" fi