-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Make auto updates rate-limit aware #22994
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Takes in a list of GraphQL query snippets | ||
| termux_github_graphql() { | ||
| local -a GITHUB_GRAPHQL_QUERIES=( "$@" ) | ||
|
|
||
| # Batch size for fetching tags, 100 seems to work consistently. | ||
| local BATCH BATCH_SIZE=100 | ||
| for (( BATCH = 0; ${#GITHUB_GRAPHQL_QUERIES[@]} >= BATCH_SIZE * BATCH ; BATCH++ )); do | ||
|
|
||
| echo "Starting batch $BATCH at: ${GITHUB_GRAPHQL_QUERIES[$BATCH * $BATCH_SIZE]//\\/}" >&2 | ||
|
|
||
| # JSON strings cannot contain tabs or newlines | ||
| # so shutup shellcheck complaining about escapes in single quotes | ||
| local QUERY | ||
|
|
||
| # Start the GraphQL query with our two fragments for getting the latest tag from a release, and from refs/tags | ||
| # These are defined only if needed, so this one is for '_latest_release_tag' | ||
| grep -q '_latest_release_tag' <<< "${GITHUB_GRAPHQL_QUERIES[@]:$BATCH * $BATCH_SIZE:$BATCH_SIZE}" && { | ||
| QUERY+="$(printf '%s\n' \ | ||
| 'fragment _latest_release_tag on Repository {' \ | ||
| ' latestRelease { tagName }' \ | ||
| '}')" | ||
| } | ||
|
|
||
| grep -q '_newest_tag' <<< "${GITHUB_GRAPHQL_QUERIES[@]:$BATCH * $BATCH_SIZE:$BATCH_SIZE}" && { | ||
| QUERY+="$(printf '%s\n' \ | ||
| 'fragment _newest_tag on Repository {' \ | ||
| ' refs( refPrefix: \"refs/tags/\" first: 1 orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {' \ | ||
| ' nodes { name }' \ | ||
| ' }' \ | ||
| '}')" | ||
| } | ||
|
|
||
| QUERY+='query {' | ||
|
|
||
| # Fill out the query body with the package repos we need to query for updates | ||
| # Lastly fetch the rate limit utilization | ||
| printf -v QUERY '%s\n' \ | ||
| "${QUERY}" \ | ||
| "${GITHUB_GRAPHQL_QUERIES[@]:$BATCH * $BATCH_SIZE:$BATCH_SIZE}" \ | ||
| 'ratelimit: rateLimit { cost limit remaining used resetAt }' \ | ||
| '}' \ | ||
|
|
||
| # echo "// Batch: $BATCH" >> /tmp/query-12345 # Uncomment for debugging GraphQL queries | ||
| # printf '%s' "${QUERY}" >> /tmp/query-12345 # Uncomment for debugging GraphQL queries | ||
|
|
||
| local response | ||
| response="$(printf '{ "query": "%s" }' "${QUERY//$'\n'/ }" | curl -fL \ | ||
| --no-progress-meter \ | ||
| -H "Authorization: token ${GITHUB_TOKEN}" \ | ||
| -H 'Accept: application/vnd.github.v3+json' \ | ||
| -H 'Content-Type: application/json' \ | ||
| -X POST \ | ||
| --data @- \ | ||
| https://api.github.com/graphql 2>&1 | ||
| )" || termux_error_exit "ERR - termux_github_graphql: $response" | ||
|
|
||
|
|
||
| unset QUERY | ||
| local TAGS idx i=0 | ||
| TAGS="$(jq -r '.data # From the data: table | ||
| | del(.ratelimit) # Remove the ratelimit: table | ||
| | to_entries[] # convert the remaining entries to an array | ||
| | .value # For each .value | ||
| | (.latestRelease?.tagName # Print out the tag name of the latest release | ||
| // .refs.nodes[]?.name # or of the latest tag | ||
| // null)' <<< "$response")" # If neither exists return null | ||
|
|
||
| while IFS=$'\n' read -r idx; do | ||
| printf 'PKG|%s|%s\n' \ | ||
| "${__GITHUB_PACKAGES[$BATCH * $BATCH_SIZE + $(( i++ ))]##*/}" \ | ||
| "${idx}" | ||
| done <<< "$TAGS" | ||
| done | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.