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

Serve pull request .diff files #3293

Merged
merged 4 commits into from Jan 5, 2018
Merged

Serve pull request .diff files #3293

merged 4 commits into from Jan 5, 2018

Conversation

strk
Copy link
Member

@strk strk commented Jan 3, 2018

See #3259

@strk strk changed the title Serve pull request .patch files Serve pull request .diff files Jan 3, 2018
@@ -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)
Copy link
Member

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

Copy link
Member Author

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 ?

Copy link
Member

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

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved with c60fa34b


// Redirect elsewhere if it's not a pull request
if !issue.IsPull {
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with 9149d562

@tboerger tboerger added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 3, 2018
@lafriks lafriks added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Jan 3, 2018
@lafriks lafriks added this to the 1.4.0 milestone Jan 3, 2018
@codecov-io
Copy link

codecov-io commented Jan 3, 2018

Codecov Report

Merging #3293 into master will decrease coverage by <.01%.
The diff coverage is 20.68%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
models/repo.go 43.2% <ø> (ø) ⬆️
routers/routes/routes.go 87.08% <100%> (+0.02%) ⬆️
routers/repo/pull.go 33.73% <17.85%> (-0.57%) ⬇️
modules/avatar/avatar.go 100% <0%> (+18.75%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce7ae17...e15748f. Read the comment docs.

@strk
Copy link
Member Author

strk commented Jan 3, 2018

For implementing .patch we'll need go-gitea/git#103, please also review that one

@strk
Copy link
Member Author

strk commented Jan 3, 2018

@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)
Copy link
Member

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?

@sapk
Copy link
Member

sapk commented Jan 4, 2018

A test would be great. Maybe add it to https://github.com/go-gitea/gitea/blob/master/integrations/pull_create_test.go#L47

@strk
Copy link
Member Author

strk commented Jan 4, 2018

@sapk how do I run that test in isolation ?

@strk
Copy link
Member Author

strk commented Jan 4, 2018

@sapk afaaa991 adds integration test.
@lunny you can see with that test that the code works


// DownloadPullDiff render a pull's raw diff
func DownloadPullDiff(ctx *context.Context) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line is unnecessary.


pr := issue.PullRequest

if pr.BaseRepo == nil {
Copy link
Member

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.

Copy link
Member Author

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...)

return
}
if pr.BaseRepo == nil {
ctx.Handle(500, "BaseRepo",
Copy link
Member

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

Copy link
Member Author

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

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 5, 2018
@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jan 5, 2018
@strk
Copy link
Member Author

strk commented Jan 5, 2018 via email

@lafriks lafriks merged commit a192f30 into go-gitea:master Jan 5, 2018
@strk strk deleted the serve-patch branch January 5, 2018 18:57
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants