aboutsummaryrefslogtreecommitdiffstats
path: root/modules/context/repo.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-05-08 17:36:54 +0800
committerGitHub <noreply@github.com>2023-05-08 17:36:54 +0800
commitcb700aedd1e670fb47b8cf0cd67fb117a1ad88a2 (patch)
tree90cdc8e732b1c498bf5113accad8dc4245a059ac /modules/context/repo.go
parentff5629268c5c01d3f460570baa571baef3f896cd (diff)
downloadgitea-cb700aedd1e670fb47b8cf0cd67fb117a1ad88a2.tar.gz
gitea-cb700aedd1e670fb47b8cf0cd67fb117a1ad88a2.zip
Split "modules/context.go" to separate files (#24569)
The "modules/context.go" is too large to maintain. This PR splits it to separate files, eg: context_request.go, context_response.go, context_serve.go This PR will help: 1. The future refactoring for Gitea's web context (eg: simplify the context) 2. Introduce proper "range request" support 3. Introduce context function This PR only moves code, doesn't change any logic.
Diffstat (limited to 'modules/context/repo.go')
-rw-r--r--modules/context/repo.go88
1 files changed, 0 insertions, 88 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index a1c8f43644..b33341c245 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -25,7 +25,6 @@ import (
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
code_indexer "code.gitea.io/gitea/modules/indexer/code"
- "code.gitea.io/gitea/modules/issue/template"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -1063,59 +1062,6 @@ func UnitTypes() func(ctx *Context) {
}
}
-// IssueTemplatesFromDefaultBranch checks for valid issue templates in the repo's default branch,
-func (ctx *Context) IssueTemplatesFromDefaultBranch() []*api.IssueTemplate {
- ret, _ := ctx.IssueTemplatesErrorsFromDefaultBranch()
- return ret
-}
-
-// IssueTemplatesErrorsFromDefaultBranch checks for issue templates in the repo's default branch,
-// returns valid templates and the errors of invalid template files.
-func (ctx *Context) IssueTemplatesErrorsFromDefaultBranch() ([]*api.IssueTemplate, map[string]error) {
- var issueTemplates []*api.IssueTemplate
-
- if ctx.Repo.Repository.IsEmpty {
- return issueTemplates, nil
- }
-
- if ctx.Repo.Commit == nil {
- var err error
- ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
- if err != nil {
- return issueTemplates, nil
- }
- }
-
- invalidFiles := map[string]error{}
- for _, dirName := range IssueTemplateDirCandidates {
- tree, err := ctx.Repo.Commit.SubTree(dirName)
- if err != nil {
- log.Debug("get sub tree of %s: %v", dirName, err)
- continue
- }
- entries, err := tree.ListEntries()
- if err != nil {
- log.Debug("list entries in %s: %v", dirName, err)
- return issueTemplates, nil
- }
- for _, entry := range entries {
- if !template.CouldBe(entry.Name()) {
- continue
- }
- fullName := path.Join(dirName, entry.Name())
- if it, err := template.UnmarshalFromEntry(entry, dirName); err != nil {
- invalidFiles[fullName] = err
- } else {
- if !strings.HasPrefix(it.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/<ref>
- it.Ref = git.BranchPrefix + it.Ref
- }
- issueTemplates = append(issueTemplates, it)
- }
- }
- }
- return issueTemplates, invalidFiles
-}
-
func GetDefaultIssueConfig() api.IssueConfig {
return api.IssueConfig{
BlankIssuesEnabled: true,
@@ -1177,31 +1123,6 @@ func (r *Repository) GetIssueConfig(path string, commit *git.Commit) (api.IssueC
return issueConfig, nil
}
-// IssueConfigFromDefaultBranch returns the issue config for this repo.
-// It never returns a nil config.
-func (ctx *Context) IssueConfigFromDefaultBranch() (api.IssueConfig, error) {
- if ctx.Repo.Repository.IsEmpty {
- return GetDefaultIssueConfig(), nil
- }
-
- commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
- if err != nil {
- return GetDefaultIssueConfig(), err
- }
-
- for _, configName := range IssueConfigCandidates {
- if _, err := commit.GetTreeEntryByPath(configName + ".yaml"); err == nil {
- return ctx.Repo.GetIssueConfig(configName+".yaml", commit)
- }
-
- if _, err := commit.GetTreeEntryByPath(configName + ".yml"); err == nil {
- return ctx.Repo.GetIssueConfig(configName+".yml", commit)
- }
- }
-
- return GetDefaultIssueConfig(), nil
-}
-
// IsIssueConfig returns if the given path is a issue config file.
func (r *Repository) IsIssueConfig(path string) bool {
for _, configName := range IssueConfigCandidates {
@@ -1211,12 +1132,3 @@ func (r *Repository) IsIssueConfig(path string) bool {
}
return false
}
-
-func (ctx *Context) HasIssueTemplatesOrContactLinks() bool {
- if len(ctx.IssueTemplatesFromDefaultBranch()) > 0 {
- return true
- }
-
- issueConfig, _ := ctx.IssueConfigFromDefaultBranch()
- return len(issueConfig.ContactLinks) > 0
-}