Skip to content
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

Use pagination when requesting github API #1168

Merged

Conversation

mboukhalfa
Copy link
Member

Fix #1162

@metal3-io-bot metal3-io-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 6, 2023
@mboukhalfa mboukhalfa force-pushed the Use-github-pagination/mohammed branch from 7bb87a3 to d14728d Compare March 6, 2023 17:20
@mboukhalfa
Copy link
Member Author

/test-ubuntu-integration-e2e-main

@mboukhalfa
Copy link
Member Author

/test-centos-integration-release-1-3

@tuminoid tuminoid self-requested a review March 6, 2023 18:35
Copy link
Member

@tuminoid tuminoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes needed.

lib/releases.sh Outdated
if [ -z "${GITHUB_TOKEN:-}" ]; then
release="$(curl -sL "${1}")" || ( set -x && exit 1 )
last_page=$(curl -s -I "${1}" -H "Authorization: token $GITHUB_TOKEN" | grep '^link:' | sed -e 's/^link:.*page=//g' -e 's/>.*$//g') || (set -x && exit 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(set -x && exit 1) creates a subshell, the parenthesis does that, so the exit 1 exits only that subshell, and not the script. If you want to perform two actions, use curly braces, {set -x && exit 1}.

Also, you want to assign the subshell output of $( ... ) with quotes, so do last_page="$( ... )"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shellcheck complaining about {set -x && exit 1} and ${set -x && exit 1} not working as expected do you know what is wrong

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${set -x ...} is definitely wrong, but what does it complain about { set -x ... } ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need semicolon at the end { set -x && exit 1; }.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! done

lib/releases.sh Outdated
else
release="$(curl -H "Authorization: token ${GITHUB_TOKEN}" -sL "${1}")" || ( set -x && exit 1 )
last_page=$(curl -s -I "${1}" | grep '^link:' | sed -e 's/^link:.*page=//g' -e 's/>.*$//g') || (set -x && exit 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

lib/releases.sh Outdated
# selection is possible given specific enough prefix, like v1.3.0-pre
release_tag="$(echo "$release" | jq -r "[.[].tag_name | select( startswith(\"${2:-}\"))] | .[0]")"
# default last page to 1
last_page=${last_page:-1}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quotes do no harm here either.

lib/releases.sh Show resolved Hide resolved
lib/releases.sh Outdated
url="${1}?page=${current_page}"

if [ -z "${GITHUB_TOKEN:-}" ]; then
release="$(curl -sL "${url}")" || (set -x && exit 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the first one

lib/releases.sh Outdated
if [ -z "${GITHUB_TOKEN:-}" ]; then
release="$(curl -sL "${url}")" || (set -x && exit 1)
else
release="$(curl -H "Authorization: token ${GITHUB_TOKEN}" -sL "${url}")" || (set -x && exit 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the first one

lib/releases.sh Outdated
# The order is exactly as released in Github.
# Downside is that selecting official releases only isn't possible, while pre-release
# selection is possible given specific enough prefix, like v1.3.0-pre
release_tag="$(echo "$release" | jq -r "[.[].tag_name | select( startswith(\"${2:-}\"))] | .[0]")"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add curlys to $release

lib/releases.sh Outdated
# selection is possible given specific enough prefix, like v1.3.0-pre
release_tag="$(echo "$release" | jq -r "[.[].tag_name | select( startswith(\"${2:-}\"))] | .[0]")"
# if release tag found
if [[ "$release_tag" != "null" ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@mboukhalfa mboukhalfa force-pushed the Use-github-pagination/mohammed branch from d14728d to be8b0df Compare March 7, 2023 08:25
@mboukhalfa mboukhalfa requested a review from tuminoid March 7, 2023 08:27
@mboukhalfa mboukhalfa force-pushed the Use-github-pagination/mohammed branch 2 times, most recently from 4ec57f1 to ba20246 Compare March 7, 2023 09:30
@mboukhalfa
Copy link
Member Author

/test-centos-integration-release-1-3
/test-ubuntu-integration-e2e-main

@mboukhalfa
Copy link
Member Author

/test-ubuntu-integration-e2e-main

@mboukhalfa mboukhalfa force-pushed the Use-github-pagination/mohammed branch from ba20246 to cfe8652 Compare March 7, 2023 10:58
@mboukhalfa
Copy link
Member Author

/test-ubuntu-integration-e2e-main

@Rozzii
Copy link
Member

Rozzii commented Mar 7, 2023

/lgtm

@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label Mar 7, 2023
@mboukhalfa
Copy link
Member Author

/test-centos-integration-release-1-3

@furkatgofurov7
Copy link
Member

/test-ubuntu-e2e-integration-main

@mboukhalfa
Copy link
Member Author

/assign @furkatgofurov7
cc @lentzi90

@mboukhalfa
Copy link
Member Author

/hold

@metal3-io-bot metal3-io-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 8, 2023
@mboukhalfa mboukhalfa force-pushed the Use-github-pagination/mohammed branch from cfe8652 to 8376ca5 Compare March 8, 2023 07:33
@metal3-io-bot metal3-io-bot removed the lgtm Indicates that a PR is ready to be merged. label Mar 8, 2023
@mboukhalfa
Copy link
Member Author

/test-centos-integration-release-1-3
/test-ubuntu-integration-e2e-main
/hold cancel

@metal3-io-bot metal3-io-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 8, 2023
Comment on lines +73 to 82
command -v jq &>/dev/null && echo "Failed to fetch CAPI release from Github" && exit 1
fi

if [[ "$CAPM3RELEASE" == "" ]]; then
command -v jq &> /dev/null && echo "Failed to fetch CAPM3 release from Github" && exit 1
command -v jq &>/dev/null && echo "Failed to fetch CAPM3 release from Github" && exit 1
fi

if [[ "$BMORELEASE" == "" ]]; then
command -v jq &> /dev/null && echo "Failed to fetch BMO release from Github" && exit 1
command -v jq &>/dev/null && echo "Failed to fetch BMO release from Github" && exit 1
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the space here? I think it is easier to read with the space so we should add it back.

Copy link
Member Author

@mboukhalfa mboukhalfa Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was auto reformatted by editor formatter! do we have coding style for that

Copy link
Member

@lentzi90 lentzi90 Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tuminoid any input on this? I'm inclined to approve it as just a matter of preference if there are no objections.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That space is completely up to personal taste. I tend to have the space there for readability, but it doesn't really matter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright I'm putting lgtm then 🙂

Copy link
Member

@furkatgofurov7 furkatgofurov7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked locally, it works fine

/approve
/hold to address the comments from @lentzi90

@metal3-io-bot metal3-io-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 8, 2023
@metal3-io-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: furkatgofurov7

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@metal3-io-bot metal3-io-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 8, 2023
@mboukhalfa
Copy link
Member Author

/test-ubuntu-e2e-integration-main

1 similar comment
@mboukhalfa
Copy link
Member Author

/test-ubuntu-e2e-integration-main

@lentzi90
Copy link
Member

lentzi90 commented Mar 8, 2023

/lgtm

@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label Mar 8, 2023
@mboukhalfa
Copy link
Member Author

/hold cancel

@metal3-io-bot metal3-io-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 8, 2023
@metal3-io-bot metal3-io-bot merged commit 78ca7ab into metal3-io:main Mar 8, 2023
@mboukhalfa mboukhalfa deleted the Use-github-pagination/mohammed branch March 8, 2023 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add pagination when requesting github API
6 participants