From 16feb5b6552d33192c61f7959eafb4ef976acee5 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 31 Oct 2015 12:04:04 -0400 Subject: [PATCH] minor fix on #1863 --- gogs.go | 2 +- modules/middleware/repo.go | 40 ++++++++++++++++++++------------------ templates/.VERSION | 2 +- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/gogs.go b/gogs.go index 2dbf6eedf1..b66f70fdad 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.6.18.1029 Beta" +const APP_VER = "0.6.18.1031 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 6424018a20..97d9050b21 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -7,6 +7,7 @@ package middleware import ( "fmt" "net/url" + "path" "strings" "github.com/mcuadros/go-version" @@ -30,15 +31,15 @@ func ApiRepoAssignment() macaron.Handler { repoName := ctx.Params(":reponame") var ( - u *models.User - err error + owner *models.User + err error ) // Check if the user is the same as the repository owner. if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) { - u = ctx.User + owner = ctx.User } else { - u, err = models.GetUserByName(userName) + owner, err = models.GetUserByName(userName) if err != nil { if models.IsErrUserNotExist(err) { ctx.Error(404) @@ -48,10 +49,10 @@ func ApiRepoAssignment() macaron.Handler { return } } - ctx.Repo.Owner = u + ctx.Repo.Owner = owner // Get repository. - repo, err := models.GetRepositoryByName(u.Id, repoName) + repo, err := models.GetRepositoryByName(owner.Id, repoName) if err != nil { if models.IsErrRepoNotExist(err) { ctx.Error(404) @@ -234,8 +235,8 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { } var ( - u *models.User - err error + owner *models.User + err error ) userName := ctx.Params(":username") @@ -247,9 +248,9 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { // Check if the user is the same as the repository owner if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) { - u = ctx.User + owner = ctx.User } else { - u, err = models.GetUserByName(userName) + owner, err = models.GetUserByName(userName) if err != nil { if models.IsErrUserNotExist(err) { ctx.Handle(404, "GetUserByName", err) @@ -259,10 +260,10 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { return } } - ctx.Repo.Owner = u + ctx.Repo.Owner = owner // Get repository. - repo, err := models.GetRepositoryByName(u.Id, repoName) + repo, err := models.GetRepositoryByName(owner.Id, repoName) if err != nil { if models.IsErrRepoNotExist(err) { ctx.Handle(404, "GetRepositoryByName", err) @@ -331,7 +332,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { } } - ctx.Data["Title"] = u.Name + "/" + repo.Name + ctx.Data["Title"] = owner.Name + "/" + repo.Name ctx.Data["Repository"] = repo ctx.Data["Owner"] = ctx.Repo.Repository.Owner ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner() @@ -345,12 +346,6 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { } ctx.Data["CloneLink"] = ctx.Repo.CloneLink - if ctx.Query("go-get") == "1" { - ctx.Data["GoGetImport"] = fmt.Sprintf("%s/%s/%s", setting.Domain, u.Name, repo.Name) - ctx.Data["GoDocDirectory"] = fmt.Sprintf("%s%s/%s/src/master{/dir}", setting.AppUrl, repo.Owner.LowerName, repo.LowerName) - ctx.Data["GoDocFile"] = fmt.Sprintf("%s%s/%s/src/master{/dir}/{file}#L{line}", setting.AppUrl, repo.Owner.LowerName, repo.LowerName) - } - if ctx.IsSigned { ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.Id, repo.ID) ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.Id, repo.ID) @@ -392,6 +387,13 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Data["BranchName"] = ctx.Repo.BranchName ctx.Data["CommitID"] = ctx.Repo.CommitID + if ctx.Query("go-get") == "1" { + ctx.Data["GoGetImport"] = path.Join(setting.Domain, setting.AppSubUrl, owner.Name, repo.Name) + prefix := path.Join(setting.AppUrl, owner.Name, repo.Name, "src", ctx.Repo.BranchName) + ctx.Data["GoDocDirectory"] = prefix + "{/dir}" + ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}" + } + userAgent := ctx.Req.Header.Get("User-Agent") ua := user_agent.New(userAgent) browserName, browserVer := ua.Browser() diff --git a/templates/.VERSION b/templates/.VERSION index dbaaca541b..9c1af4fa92 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.6.18.1029 Beta \ No newline at end of file +0.6.18.1031 Beta \ No newline at end of file