mirror of
https://github.com/gogs/gogs.git
synced 2025-05-31 11:42:13 +00:00
repo: support go get subpkg (#1878)
This commit is contained in:
parent
af4cf463f5
commit
239dd978ff
2
gogs.go
2
gogs.go
@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/gogits/gogs/pkg/setting"
|
"github.com/gogits/gogs/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.11.13.0603"
|
const APP_VER = "0.11.14.0603"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setting.AppVer = APP_VER
|
setting.AppVer = APP_VER
|
||||||
|
@ -7,10 +7,8 @@ package context
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
|
||||||
"gopkg.in/editorconfig/editorconfig-core-go.v1"
|
"gopkg.in/editorconfig/editorconfig-core-go.v1"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
|
|
||||||
@ -108,24 +106,6 @@ func (r *Repository) PullRequestURL(baseBranch, headBranch string) string {
|
|||||||
return fmt.Sprintf("%s/compare/%s...%s:%s", repoLink, baseBranch, r.Owner.Name, headBranch)
|
return fmt.Sprintf("%s/compare/%s...%s:%s", repoLink, baseBranch, r.Owner.Name, headBranch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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")),
|
|
||||||
})))
|
|
||||||
}
|
|
||||||
|
|
||||||
// [0]: issues, [1]: wiki
|
// [0]: issues, [1]: wiki
|
||||||
func RepoAssignment(pages ...bool) macaron.Handler {
|
func RepoAssignment(pages ...bool) macaron.Handler {
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
@ -156,33 +136,16 @@ func RepoAssignment(pages ...bool) macaron.Handler {
|
|||||||
} else {
|
} else {
|
||||||
owner, err = models.GetUserByName(ownerName)
|
owner, err = models.GetUserByName(ownerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.IsUserNotExist(err) {
|
ctx.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
|
||||||
if ctx.Query("go-get") == "1" {
|
|
||||||
earlyResponseForGoGetMeta(ctx)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx.NotFound()
|
|
||||||
} else {
|
|
||||||
ctx.Handle(500, "GetUserByName", err)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.Repo.Owner = owner
|
ctx.Repo.Owner = owner
|
||||||
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||||
|
|
||||||
// Get repository.
|
|
||||||
repo, err := models.GetRepositoryByName(owner.ID, repoName)
|
repo, err := models.GetRepositoryByName(owner.ID, repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.IsRepoNotExist(err) {
|
ctx.NotFoundOrServerError("GetRepositoryByName", errors.IsRepoNotExist, err)
|
||||||
if ctx.Query("go-get") == "1" {
|
|
||||||
earlyResponseForGoGetMeta(ctx)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx.NotFound()
|
|
||||||
} else {
|
|
||||||
ctx.Handle(500, "GetRepositoryByName", err)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +162,7 @@ func RepoAssignment(pages ...bool) macaron.Handler {
|
|||||||
} else {
|
} else {
|
||||||
mode, err := models.AccessLevel(ctx.UserID(), repo)
|
mode, err := models.AccessLevel(ctx.UserID(), repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "AccessLevel", err)
|
ctx.ServerError("AccessLevel", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Repo.AccessMode = mode
|
ctx.Repo.AccessMode = mode
|
||||||
@ -207,11 +170,6 @@ func RepoAssignment(pages ...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
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect to any accessible page if not yet on it
|
// Redirect to any accessible page if not yet on it
|
||||||
if repo.IsPartialPublic() &&
|
if repo.IsPartialPublic() &&
|
||||||
(!(isIssuesPage || isWikiPage) ||
|
(!(isIssuesPage || isWikiPage) ||
|
||||||
@ -309,13 +267,6 @@ func RepoAssignment(pages ...bool) macaron.Handler {
|
|||||||
ctx.Data["BranchName"] = ctx.Repo.BranchName
|
ctx.Data["BranchName"] = ctx.Repo.BranchName
|
||||||
ctx.Data["CommitID"] = ctx.Repo.CommitID
|
ctx.Data["CommitID"] = ctx.Repo.CommitID
|
||||||
|
|
||||||
if ctx.Query("go-get") == "1" {
|
|
||||||
ctx.Data["GoGetImport"] = composeGoGetImport(owner.Name, repo.Name)
|
|
||||||
prefix := setting.AppURL + path.Join(owner.Name, repo.Name, "src", ctx.Repo.BranchName)
|
|
||||||
ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
|
|
||||||
ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}"
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Data["IsGuest"] = !ctx.Repo.HasAccess()
|
ctx.Data["IsGuest"] = !ctx.Repo.HasAccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,6 @@
|
|||||||
<meta name="referrer" content="no-referrer" />
|
<meta name="referrer" content="no-referrer" />
|
||||||
<meta name="_csrf" content="{{.CSRFToken}}" />
|
<meta name="_csrf" content="{{.CSRFToken}}" />
|
||||||
<meta name="_suburl" content="{{AppSubURL}}" />
|
<meta name="_suburl" content="{{AppSubURL}}" />
|
||||||
{{if .GoGetImport}}
|
|
||||||
<meta name="go-import" content="{{.GoGetImport}} git {{.CloneLink.HTTPS}}">
|
|
||||||
<meta name="go-source" content="{{.GoGetImport}} _ {{.GoDocDirectory}} {{.GoDocFile}}">
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
<!-- Open Graph Tags -->
|
<!-- Open Graph Tags -->
|
||||||
{{if .PageIsAdmin}}
|
{{if .PageIsAdmin}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user