-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Serve pull request .diff files #3293
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
routers/routes/routes.go
Outdated
@@ -591,6 +591,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
m.Group("", func() { | |||
m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues) | |||
m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue) | |||
m.Get("/pulls/:index.diff", repo.DownloadPullDiff) |
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.
There should be check that user has rights to access models.UnitTypePullRequests
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.
why isn't it done for the route before ? How's .diff different from the non-diff URL ?
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.
If you would move it to this part of route than you would not need to check rights as all group has right check already:
https://github.com/strk/gitea/blob/43c2bfa2d016d899936a178b5b5676e27d13c8dc/routers/routes/routes.go#L629
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.
There is no check for group as these routes are common for issues and PR and each have it's own rights
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.
moved with c60fa34b
routers/repo/pull.go
Outdated
|
||
// Redirect elsewhere if it's not a pull request | ||
if !issue.IsPull { | ||
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index)) |
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.
It should not redirect as this will be confusing when using from command line to download patch, instead it should return 404
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.
Done with 9149d56
Codecov Report
@@ Coverage Diff @@
## master #3293 +/- ##
==========================================
- Coverage 34.81% 34.81% -0.01%
==========================================
Files 277 277
Lines 40271 40303 +32
==========================================
+ Hits 14021 14031 +10
- Misses 24189 24207 +18
- Partials 2061 2065 +4
Continue to review full report at Codecov.
|
For implementing .patch we'll need go-gitea/git#103, please also review that one |
@lafriks I believe I addressed all your concerns here |
@@ -624,6 +624,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
}, repo.MustBeNotBare, context.RepoRef(), context.CheckUnit(models.UnitTypeCode)) | |||
|
|||
m.Group("/pulls/:index", func() { | |||
m.Get(".diff", repo.DownloadPullDiff) |
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.
I think maybe it's not work?
A test would be great. Maybe add it to https://github.com/go-gitea/gitea/blob/master/integrations/pull_create_test.go#L47 |
@sapk how do I run that test in isolation ? |
routers/repo/pull.go
Outdated
|
||
// DownloadPullDiff render a pull's raw diff | ||
func DownloadPullDiff(ctx *context.Context) { | ||
|
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.
blank line is unnecessary.
routers/repo/pull.go
Outdated
|
||
pr := issue.PullRequest | ||
|
||
if pr.BaseRepo == nil { |
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.
use err = pr.GetBaseRepo()
is better.
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.
See if you like 8150dbb9 (I'm not sure GetBaseRepo was much better...)
routers/repo/pull.go
Outdated
return | ||
} | ||
if pr.BaseRepo == nil { | ||
ctx.Handle(500, "BaseRepo", |
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 move this condition to previous if and you will not need this section. err != nil || pr.BaseRepo == nil
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.
upon reading the correct GetBaseRepo method I realized there's no way pr.BaseRepo is nil after calling GetBaseRepo and getting no error, so I removed the whole check for null in lattest commit
Can I get some LGTM and a merge here please ?
|
See #3259