Repository navigation
Provide all metadata fields in scripted pr view #1532
Description
Activity
Thanks for the feature request!
except that if your redirect stdout it drops this information. (I understand having a command behave differently in interactive vs scripted contexts, but this seems like a pretty surprising behavior).
Do you think a good solution would be to add extra fields for both PR number and URL in the scripted output?
number: 1234 url: https://github.com/OWNER/REPO/pull/1234Ref. #1373
I included a collapsed suggestion for what I think this could look like. You could include all the informative parts of the URL as separate fields (owner and repo separately), which I think is nicer for scripting than having to parse the URL. The URL is probably useful enough on its own that it might be also nice to have it as denormalized output. I also noticed there are a few other pieces of information only visible in the interactive output: the count of commits in the PR and the branch the PR is from. I don't currently have a use case for those, but I think that any information in the interactive view should also be accessible in the scripted output.
Reacted by Mislav MarohnićAbsolutely; thank you for the suggestions!
I think the linked commit doesn't quite close this issue because there's still info that is only available in the non-TTY output:
commit_count: 14 base_repo_owner: google base_repo: iree base_branch: google pr_repo_owner: GMNGeoffrey pr_repo: iree pr_branch: main-to-googleReacted by Amit SinghBut thanks for adding the PR number! That solves my use case :-)
Reacted by Dan Hughes@mislav Ping on the above comment, since I don't think this issue is actually fully fixed.
Reacted by Amit Singh@GMNGeoffrey Sorry about that! Reopening
I'm thinking that, instead of listing every possible attribute of a PR in a line-based format, we could consider allowing you to specify exactly which fields you need and output just those in a format of your choosing (JSON, YAML, etc.). #1089
Reacted by hash- changed the title
[-]`gh pr view` should provide all information when scripted (e.g. PR number)[/-][+]Provide all metadata fields in scripted `pr view`[/+]on Sep 17, 2020 No worries. I agree some sort of structured output would be nice
- addedcoreThis issue is not accepting PRs from outside contributorsThis issue is not accepting PRs from outside contributorsneeds-designAn engineering task needs design to proceedAn engineering task needs design to proceed
on Oct 7, 2020 @GMNGeoffrey Please try out the
gh pr view --jsonthat will be new in today's release and let us know if that covers your needs!Example use:
$ gh pr view [PRNUMBER] --json headRefName,url,headRepositoryAn additional
--jqexpression might be supplied to turn the JSON into something immediately usable in a shell script.
Describe the feature or problem you’d like to solve
I am trying to automate doing something with the PR just created from the current branch.
gh pr viewwill print out the PR info including the URL, which would be fine, except that if your redirect stdout it drops this information. (I understand having a command behave differently in interactive vs scripted contexts, but this seems like a pretty surprising behavior).Proposed solution
All information in the interactive view should also be present in the scripted view. In particular
gh pr viewshould include the PR number and URL (and/or include the owner and repo name as separate fields).How will it benefit CLI and its users?
This enables
ghto be used with other automation that operates on PRs.Additional context
Current behavior
Proposed behavior