-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add API endpoint to get changed files of a PR #18228
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
Conversation
We need more fields here. {
"sha": "bbcd538c8e72b8c175046e27cc8f907076331401",
"filename": "file1.txt",
"status": "added",
"additions": 103,
"deletions": 21,
"changes": 124,
"blob_url": "https://github.com/octocat/Hello-World/blob/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",
"raw_url": "https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",
"contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e",
"patch": "@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test"
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few touches on the code - also to addition on lunny, it should have more fields to become more useful. Also I'm not sure which applications might need this, so this could be really irrelevant. But it could be that applications might not need the patch
field(which could become quite large on big PR's) so a option to not send that back would be nice in order to reduce network bandwidth for those who don't need it, but only need the other fields.
return | ||
} | ||
|
||
var prInfo *git.CompareInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move this to Line 1321(after defer baseGitRepo.Close()
)
&gitdiff.DiffOptions{ | ||
BeforeCommitID: startCommitID, | ||
AfterCommitID: endCommitID, | ||
SkipTo: ctx.FormString("skip-to"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
skip-to
isn't mentioned as query in the swagger description.
MaxLines: maxLines, | ||
MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters, | ||
MaxFiles: maxFiles, | ||
WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will always be empty as this ctx.Data is set by SetWhitespaceBehavior
middleware.
WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), | ||
}, ctx.FormStrings("files")...) | ||
if err != nil { | ||
ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err) | |
ctx.ServerError("GetDiff", err) |
start, end := listOptions.GetStartEnd() | ||
|
||
if end > totalNumberOfFiles { | ||
end = totalNumberOfFiles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could cause that it becomes. start
> end
In which a panic will be caused on line 1368 panic: runtime error: makeslice: cap out of range
. Maybe add a check if start
is still smaller than end
?
apiFile := convert.ToChangedFile(diff.Files[i]) | ||
apiFiles = append(apiFiles, apiFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apiFile := convert.ToChangedFile(diff.Files[i]) | |
apiFiles = append(apiFiles, apiFile) | |
apiFiles = append(apiFiles, convert.ToChangedFile(diff.Files[i])) |
@@ -930,6 +930,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { | |||
m.Get(".{diffType:diff|patch}", repo.DownloadPullDiffOrPatch) | |||
m.Post("/update", reqToken(), repo.UpdatePullRequest) | |||
m.Get("/commits", repo.GetPullRequestCommits) | |||
m.Get("/files", repo.GetPullRequestFiles) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use context.ReferencesGitRepo(false),
to get gitRepo injected into ctx
Codecov Report
@@ Coverage Diff @@
## main #18228 +/- ##
=======================================
Coverage ? 46.02%
=======================================
Files ? 838
Lines ? 92791
Branches ? 0
=======================================
Hits ? 42704
Misses ? 43303
Partials ? 6784
Continue to review full report at Codecov.
|
Would be nice if it would return structure same as in https://docs.github.com/en/rest/reference/pulls#list-pull-requests-files even if it would return only filenames so that it could be extended easier in the future |
☝️ |
Any progress on this? It looks like this is needed for several CI-related integrations. |
I haven't looked at this PR for a while. You are right its required for some CI systems that's the reason I started it 😉. My general plan was to create the most basic version for now just a list of paths of all changed files with a structure similar to the one of Github. This way it would be easily extendable in the future if needed. |
Any update? Do you maybe wanna integrate the requested changes and if the team is willing to, it could be released in this state, and when needed expanded feature-wise? I think it's somewhat important for Woodpeeker, Drone and other CIs. Including myself - a bot I'm writing for a internal project would somewhat rely on this existing. |
seems like #21177 is winning the race 🏇🏾 😃 |
Please join the discussion there. :) |
This adds an api endpoint `/files` to PRs that allows to get a list of changed files. built upon #18228, reviews there are included closes #654 Co-authored-by: Anton Bracke <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
closes #654