1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-21 12:44:49 -05:00

feat: Only use issue and wiki on repo. (#1297)

This commit is contained in:
Bo-Yi Wu 2017-03-18 05:59:07 -05:00 committed by Lunny Xiao
parent 5ecb369dac
commit 1c3bd436cc
7 changed files with 32 additions and 40 deletions

View file

@ -448,7 +448,7 @@ func runWeb(ctx *cli.Context) error {
m.Combo("").Get(repo.ProtectedBranch).Post(repo.ProtectedBranchPost) m.Combo("").Get(repo.ProtectedBranch).Post(repo.ProtectedBranchPost)
m.Post("/can_push", repo.ChangeProtectedBranch) m.Post("/can_push", repo.ChangeProtectedBranch)
m.Post("/delete", repo.DeleteProtectedBranch) m.Post("/delete", repo.DeleteProtectedBranch)
}) }, repo.MustBeNotBare)
m.Group("/hooks", func() { m.Group("/hooks", func() {
m.Get("", repo.Webhooks) m.Get("", repo.Webhooks)
@ -520,11 +520,11 @@ func runWeb(ctx *cli.Context) error {
m.Get("/new", repo.NewRelease) m.Get("/new", repo.NewRelease)
m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost) m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost)
m.Post("/delete", repo.DeleteRelease) m.Post("/delete", repo.DeleteRelease)
}, reqRepoWriter, context.RepoRef()) }, repo.MustBeNotBare, reqRepoWriter, context.RepoRef())
m.Group("/releases", func() { m.Group("/releases", func() {
m.Get("/edit/*", repo.EditRelease) m.Get("/edit/*", repo.EditRelease)
m.Post("/edit/*", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost) m.Post("/edit/*", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
}, reqRepoWriter, func(ctx *context.Context) { }, repo.MustBeNotBare, reqRepoWriter, func(ctx *context.Context) {
var err error var err error
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
if err != nil { if err != nil {
@ -563,17 +563,17 @@ func runWeb(ctx *cli.Context) error {
return return
} }
}) })
}, reqRepoWriter, context.RepoRef(), func(ctx *context.Context) { }, repo.MustBeNotBare, reqRepoWriter, context.RepoRef(), func(ctx *context.Context) {
if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit { if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit {
ctx.Handle(404, "", nil) ctx.Handle(404, "", nil)
return return
} }
}) })
}, reqSignIn, context.RepoAssignment(), repo.MustBeNotBare, context.UnitTypes()) }, reqSignIn, context.RepoAssignment(), context.UnitTypes())
m.Group("/:username/:reponame", func() { m.Group("/:username/:reponame", func() {
m.Group("", func() { m.Group("", func() {
m.Get("/releases", repo.Releases) m.Get("/releases", repo.MustBeNotBare, repo.Releases)
m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues) m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues)
m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue) m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue)
m.Get("/labels/", repo.RetrieveLabels, repo.Labels) m.Get("/labels/", repo.RetrieveLabels, repo.Labels)
@ -581,7 +581,7 @@ func runWeb(ctx *cli.Context) error {
}, context.RepoRef()) }, context.RepoRef())
// m.Get("/branches", repo.Branches) // m.Get("/branches", repo.Branches)
m.Post("/branches/:name/delete", reqSignIn, reqRepoWriter, repo.DeleteBranchPost) m.Post("/branches/:name/delete", reqSignIn, reqRepoWriter, repo.MustBeNotBare, repo.DeleteBranchPost)
m.Group("/wiki", func() { m.Group("/wiki", func() {
m.Get("/?:page", repo.Wiki) m.Get("/?:page", repo.Wiki)
@ -601,7 +601,7 @@ func runWeb(ctx *cli.Context) error {
m.Get("/*", repo.WikiRaw) m.Get("/*", repo.WikiRaw)
}, repo.MustEnableWiki) }, repo.MustEnableWiki)
m.Get("/archive/*", repo.Download) m.Get("/archive/*", repo.MustBeNotBare, repo.Download)
m.Group("/pulls/:index", func() { m.Group("/pulls/:index", func() {
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits) m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
@ -617,10 +617,10 @@ func runWeb(ctx *cli.Context) error {
m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.Diff) m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.Diff)
m.Get("/forks", repo.Forks) m.Get("/forks", repo.Forks)
}, context.RepoRef()) }, context.RepoRef())
m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)", repo.RawDiff) m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)", repo.MustBeNotBare, repo.RawDiff)
m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.CompareDiff) m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.MustBeNotBare, repo.CompareDiff)
}, ignSignIn, context.RepoAssignment(), repo.MustBeNotBare, context.UnitTypes()) }, ignSignIn, context.RepoAssignment(), context.UnitTypes())
m.Group("/:username/:reponame", func() { m.Group("/:username/:reponame", func() {
m.Get("/stars", repo.Stars) m.Get("/stars", repo.Stars)
m.Get("/watchers", repo.Watchers) m.Get("/watchers", repo.Watchers)
@ -630,7 +630,7 @@ func runWeb(ctx *cli.Context) error {
m.Group("/:reponame", func() { m.Group("/:reponame", func() {
m.Get("", repo.SetEditorconfigIfExists, repo.Home) m.Get("", repo.SetEditorconfigIfExists, repo.Home)
m.Get("\\.git$", repo.SetEditorconfigIfExists, repo.Home) m.Get("\\.git$", repo.SetEditorconfigIfExists, repo.Home)
}, ignSignIn, context.RepoAssignment(true), context.RepoRef(), context.UnitTypes()) }, ignSignIn, context.RepoAssignment(), context.RepoRef(), context.UnitTypes())
m.Group("/:reponame", func() { m.Group("/:reponame", func() {
m.Group("/info/lfs", func() { m.Group("/info/lfs", func() {

View file

@ -553,7 +553,7 @@ func (repo *Repository) CanBeForked() bool {
// CanEnablePulls returns true if repository meets the requirements of accepting pulls. // CanEnablePulls returns true if repository meets the requirements of accepting pulls.
func (repo *Repository) CanEnablePulls() bool { func (repo *Repository) CanEnablePulls() bool {
return !repo.IsMirror return !repo.IsMirror && !repo.IsBare
} }
// AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled. // AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.

View file

@ -12,7 +12,6 @@ import (
"code.gitea.io/git" "code.gitea.io/git"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"github.com/Unknwon/com" "github.com/Unknwon/com"
editorconfig "gopkg.in/editorconfig/editorconfig-core-go.v1" editorconfig "gopkg.in/editorconfig/editorconfig-core-go.v1"
@ -154,15 +153,8 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
} }
// RepoAssignment returns a macaron to handle repository assignment // RepoAssignment returns a macaron to handle repository assignment
func RepoAssignment(args ...bool) macaron.Handler { func RepoAssignment() macaron.Handler {
return func(ctx *Context) { return func(ctx *Context) {
var (
displayBare bool // To display bare page if it is a bare repo.
)
if len(args) >= 1 {
displayBare = args[0]
}
var ( var (
owner *models.User owner *models.User
err error err error
@ -294,15 +286,7 @@ func RepoAssignment(args ...bool) macaron.Handler {
// repo is bare and display enable // repo is bare and display enable
if ctx.Repo.Repository.IsBare { if ctx.Repo.Repository.IsBare {
log.Debug("Bare repository: %s", ctx.Repo.RepoLink) ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
// NOTE: to prevent templating error
ctx.Data["BranchName"] = ""
if displayBare {
if !ctx.Repo.IsAdmin() {
ctx.Flash.Info(ctx.Tr("repo.repo_is_empty"), true)
}
ctx.HTML(200, "repo/bare")
}
return return
} }

View file

@ -479,7 +479,7 @@ quick_guide = Quick Guide
clone_this_repo = Clone this repository clone_this_repo = Clone this repository
create_new_repo_command = Create a new repository on the command line create_new_repo_command = Create a new repository on the command line
push_exist_repo = Push an existing repository from the command line push_exist_repo = Push an existing repository from the command line
repo_is_empty = This repository is empty, please come back later! bare_message = This repository does not have any content yet.
code = Code code = Code
branch = Branch branch = Branch

View file

@ -28,6 +28,7 @@ import (
) )
const ( const (
tplRepoBARE base.TplName = "repo/bare"
tplRepoHome base.TplName = "repo/home" tplRepoHome base.TplName = "repo/home"
tplWatchers base.TplName = "repo/watchers" tplWatchers base.TplName = "repo/watchers"
tplForks base.TplName = "repo/forks" tplForks base.TplName = "repo/forks"
@ -243,12 +244,18 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
// Home render repository home page // Home render repository home page
func Home(ctx *context.Context) { func Home(ctx *context.Context) {
ctx.Data["PageIsViewCode"] = true
if ctx.Repo.Repository.IsBare {
ctx.HTML(200, tplRepoBARE)
return
}
title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name
if len(ctx.Repo.Repository.Description) > 0 { if len(ctx.Repo.Repository.Description) > 0 {
title += ": " + ctx.Repo.Repository.Description title += ": " + ctx.Repo.Repository.Description
} }
ctx.Data["Title"] = title ctx.Data["Title"] = title
ctx.Data["PageIsViewCode"] = true
ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireHighlightJS"] = true
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName

View file

@ -8,9 +8,6 @@
{{if .IsRepositoryAdmin}} {{if .IsRepositoryAdmin}}
<h4 class="ui top attached header"> <h4 class="ui top attached header">
{{.i18n.Tr "repo.quick_guide"}} {{.i18n.Tr "repo.quick_guide"}}
<div class="ui right">
<a class="ui black tiny button" href="{{.RepoLink}}/settings">{{.i18n.Tr "repo.settings"}}</a>
</div>
</h4> </h4>
<div class="ui attached guide table segment"> <div class="ui attached guide table segment">
<div class="item"> <div class="item">
@ -58,6 +55,10 @@ git push -u origin master</code></pre>
git push -u origin master</code></pre> git push -u origin master</code></pre>
</div> </div>
</div> </div>
{{else}}
<div class="ui segment center">
{{.i18n.Tr "repo.bare_message"}}
</div>
{{end}} {{end}}
</div> </div>
</div> </div>

View file

@ -46,7 +46,7 @@
</div><!-- end grid --> </div><!-- end grid -->
</div><!-- end container --> </div><!-- end container -->
{{end}} {{end}}
{{if not (or .IsBareRepo .IsDiffCompare)}} {{if not .IsDiffCompare}}
<div class="ui tabs container"> <div class="ui tabs container">
<div class="ui tabular stackable menu navbar"> <div class="ui tabular stackable menu navbar">
{{if .Repository.EnableUnit $.UnitTypeCode}} {{if .Repository.EnableUnit $.UnitTypeCode}}
@ -66,20 +66,20 @@
<i class="octicon octicon-issue-opened"></i> {{.i18n.Tr "repo.issues"}} </span> <i class="octicon octicon-issue-opened"></i> {{.i18n.Tr "repo.issues"}} </span>
</a> </a>
{{end}} {{end}}
{{if .Repository.AllowsPulls}} {{if .Repository.AllowsPulls}}
<a class="{{if .PageIsPullList}}active{{end}} item" href="{{.RepoLink}}/pulls"> <a class="{{if .PageIsPullList}}active{{end}} item" href="{{.RepoLink}}/pulls">
<i class="octicon octicon-git-pull-request"></i> {{.i18n.Tr "repo.pulls"}} <span class="ui {{if not .Repository.NumOpenPulls}}gray{{else}}blue{{end}} small label">{{.Repository.NumOpenPulls}}</span> <i class="octicon octicon-git-pull-request"></i> {{.i18n.Tr "repo.pulls"}} <span class="ui {{if not .Repository.NumOpenPulls}}gray{{else}}blue{{end}} small label">{{.Repository.NumOpenPulls}}</span>
</a> </a>
{{end}} {{end}}
{{if .Repository.EnableUnit $.UnitTypeCommits}} {{if and (.Repository.EnableUnit $.UnitTypeCommits) (not .IsBareRepo)}}
<a class="{{if (or (.PageIsCommits) (.PageIsDiff))}}active{{end}} item" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}"> <a class="{{if (or (.PageIsCommits) (.PageIsDiff))}}active{{end}} item" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}">
<i class="octicon octicon-history"></i> {{.i18n.Tr "repo.commits"}} <span class="ui {{if not .CommitsCount}}gray{{else}}blue{{end}} small label">{{.CommitsCount}}</span> <i class="octicon octicon-history"></i> {{.i18n.Tr "repo.commits"}} <span class="ui {{if not .CommitsCount}}gray{{else}}blue{{end}} small label">{{.CommitsCount}}</span>
</a> </a>
{{end}} {{end}}
{{if .Repository.EnableUnit $.UnitTypeReleases}} {{if and (.Repository.EnableUnit $.UnitTypeReleases) (not .IsBareRepo) }}
<a class="{{if .PageIsReleaseList}}active{{end}} item" href="{{.RepoLink}}/releases"> <a class="{{if .PageIsReleaseList}}active{{end}} item" href="{{.RepoLink}}/releases">
<i class="octicon octicon-tag"></i> {{.i18n.Tr "repo.releases"}} <span class="ui {{if not .Repository.NumTags}}gray{{else}}blue{{end}} small label">{{.Repository.NumTags}}</span> <i class="octicon octicon-tag"></i> {{.i18n.Tr "repo.releases"}} <span class="ui {{if not .Repository.NumTags}}gray{{else}}blue{{end}} small label">{{.Repository.NumTags}}</span>
</a> </a>