-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[update.sh] Parsing token inside each upstream #16289
Changes from 24 commits
c9f6f14
fc9b64a
9102492
195a57b
d1c2d5f
f4c25a1
234d054
06e79a2
e7c1575
29ba761
079e8a0
16fb088
2f3af88
ed1c0fd
bced796
8d363a1
3642082
9c887df
5b3ce14
4a7018b
f2e9b54
b21bfb1
226133c
1d7191b
7b5cc6a
618a94f
5908569
816f785
10dfd3c
4b8a187
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -511,15 +511,6 @@ EOS | |||||||||
CURL_DISABLE_CURLRC_ARGS=() | ||||||||||
fi | ||||||||||
|
||||||||||
# HOMEBREW_GITHUB_API_TOKEN is optionally defined in the user environment. | ||||||||||
# shellcheck disable=SC2153 | ||||||||||
if [[ -n "${HOMEBREW_GITHUB_API_TOKEN}" ]] | ||||||||||
then | ||||||||||
CURL_GITHUB_API_ARGS=("--header" "Authorization: token ${HOMEBREW_GITHUB_API_TOKEN}") | ||||||||||
else | ||||||||||
CURL_GITHUB_API_ARGS=() | ||||||||||
fi | ||||||||||
|
||||||||||
# only allow one instance of brew update | ||||||||||
lock update | ||||||||||
|
||||||||||
|
@@ -637,13 +628,35 @@ EOS | |||||||||
# the refspec ensures that the default upstream branch gets updated | ||||||||||
( | ||||||||||
UPSTREAM_REPOSITORY_URL="$(git config remote.origin.url)" | ||||||||||
unset UPSTREAM_REPOSITORY | ||||||||||
unset UPSTREAM_REPOSITORY_TOKEN | ||||||||||
|
||||||||||
# HOMEBREW_UPDATE_FORCE and HOMEBREW_UPDATE_AUTO aren't modified here so ignore subshell warning. | ||||||||||
# shellcheck disable=SC2030 | ||||||||||
if [[ "${UPSTREAM_REPOSITORY_URL}" == "https://github.com/"* ]] | ||||||||||
then | ||||||||||
UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY_URL#https://github.com/}" | ||||||||||
UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY%.git}" | ||||||||||
elif [[ "${UPSTREAM_REPOSITORY_URL}" =~ https://(([^:@]+)(:([^@]+))?@)?github.com/(.*)$ ]] | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is Group 1 itself even necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed it seems we can remove that grouping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you all for your feedbacks and suggestions! Indeed, based on https://en.wikipedia.org/wiki/URL#Syntax, what about to rewrite the parsing in the and then to look inside how it is formatted ( From my experiences, the GIT API Key looks to match There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think this is what we want to do here based on discussion with @MikeMcQuaid. |
||||||||||
then | ||||||||||
UPSTREAM_REPOSITORY="${BASH_REMATCH[5]%.git}" | ||||||||||
UPSTREAM_REPOSITORY_TOKEN="${BASH_REMATCH[4]:-${BASH_REMATCH[2]}}" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments explaining which parts of the regex we're looking for here would be good too. |
||||||||||
fi | ||||||||||
|
||||||||||
if [[ -n "${UPSTREAM_REPOSITORY}" ]] | ||||||||||
then | ||||||||||
# UPSTREAM_REPOSITORY_TOKEN is parsed (if exists) from UPSTREAM_REPOSITORY_URL | ||||||||||
# HOMEBREW_GITHUB_API_TOKEN is optionally defined in the user environment. | ||||||||||
# shellcheck disable=SC2153 | ||||||||||
if [[ -n "${UPSTREAM_REPOSITORY_TOKEN}" ]] | ||||||||||
then | ||||||||||
CURL_GITHUB_API_ARGS=("--header" "Authorization: token ${UPSTREAM_REPOSITORY_TOKEN}") | ||||||||||
elif [[ -n "${HOMEBREW_GITHUB_API_TOKEN}" ]] | ||||||||||
then | ||||||||||
CURL_GITHUB_API_ARGS=("--header" "Authorization: token ${HOMEBREW_GITHUB_API_TOKEN}") | ||||||||||
else | ||||||||||
CURL_GITHUB_API_ARGS=() | ||||||||||
fi | ||||||||||
|
||||||||||
if [[ "${DIR}" == "${HOMEBREW_REPOSITORY}" && -n "${HOMEBREW_UPDATE_TO_TAG}" ]] | ||||||||||
then | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to leave a comment explaining the format we're trying to match here exactly.