summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-02-20 14:12:15 -0500
committerUnknwon <u@gogs.io>2016-02-20 14:12:15 -0500
commita703f7d7b42ec1d5190a84835379aba2f2d3250f (patch)
tree4be969388ba739491c11eb3e14b9b9c93936c711 /routers
parentb7f3d94cd048cbad6bc406bcbd79b490ccd416a9 (diff)
parent658bfc2704eb7630911b5a3c994258757dd79cec (diff)
downloadgitea-a703f7d7b42ec1d5190a84835379aba2f2d3250f.tar.gz
gitea-a703f7d7b42ec1d5190a84835379aba2f2d3250f.zip
Merge pull request #2647 from andreynering/issue-template
Implement issue and pull request templates
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/issue.go48
-rw-r--r--routers/repo/pull.go11
2 files changed, 59 insertions, 0 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 400da72029..1d747d2f7e 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -7,6 +7,8 @@ package repo
import (
"errors"
"fmt"
+ "io"
+ "io/ioutil"
"net/http"
"net/url"
"strings"
@@ -34,11 +36,19 @@ const (
MILESTONE base.TplName = "repo/issue/milestones"
MILESTONE_NEW base.TplName = "repo/issue/milestone_new"
MILESTONE_EDIT base.TplName = "repo/issue/milestone_edit"
+
+ ISSUE_TEMPLATE_KEY = "IssueTemplate"
)
var (
ErrFileTypeForbidden = errors.New("File type is not allowed")
ErrTooManyFiles = errors.New("Maximum number of files to upload exceeded")
+
+ IssueTemplateCandidates = []string{
+ "ISSUE_TEMPLATE.md",
+ ".gogs/ISSUE_TEMPLATE.md",
+ ".github/ISSUE_TEMPLATE.md",
+ }
)
func MustEnableIssues(ctx *middleware.Context) {
@@ -281,9 +291,47 @@ func RetrieveRepoMetas(ctx *middleware.Context, repo *models.Repository) []*mode
return labels
}
+func getFileContentFromDefaultBranch(ctx *middleware.Context, filename string) (string, bool) {
+ var r io.Reader
+ var bytes []byte
+
+ if ctx.Repo.Commit == nil {
+ var err error
+ ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
+ if err != nil {
+ return "", false
+ }
+ }
+
+ entry, err := ctx.Repo.Commit.GetTreeEntryByPath(filename)
+ if err != nil {
+ return "", false
+ }
+ r, err = entry.Blob().Data()
+ if err != nil {
+ return "", false
+ }
+ bytes, err = ioutil.ReadAll(r)
+ if err != nil {
+ return "", false
+ }
+ return string(bytes), true
+}
+
+func setTemplateIfExists(ctx *middleware.Context, ctxDataKey string, possibleFiles []string) {
+ for _, filename := range possibleFiles {
+ content, found := getFileContentFromDefaultBranch(ctx, filename)
+ if found {
+ ctx.Data[ctxDataKey] = content
+ return
+ }
+ }
+}
+
func NewIssue(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.issues.new")
ctx.Data["PageIsIssueList"] = true
+ setTemplateIfExists(ctx, ISSUE_TEMPLATE_KEY, IssueTemplateCandidates)
renderAttachmentSettings(ctx)
RetrieveRepoMetas(ctx, ctx.Repo.Repository)
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 3240461c84..cf8c4829b4 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -26,6 +26,16 @@ const (
COMPARE_PULL base.TplName = "repo/pulls/compare"
PULL_COMMITS base.TplName = "repo/pulls/commits"
PULL_FILES base.TplName = "repo/pulls/files"
+
+ PULL_REQUEST_TEMPLATE_KEY = "PullRequestTemplate"
+)
+
+var (
+ PullRequestTemplateCandidates = []string{
+ "PULL_REQUEST.md",
+ ".gogs/PULL_REQUEST.md",
+ ".github/PULL_REQUEST.md",
+ }
)
func getForkRepository(ctx *middleware.Context) *models.Repository {
@@ -540,6 +550,7 @@ func CompareAndPullRequest(ctx *middleware.Context) {
ctx.Data["PageIsComparePull"] = true
ctx.Data["IsDiffCompare"] = true
ctx.Data["RequireHighlightJS"] = true
+ setTemplateIfExists(ctx, PULL_REQUEST_TEMPLATE_KEY, PullRequestTemplateCandidates)
renderAttachmentSettings(ctx)
headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx)