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

gh pr diff for a single filepath #5398

Closed
Bhupesh-V opened this issue Apr 3, 2022 · 2 comments
Closed

gh pr diff for a single filepath #5398

Bhupesh-V opened this issue Apr 3, 2022 · 2 comments
Labels
enhancement a request to improve CLI needs-triage needs to be reviewed

Comments

@Bhupesh-V
Copy link

Bhupesh-V commented Apr 3, 2022

Describe the feature or problem you’d like to solve

So by default diffs of all the file changes are presented to the user. Parsing diff for a single file path is possible using sed but it can be error-prone and let's be honest not the best way to do it

escaped_filepath=${1//\//\\/}
gh pr diff --color always 34 | sed -n "/diff --git a\/$escaped_filepath/d;/diff/q;p"

Proposed solution

I believe we can refer to this behavior from the git command itself,

git diff myBranch..targetBranch -- relative_filepath

We can retrofit waigani's diffparser to filter out diffs when the user requests so

Let me know if this is something useful enough, More than happy to pick it up

@Bhupesh-V Bhupesh-V added the enhancement a request to improve CLI label Apr 3, 2022
@cliAutomation cliAutomation added the needs-triage needs to be reviewed label Apr 3, 2022
@samcoe
Copy link
Contributor

samcoe commented Apr 5, 2022

@Bhupesh-V Thanks for the feature request but this is a limitation of the API unfortunately. The API does not have the ability to retrieve just a single file diff from a PR. As you stated we could introduce a new library to manually parse the full diff and discard all but the desired file changes but the one you linked appears to be unmaintained. As git already provides an alternative solution to the problem I am going to close this as won't add. Perhaps it is worth investigating if third-party diff viewers such as delta can provide this functionality by piping the output of gh pr diff to it.

@samcoe samcoe closed this as completed Apr 5, 2022
@wojsmol
Copy link

wojsmol commented Sep 1, 2022

Maybe after we have https://docs.github.com/en/rest/pulls/pulls#list-pull-requests-files adding this can be reconsidered?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement a request to improve CLI needs-triage needs to be reviewed
Projects
None yet
Development

No branches or pull requests

4 participants