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

Fix Go 1.13 private repository go get issue #8100

Merged
merged 3 commits into from
Sep 6, 2019
Merged

Fix Go 1.13 private repository go get issue #8100

merged 3 commits into from
Sep 6, 2019

Conversation

rutgerbrf
Copy link

Fixes #8095.

Signed-off-by: Rutger Broekhoff <rutger@viasalix.nl>
@lunny lunny added the type/bug label Sep 5, 2019
@lunny lunny added this to the 1.10.0 milestone Sep 5, 2019
@@ -249,6 +249,17 @@ func Contexter() macaron.Handler {
if ctx.Query("go-get") == "1" {
ownerName := c.Params(":username")
repoName := c.Params(":reponame")
if ownerName == "" || repoName == "" {
_, _ = c.Write([]byte(`<!doctype html>
Copy link
Member

Choose a reason for hiding this comment

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

if returned error, you should give a 500 I think.

Copy link
Member

Choose a reason for hiding this comment

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

Why not see the problem the other way and simply ignore go-get params instead of erroring ?

if ctx.Query("go-get") == "1" && ownerName != "" && repoName != "" {

}

Copy link
Member

Choose a reason for hiding this comment

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

This could be break down in two if obviously.

if ctx.Query("go-get") == "1" 
  ownerName := c.Params(":username")
  repoName := c.Params(":reponame")
  if ownerName != "" && repoName != "" {
	... Do go-get work
  }
}

Copy link
Member

Choose a reason for hiding this comment

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

But else we still need return 404 but not continue the other work.

Copy link
Member

Choose a reason for hiding this comment

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

Once ctx.Query("go-get") == "1" , it should return anyway here.

Copy link
Author

@rutgerbrf rutgerbrf Sep 5, 2019

Choose a reason for hiding this comment

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

I think a 400 should be returned because in this case the client has not provided adequate information for the server to provide an import URL from the its request.

Copy link
Author

@rutgerbrf rutgerbrf Sep 5, 2019

Choose a reason for hiding this comment

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

reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")
I suppose this should also be applied in this case.

Copy link
Author

Choose a reason for hiding this comment

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

Or perhaps in trimmedRepoName, such that this is not interfered with:

prefix := setting.AppURL + path.Join(url.PathEscape(ownerName), url.PathEscape(repoName), "src", "branch", util.PathEscapeSegments(branchName))

Copy link
Member

@sapk sapk Sep 5, 2019

Choose a reason for hiding this comment

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

Why we should return an error ? For exemple github doesn't trigger an error on an profile if you use go-get param. Futhermore triggering an error from a supervision point could be misleading. I will not block as it need a quick fix.

@@ -202,6 +202,9 @@ func ComposeGoGetImport(owner, repo string) string {
func EarlyResponseForGoGetMeta(ctx *Context) {
username := ctx.Params(":username")
reponame := ctx.Params(":reponame")
if username == "" || reponame == "" {
ctx.PlainText(404, []byte("invalid repository path"))
Copy link
Member

Choose a reason for hiding this comment

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

return

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 5, 2019
@@ -202,6 +202,9 @@ func ComposeGoGetImport(owner, repo string) string {
func EarlyResponseForGoGetMeta(ctx *Context) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here we can check previously to calling this method and maybe pass username and reponame as args since they are already extracted and cleaned from context before calling:

reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")

Copy link
Author

Choose a reason for hiding this comment

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

Would it not be preferable to add this for username as well in case only .git is appended to the Gitea instance URL?

Copy link
Author

Choose a reason for hiding this comment

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

I guess not because it seems possible to have the suffix .git in a username or organization name.

Signed-off-by: Rutger Broekhoff <rutger@viasalix.nl>
@GiteaBot GiteaBot 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 Sep 5, 2019
@GiteaBot GiteaBot 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 Sep 6, 2019
Copy link
Member

@techknowlogick techknowlogick left a comment

Choose a reason for hiding this comment

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

This should be sent to master branch first. I'm going to mark this as blocked so we don't merge this prematurely.

@techknowlogick techknowlogick added the status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR label Sep 6, 2019
@lunny lunny modified the milestones: 1.10.0, 1.9.3 Sep 6, 2019
@lunny
Copy link
Member

lunny commented Sep 6, 2019

@rutgerbrf please send a PR to master also.

lunny pushed a commit to lunny/gitea that referenced this pull request Sep 6, 2019
Signed-off-by: Rutger Broekhoff <rutger@viasalix.nl>
lunny added a commit that referenced this pull request Sep 6, 2019
* Fix Go 1.13 invalid import path creation

Signed-off-by: Rutger Broekhoff <rutger@viasalix.nl>

* Apply suggested changes from #8100

Signed-off-by: Rutger Broekhoff <rutger@viasalix.nl>
@lunny lunny removed the status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR label Sep 6, 2019
@lunny
Copy link
Member

lunny commented Sep 6, 2019

Since #8112 merged, I have removed the blocked label. @techknowlogick

@lafriks
Copy link
Member

lafriks commented Sep 6, 2019

@techknowlogick it is been merged to master please approve

@techknowlogick techknowlogick dismissed their stale review September 6, 2019 13:58

merged to master

@techknowlogick techknowlogick merged commit 89c5748 into go-gitea:release/v1.9 Sep 6, 2019
@rutgerbrf rutgerbrf deleted the fix-go1.13-invalid-import-path branch December 24, 2019 09:23
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 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/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants