mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-13 14:27:17 +00:00
feat: search in the docs
directory for issue and pull request templates (#8863)
For pull request templates, Forgejo currently does not look in the `docs` directory, but [GitHub does](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/creating-a-pull-request-template-for-your-repository#adding-a-pull-request-template). By making Forgejo also look there, it becomes possible to have the same repository work on both sites, without the need for vendor-specific paths. There was duplication in the list of accepted file paths. On the one hand it’s nice for greppability that they are all spelled out, but it does mean adding 6 variants, I thought it would be more maintainable to deduplicate the Cartesian product. I added one fully spelled out path in the comment to still maintain some greppability. Resolves forgejo/forgejo#8284 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8863 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Ruud van Asseldonk <dev@veniogames.com> Co-committed-by: Ruud van Asseldonk <dev@veniogames.com>
This commit is contained in:
parent
0606f05707
commit
995dba14ec
6 changed files with 50 additions and 54 deletions
|
@ -76,34 +76,27 @@ const (
|
||||||
issueTemplateTitleKey = "IssueTemplateTitle"
|
issueTemplateTitleKey = "IssueTemplateTitle"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IssueTemplateCandidates issue templates
|
// generateIssueTemplateLocations generates all the file paths where we
|
||||||
var IssueTemplateCandidates = []string{
|
// look for an issue template, e.g. ".forgejo/ISSUE_TEMPLATE.md".
|
||||||
"ISSUE_TEMPLATE.md",
|
func generateIssueTemplateLocations() []string {
|
||||||
"ISSUE_TEMPLATE.yaml",
|
var result []string
|
||||||
"ISSUE_TEMPLATE.yml",
|
prefixes := []string{"", ".forgejo/", ".gitea/", ".github/", "docs/"}
|
||||||
"issue_template.md",
|
filenames := []string{"ISSUE_TEMPLATE", "issue_template"}
|
||||||
"issue_template.yaml",
|
extensions := []string{".md", ".yaml", ".yml"}
|
||||||
"issue_template.yml",
|
|
||||||
".forgejo/ISSUE_TEMPLATE.md",
|
for _, prefix := range prefixes {
|
||||||
".forgejo/ISSUE_TEMPLATE.yaml",
|
for _, filename := range filenames {
|
||||||
".forgejo/ISSUE_TEMPLATE.yml",
|
for _, extension := range extensions {
|
||||||
".forgejo/issue_template.md",
|
result = append(result, prefix+filename+extension)
|
||||||
".forgejo/issue_template.yaml",
|
}
|
||||||
".forgejo/issue_template.yml",
|
}
|
||||||
".gitea/ISSUE_TEMPLATE.md",
|
}
|
||||||
".gitea/ISSUE_TEMPLATE.yaml",
|
|
||||||
".gitea/ISSUE_TEMPLATE.yml",
|
return result
|
||||||
".gitea/issue_template.md",
|
|
||||||
".gitea/issue_template.yaml",
|
|
||||||
".gitea/issue_template.yml",
|
|
||||||
".github/ISSUE_TEMPLATE.md",
|
|
||||||
".github/ISSUE_TEMPLATE.yaml",
|
|
||||||
".github/ISSUE_TEMPLATE.yml",
|
|
||||||
".github/issue_template.md",
|
|
||||||
".github/issue_template.yaml",
|
|
||||||
".github/issue_template.yml",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var issueTemplateCandidates = generateIssueTemplateLocations()
|
||||||
|
|
||||||
// MustAllowUserComment checks to make sure if an issue is locked.
|
// MustAllowUserComment checks to make sure if an issue is locked.
|
||||||
// If locked and user has permissions to write to the repository,
|
// If locked and user has permissions to write to the repository,
|
||||||
// then the comment is allowed, else it is blocked
|
// then the comment is allowed, else it is blocked
|
||||||
|
@ -1005,7 +998,7 @@ func NewIssue(ctx *context.Context) {
|
||||||
ctx.Data["Tags"] = tags
|
ctx.Data["Tags"] = tags
|
||||||
|
|
||||||
_, templateErrs := issue_service.GetTemplatesFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo)
|
_, templateErrs := issue_service.GetTemplatesFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo)
|
||||||
templateLoaded, errs := setTemplateIfExists(ctx, issueTemplateKey, IssueTemplateCandidates)
|
templateLoaded, errs := setTemplateIfExists(ctx, issueTemplateKey, issueTemplateCandidates)
|
||||||
for k, v := range errs {
|
for k, v := range errs {
|
||||||
templateErrs[k] = v
|
templateErrs[k] = v
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,33 +66,27 @@ const (
|
||||||
pullRequestTemplateKey = "PullRequestTemplate"
|
pullRequestTemplateKey = "PullRequestTemplate"
|
||||||
)
|
)
|
||||||
|
|
||||||
var pullRequestTemplateCandidates = []string{
|
// generatePullRequestTemplateLocations generates all the file paths where we
|
||||||
"PULL_REQUEST_TEMPLATE.md",
|
// look for a pull request template, e.g. ".forgejo/PULL_REQUEST_TEMPLATE.md".
|
||||||
"PULL_REQUEST_TEMPLATE.yaml",
|
func generatePullRequestTemplateLocations() []string {
|
||||||
"PULL_REQUEST_TEMPLATE.yml",
|
var result []string
|
||||||
"pull_request_template.md",
|
prefixes := []string{"", ".forgejo/", ".gitea/", ".github/", "docs/"}
|
||||||
"pull_request_template.yaml",
|
filenames := []string{"PULL_REQUEST_TEMPLATE", "pull_request_template"}
|
||||||
"pull_request_template.yml",
|
extensions := []string{".md", ".yaml", ".yml"}
|
||||||
".forgejo/PULL_REQUEST_TEMPLATE.md",
|
|
||||||
".forgejo/PULL_REQUEST_TEMPLATE.yaml",
|
for _, prefix := range prefixes {
|
||||||
".forgejo/PULL_REQUEST_TEMPLATE.yml",
|
for _, filename := range filenames {
|
||||||
".forgejo/pull_request_template.md",
|
for _, extension := range extensions {
|
||||||
".forgejo/pull_request_template.yaml",
|
result = append(result, prefix+filename+extension)
|
||||||
".forgejo/pull_request_template.yml",
|
}
|
||||||
".gitea/PULL_REQUEST_TEMPLATE.md",
|
}
|
||||||
".gitea/PULL_REQUEST_TEMPLATE.yaml",
|
}
|
||||||
".gitea/PULL_REQUEST_TEMPLATE.yml",
|
|
||||||
".gitea/pull_request_template.md",
|
return result
|
||||||
".gitea/pull_request_template.yaml",
|
|
||||||
".gitea/pull_request_template.yml",
|
|
||||||
".github/PULL_REQUEST_TEMPLATE.md",
|
|
||||||
".github/PULL_REQUEST_TEMPLATE.yaml",
|
|
||||||
".github/PULL_REQUEST_TEMPLATE.yml",
|
|
||||||
".github/pull_request_template.md",
|
|
||||||
".github/pull_request_template.yaml",
|
|
||||||
".github/pull_request_template.yml",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pullRequestTemplateCandidates = generatePullRequestTemplateLocations()
|
||||||
|
|
||||||
func getRepository(ctx *context.Context, repoID int64) *repo_model.Repository {
|
func getRepository(ctx *context.Context, repoID int64) *repo_model.Repository {
|
||||||
repo, err := repo_model.GetRepositoryByID(ctx, repoID)
|
repo, err := repo_model.GetRepositoryByID(ctx, repoID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -31,6 +31,8 @@ var templateDirCandidates = []string{
|
||||||
".github/issue_template",
|
".github/issue_template",
|
||||||
".gitlab/ISSUE_TEMPLATE",
|
".gitlab/ISSUE_TEMPLATE",
|
||||||
".gitlab/issue_template",
|
".gitlab/issue_template",
|
||||||
|
"docs/ISSUE_TEMPLATE",
|
||||||
|
"docs/issue_template",
|
||||||
}
|
}
|
||||||
|
|
||||||
var templateConfigCandidates = []string{
|
var templateConfigCandidates = []string{
|
||||||
|
@ -40,6 +42,8 @@ var templateConfigCandidates = []string{
|
||||||
".gitea/issue_template/config",
|
".gitea/issue_template/config",
|
||||||
".github/ISSUE_TEMPLATE/config",
|
".github/ISSUE_TEMPLATE/config",
|
||||||
".github/issue_template/config",
|
".github/issue_template/config",
|
||||||
|
"docs/ISSUE_TEMPLATE/config",
|
||||||
|
"docs/issue_template/config",
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDefaultTemplateConfig() api.IssueConfig {
|
func GetDefaultTemplateConfig() api.IssueConfig {
|
||||||
|
|
|
@ -133,6 +133,7 @@ func TestAPIRepoIssueConfigPaths(t *testing.T) {
|
||||||
".gitea/issue_template/config",
|
".gitea/issue_template/config",
|
||||||
".github/ISSUE_TEMPLATE/config",
|
".github/ISSUE_TEMPLATE/config",
|
||||||
".github/issue_template/config",
|
".github/issue_template/config",
|
||||||
|
"docs/issue_template/config",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, candidate := range templateConfigCandidates {
|
for _, candidate := range templateConfigCandidates {
|
||||||
|
@ -184,7 +185,7 @@ func TestAPIRepoValidateIssueConfig(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Invalid", func(t *testing.T) {
|
t.Run("Invalid", func(t *testing.T) {
|
||||||
dirs := []string{".gitea", ".forgejo"}
|
dirs := []string{".gitea", ".forgejo", "docs"}
|
||||||
for _, dir := range dirs {
|
for _, dir := range dirs {
|
||||||
t.Run(dir, func(t *testing.T) {
|
t.Run(dir, func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
|
@ -42,6 +42,7 @@ func TestAPIIssueTemplateList(t *testing.T) {
|
||||||
".gitea/issue_template/test.md",
|
".gitea/issue_template/test.md",
|
||||||
".github/ISSUE_TEMPLATE/test.md",
|
".github/ISSUE_TEMPLATE/test.md",
|
||||||
".github/issue_template/test.md",
|
".github/issue_template/test.md",
|
||||||
|
"docs/issue_template/test.md",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, template := range templateCandidates {
|
for _, template := range templateCandidates {
|
||||||
|
@ -79,6 +80,7 @@ This is the template!`)
|
||||||
".forgejo/issue_template/test.md",
|
".forgejo/issue_template/test.md",
|
||||||
".gitea/issue_template/test.md",
|
".gitea/issue_template/test.md",
|
||||||
".github/issue_template/test.md",
|
".github/issue_template/test.md",
|
||||||
|
"docs/issue_template/test.md",
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, template := range templatePriority {
|
for _, template := range templatePriority {
|
||||||
|
@ -107,7 +109,7 @@ This is the template!`)
|
||||||
// If templates have the same filename and content, but in different
|
// If templates have the same filename and content, but in different
|
||||||
// directories, they count as different templates, and all are
|
// directories, they count as different templates, and all are
|
||||||
// considered.
|
// considered.
|
||||||
assert.Len(t, issueTemplates, 3)
|
assert.Len(t, issueTemplates, 4)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,6 +136,8 @@ func TestPullCreateWithPullTemplate(t *testing.T) {
|
||||||
".gitea/pull_request_template.md",
|
".gitea/pull_request_template.md",
|
||||||
".github/PULL_REQUEST_TEMPLATE.md",
|
".github/PULL_REQUEST_TEMPLATE.md",
|
||||||
".github/pull_request_template.md",
|
".github/pull_request_template.md",
|
||||||
|
"docs/pull_request_template.md",
|
||||||
|
"docs/PULL_REQUEST_TEMPLATE.md",
|
||||||
}
|
}
|
||||||
|
|
||||||
createBaseRepo := func(t *testing.T, templateFiles []string, message string) (*repo_model.Repository, func()) {
|
createBaseRepo := func(t *testing.T, templateFiles []string, message string) (*repo_model.Repository, func()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue