Fix Go 1.13 private repository go get issue (#8112)

* 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>
pull/8118/head
Lunny Xiao 5 years ago committed by GitHub
parent c03d75fbd5
commit 88e1c29df1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      modules/context/context.go
  2. 8
      modules/context/repo.go

@ -250,6 +250,19 @@ func Contexter() macaron.Handler {
if ctx.Query("go-get") == "1" { if ctx.Query("go-get") == "1" {
ownerName := c.Params(":username") ownerName := c.Params(":username")
repoName := c.Params(":reponame") repoName := c.Params(":reponame")
trimmedRepoName := strings.TrimSuffix(repoName, ".git")
if ownerName == "" || trimmedRepoName == "" {
_, _ = c.Write([]byte(`<!doctype html>
<html>
<body>
invalid import path
</body>
</html>
`))
c.WriteHeader(400)
return
}
branchName := "master" branchName := "master"
repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName) repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName)
@ -277,7 +290,7 @@ func Contexter() macaron.Handler {
</body> </body>
</html> </html>
`, map[string]string{ `, map[string]string{
"GoGetImport": ComposeGoGetImport(ownerName, strings.TrimSuffix(repoName, ".git")), "GoGetImport": ComposeGoGetImport(ownerName, trimmedRepoName),
"CloneLink": models.ComposeHTTPSCloneURL(ownerName, repoName), "CloneLink": models.ComposeHTTPSCloneURL(ownerName, repoName),
"GoDocDirectory": prefix + "{/dir}", "GoDocDirectory": prefix + "{/dir}",
"GoDocFile": prefix + "{/dir}/{file}#L{line}", "GoDocFile": prefix + "{/dir}/{file}#L{line}",

@ -201,10 +201,14 @@ func ComposeGoGetImport(owner, repo string) string {
// .netrc file. // .netrc file.
func EarlyResponseForGoGetMeta(ctx *Context) { func EarlyResponseForGoGetMeta(ctx *Context) {
username := ctx.Params(":username") username := ctx.Params(":username")
reponame := ctx.Params(":reponame") reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")
if username == "" || reponame == "" {
ctx.PlainText(400, []byte("invalid repository path"))
return
}
ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`, ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`,
map[string]string{ map[string]string{
"GoGetImport": ComposeGoGetImport(username, strings.TrimSuffix(reponame, ".git")), "GoGetImport": ComposeGoGetImport(username, reponame),
"CloneLink": models.ComposeHTTPSCloneURL(username, reponame), "CloneLink": models.ComposeHTTPSCloneURL(username, reponame),
}))) })))
} }

Loading…
Cancel
Save