mirror of
1
Fork 0

#2825 early response 200 when ?go-get=1

This commit is contained in:
Unknwon 2016-08-07 14:29:16 -07:00
parent 0c2b9bbb2b
commit e5bf4281b5
5 changed files with 41 additions and 5 deletions

View File

@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
##### Current tip version: 0.9.66 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions) ##### Current tip version: 0.9.67 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
| Web | UI | Preview | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|

View File

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.66.0806" const APP_VER = "0.9.67.0806"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

View File

@ -494,6 +494,11 @@ type CloneLink struct {
Git string Git string
} }
// ComposeHTTPSCloneURL returns HTTPS clone URL based on given owner and repository name.
func ComposeHTTPSCloneURL(owner, repo string) string {
return fmt.Sprintf("%s%s/%s.git", setting.AppUrl, owner, repo)
}
func (repo *Repository) cloneLink(isWiki bool) *CloneLink { func (repo *Repository) cloneLink(isWiki bool) *CloneLink {
repoName := repo.Name repoName := repo.Name
if isWiki { if isWiki {
@ -507,7 +512,7 @@ func (repo *Repository) cloneLink(isWiki bool) *CloneLink {
} else { } else {
cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", setting.RunUser, setting.SSH.Domain, repo.Owner.Name, repoName) cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", setting.RunUser, setting.SSH.Domain, repo.Owner.Name, repoName)
} }
cl.HTTPS = fmt.Sprintf("%s%s/%s.git", setting.AppUrl, repo.Owner.Name, repoName) cl.HTTPS = ComposeHTTPSCloneURL(repo.Owner.Name, repo.Name)
return cl return cl
} }

View File

@ -9,6 +9,7 @@ import (
"path" "path"
"strings" "strings"
"github.com/Unknwon/com"
"gopkg.in/macaron.v1" "gopkg.in/macaron.v1"
"github.com/gogits/git-module" "github.com/gogits/git-module"
@ -84,6 +85,24 @@ func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
} }
} }
// composeGoGetImport returns go-get-import meta content.
func composeGoGetImport(owner, repo string) string {
return path.Join(setting.Domain, setting.AppSubUrl, owner, repo)
}
// earlyResponseForGoGetMeta responses appropriate go-get meta with status 200
// if user does not have actual access to the requested repository,
// or the owner or repository does not exist at all.
// This is particular a workaround for "go get" command which does not respect
// .netrc file.
func earlyResponseForGoGetMeta(ctx *Context) {
ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`,
map[string]string{
"GoGetImport": composeGoGetImport(ctx.Params(":username"), ctx.Params(":reponame")),
"CloneLink": models.ComposeHTTPSCloneURL(ctx.Params(":username"), ctx.Params(":reponame")),
})))
}
func RepoAssignment(args ...bool) macaron.Handler { func RepoAssignment(args ...bool) macaron.Handler {
return func(ctx *Context) { return func(ctx *Context) {
var ( var (
@ -112,6 +131,10 @@ func RepoAssignment(args ...bool) macaron.Handler {
owner, err = models.GetUserByName(userName) owner, err = models.GetUserByName(userName)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
if ctx.Query("go-get") == "1" {
earlyResponseForGoGetMeta(ctx)
return
}
ctx.Handle(404, "GetUserByName", err) ctx.Handle(404, "GetUserByName", err)
} else { } else {
ctx.Handle(500, "GetUserByName", err) ctx.Handle(500, "GetUserByName", err)
@ -125,6 +148,10 @@ func RepoAssignment(args ...bool) macaron.Handler {
repo, err := models.GetRepositoryByName(owner.ID, repoName) repo, err := models.GetRepositoryByName(owner.ID, repoName)
if err != nil { if err != nil {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
if ctx.Query("go-get") == "1" {
earlyResponseForGoGetMeta(ctx)
return
}
ctx.Handle(404, "GetRepositoryByName", err) ctx.Handle(404, "GetRepositoryByName", err)
} else { } else {
ctx.Handle(500, "GetRepositoryByName", err) ctx.Handle(500, "GetRepositoryByName", err)
@ -149,6 +176,10 @@ func RepoAssignment(args ...bool) macaron.Handler {
// Check access. // Check access.
if ctx.Repo.AccessMode == models.ACCESS_MODE_NONE { if ctx.Repo.AccessMode == models.ACCESS_MODE_NONE {
if ctx.Query("go-get") == "1" {
earlyResponseForGoGetMeta(ctx)
return
}
ctx.Handle(404, "no access right", err) ctx.Handle(404, "no access right", err)
return return
} }
@ -269,7 +300,7 @@ func RepoAssignment(args ...bool) macaron.Handler {
ctx.Data["PullRequestCtx"] = ctx.Repo.PullRequest ctx.Data["PullRequestCtx"] = ctx.Repo.PullRequest
if ctx.Query("go-get") == "1" { if ctx.Query("go-get") == "1" {
ctx.Data["GoGetImport"] = path.Join(setting.Domain, setting.AppSubUrl, owner.Name, repo.Name) ctx.Data["GoGetImport"] = composeGoGetImport(owner.Name, repo.Name)
prefix := setting.AppUrl + path.Join(owner.Name, repo.Name, "src", ctx.Repo.BranchName) prefix := setting.AppUrl + path.Join(owner.Name, repo.Name, "src", ctx.Repo.BranchName)
ctx.Data["GoDocDirectory"] = prefix + "{/dir}" ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}" ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}"

View File

@ -1 +1 @@
0.9.66.0806 0.9.67.0806