I would like the ability to easily get the pr number of the current branch. We already have this underlying information since it makes $ git show pr
possible but rather than opening a link to the PR I just want the PR number sent to stdout
.
My motivation is to leverage this information in a script, along the lines of:
yarn publish \
--tag "pr$(git pr show --number)" \
--no-git-tag-version \
--new-version "0.0.0-pr.$(git pr show --number).$(git show -s head --format='%h')"
Hi thank you for writing in!
You can extract the PR number in bash like so:
# split fields by "/" and output the last value
hub pr show -u | awk -F/ '{print $(NF)}'
For a more sophisticated approach, you can use hub pr list
:
# 1. Fetch open PRs where the current branch is the head,
# 2. Output only the PR number.
hub pr list --head="$(git branch --show-current)" --format='%I%n'
Thanks for the workaround @mislav! -u
gets us really close. I think a -n
that provides the last step would still be worthwhile, though.
I'm personally not familiar with awk, prefer regexp.
git pr show -u | pcregrep -o '\d+$'
But yeah the following would be ideal I guess:
git pr show -n
Thank you for the feedback.
Personally, I think supporting -n
/--number
would be adding an _additional_ mechanism for selecting specific fields for output that is different than the current mechanism, which is the --format
flag.
Do you feel that hub pr show
should then support --format='%I'
?
Do you feel that hub pr show should then support --format='%I'?
That would generally align with git
conventions. I think --format
would be justifiable if there were at least a few symbols available? What might the use-cases be?
%n PR number
%cn PR comments number
%a PR author github handle
...
Seems we could come up with quite a few :)
I think
--format
would be justifiable if there were at least a few symbols available?
We already support quite a few in hub pr list
: https://hub.github.com/hub-pr.1.html#options 馃槈
My suggestion was that we could consider also making them available to hub pr show
with the same syntax so we don't have to reinvent the wheel and add flags such as -n/--number
.
@mislav sounds great, I agree
Reopening and renaming this issue then. Thank you!
mind if I try and take a crack at this one
@tomlazar Be my guest please! 馃檹
Most helpful comment
Reopening and renaming this issue then. Thank you!