Can this component be used with GitHub API style patch strings?
princefishthrower opened this issue · 8 comments
I'm currently working with the GitHub API and given two different version numbers, their API returns an array of file changes, where each file contains a patch
string that looks something like this (dumb example, this is from the gatsby
repository for their internal .jestSetup.js
file:
@@ -1,4 +1,5 @@ process.env.GATSBY_RECIPES_NO_COLOR = "true" +process.env.GATSBY_SHOULD_TRACK_IMAGE_CDN_URLS = "true" // Potrace has a dependency on giwrap which has a process.nextTick as a sideEffect which messes up with jest. jest.mock(`gifwrap`, () => jest.fn())
is there a way to use the patch
string with this component or is the only way to generate the hunks
with the old text / new text?
(Also if this component doesn't work with the patch
text, I would be happy to learn if anyone has built a component that can!)
Thanks!
Chris
Is this patch string exactly the same with that from GitHub API? I'm curious that it is a single line, but it seems to reflect a code change with about 3 lines?
@otakustay - I'm not sure how GitHub generates it, here is another example from their API: https://api.github.com/repos/git/git/compare/v2.2.0-rc1...v2.2.0-rc2
I'm struggling to find GitHub's specification for how this diff string is generated.
The simplest way is to use diff_url
property to fetch the diff text, this is a valid git diff string, pass it to parseDiff
function will produce diff objects consumable by Diff
component.
The patch
property in each file is a git patch string, I believe it can be converted to diff string but the algorithm is currently unknown, I would like to try it if you can't use diff_url
instead
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@otakustay did u had time to look into this ?, I am also trying to use patch string from github API and trying to generate a diff view out of it. Is it possible to use this component ?
As I suggested above, if you can use diff_url
property in GitHub API Response to fetch diff text, it can perfectly suit this component.
If using diff_url
is impossible for some other reasons, I would take time to see how patch string is constructed, but this may not be working in all edge cases
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
A better way is to make the request to the compare endpoint but include this header:
Accept: "application/vnd.github.v3.patch"
It'll return the patch diff text as a string. Works in octokit too.