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

misc: Add checkout-pr.sh script for easier checkout #1947

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

honggyukim
Copy link
Collaborator

It takes some time to get the patches for review but it'd be useful to have a script for that.

The script accepts only a parameter to get the pull request ID. It fetches from the source repo and checkouts to the fetched head.

Copy link
Owner

@namhyung namhyung left a comment

Choose a reason for hiding this comment

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

Don't we have misc/wget-pr.sh already?

pr_json="pr.json"

curl -o $pr_json https://api.github.com/repos/namhyung/uftrace/pulls/$pr
repo=$(jq -r '.head.repo.html_url' $pr_json)
Copy link
Owner

Choose a reason for hiding this comment

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

What is jq?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You can easily understand by running the following command. It's to get the PR sender's uftrace repo.

$ curl -s https://api.github.com/repos/namhyung/uftrace/pulls/1947 | jq -r '.head.repo.html_url'
https://github.com/honggyukim/uftrace

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can also get the branch name as follows.

$ curl -s https://api.github.com/repos/namhyung/uftrace/pulls/1947 | jq -r '.head.ref'
check/checkout-pr.sh

Copy link
Owner

Choose a reason for hiding this comment

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

That's cool. Is it ok to assume if it's installed on all modern distros?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry for the late answer but I guess yes.

Copy link
Collaborator Author

@honggyukim honggyukim left a comment

Choose a reason for hiding this comment

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

Don't we have misc/wget-pr.sh already?

wget-pr.sh just downloads .patch file, but this fetches the remote branch then checkout to it. If the PR is a bit outdated then the downloaded .patch file can make conflicts.

Rather than this, we can just put the PR number then it will create a branch pull/<pr>, then checkout to it and we can easily see if the branch needs rebase or not.

The usage to checkout to #1756 is as follows.

$ ./misc/checkout-pr.sh 1756

pr_json="pr.json"

curl -o $pr_json https://api.github.com/repos/namhyung/uftrace/pulls/$pr
repo=$(jq -r '.head.repo.html_url' $pr_json)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@honggyukim
Copy link
Collaborator Author

This might be not needed if we're working on already registered remote repos but I felt it's tedious to fetch and checkout some new contributors' branch. This script makes the workflow much easier.

Copy link
Owner

@namhyung namhyung left a comment

Choose a reason for hiding this comment

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

Ok, I like you used git checkout -B to create or update the branch.

@honggyukim honggyukim force-pushed the check/checkout-pr.sh branch from 163db4b to 6fbb3cd Compare October 1, 2024 17:16
It usually takes some time to get patches for review but it'd be useful
to have a script for that.

The 'checkout-pr.sh' script accepts a single parameter to get the pull
request ID.
It fetches from the source repo and checkouts to the fetched head.

The example usage is as follows.

  $ ./misc/checkout-pr.sh 1974
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
  100 18502  100 18502    0     0  39899      0 --:--:-- --:--:-- --:--:-- 39875
  remote: Enumerating objects: 1, done.
  remote: Counting objects: 100% (1/1), done.
  remote: Total 1 (delta 0), reused 1 (delta 0), pack-reused 0 (from 0)
  Unpacking objects: 100% (1/1), 354 bytes | 354.00 KiB/s, done.
  From https://github.com/GabrielKimm/uftrace
   * branch              fix-tui-non-utf8-locale -> FETCH_HEAD
  Switched to and reset branch 'pull/1974'

Now you're ready to review the pull request 1974 where can be found at
namhyung#1974.

Signed-off-by: Honggyu Kim <[email protected]>
@honggyukim honggyukim force-pushed the check/checkout-pr.sh branch from 6fbb3cd to e37e65a Compare October 1, 2024 17:38
@honggyukim
Copy link
Collaborator Author

@namhyung I've just update it so please have a look again. Thanks.

Copy link
Owner

@namhyung namhyung left a comment

Choose a reason for hiding this comment

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

LGTM

@namhyung namhyung merged commit b47a765 into namhyung:master Oct 4, 2024
3 checks passed
@honggyukim honggyukim deleted the check/checkout-pr.sh branch October 4, 2024 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants