From fac2cb64f2bbb0110218f41bc6e16b88b9a0a79a Mon Sep 17 00:00:00 2001 From: JakobDev Date: Thu, 25 Aug 2022 14:56:47 +0200 Subject: [PATCH 01/25] Allow disabling blank Issues --- modules/context/repo.go | 48 ++++++++++++++++++++++++++++++++ modules/structs/issue.go | 4 +++ routers/web/repo/issue.go | 4 +++ templates/repo/issue/choose.tmpl | 26 +++++++++++------ 4 files changed, 74 insertions(+), 8 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index 1e0f6461a28f..a3eb187e348b 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -35,6 +35,7 @@ import ( asymkey_service "code.gitea.io/gitea/services/asymkey" "github.com/editorconfig/editorconfig-core-go/v2" + "gopkg.in/yaml.v2" ) // IssueTemplateDirCandidates issue templates directory @@ -1100,3 +1101,50 @@ func (ctx *Context) IssueTemplatesFromDefaultBranch() []api.IssueTemplate { } return issueTemplates } + +func ExtractIssueConfigFromYaml(configContent []byte) (api.IssueConfig, error) { + config := api.IssueConfig{ + BlankIssuesEnabled: true, + } + + err := yaml.Unmarshal(configContent, &config) + if err != nil { + return api.IssueConfig{}, err + } + + return config, nil +} + +func (ctx *Context) IssueConfigFromDefaultBranch() (api.IssueConfig, error) { + defaultIssueConfig := api.IssueConfig{ + BlankIssuesEnabled: true, + } + + commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) + if err != nil { + return defaultIssueConfig, nil + } + + entry, err := commit.GetTreeEntryByPath(".gitea/issue_config.yaml") + if err != nil { + return defaultIssueConfig, nil + } + + r, err := entry.Blob().DataAsync() + if err != nil { + log.Debug("DataAsync: %v", err) + return defaultIssueConfig, nil + } + + configContent, err := io.ReadAll(r) + if err != nil { + return defaultIssueConfig, err + } + + issueConfig, err := ExtractIssueConfigFromYaml(configContent) + if err != nil { + return defaultIssueConfig, err + } + + return issueConfig, nil +} diff --git a/modules/structs/issue.go b/modules/structs/issue.go index c72487fe4dca..dcdac1b95777 100644 --- a/modules/structs/issue.go +++ b/modules/structs/issue.go @@ -132,6 +132,10 @@ type IssueTemplate struct { FileName string `json:"file_name" yaml:"-"` } +type IssueConfig struct { + BlankIssuesEnabled bool `json:"blank_issues_enabled" yaml:"blank_issues_enabled"` +} + // Valid checks whether an IssueTemplate is considered valid, e.g. at least name and about func (it IssueTemplate) Valid() bool { return strings.TrimSpace(it.Name) != "" && strings.TrimSpace(it.About) != "" diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 3f14416e4837..8b85d9b50a20 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -869,6 +869,10 @@ func NewIssueChooseTemplate(ctx *context.Context) { return } + issueConfig, err := ctx.IssueConfigFromDefaultBranch() + ctx.Data["IssueConfig"] = issueConfig + ctx.Data["IssueConfigError"] = err + ctx.Data["milestone"] = ctx.FormInt64("milestone") ctx.Data["project"] = ctx.FormInt64("project") diff --git a/templates/repo/issue/choose.tmpl b/templates/repo/issue/choose.tmpl index bbddd6d9a6ce..73272bd6f481 100644 --- a/templates/repo/issue/choose.tmpl +++ b/templates/repo/issue/choose.tmpl @@ -19,17 +19,27 @@ {{end}} -
-
-
- {{.locale.Tr "repo.issues.choose.blank"}} -
{{.locale.Tr "repo.issues.choose.blank_about"}} + {{if .IssueConfig.BlankIssuesEnabled}} +
+
+
+ {{.locale.Tr "repo.issues.choose.blank"}} +
{{.locale.Tr "repo.issues.choose.blank_about"}} +
+
- + {{end}} + {{- if .IssueConfigError}} +
+
+
Your issue_config.yaml contains a error:
+ {{.IssueConfigError}}
-
+ {{end}}
{{template "base/footer" .}} From adb916e8f6c4d6e2360b084c5a0b8652f8871a56 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 29 Aug 2022 11:30:52 +0200 Subject: [PATCH 02/25] Change supported paths --- modules/context/repo.go | 53 ++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index a3eb187e348b..32724adf586d 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -50,6 +50,21 @@ var IssueTemplateDirCandidates = []string{ ".gitlab/issue_template", } +var IssueConfigCanidates = []string{ + ".gitea/config.yaml", + ".gitea/config.yml", + ".gitea/ISSUE_TEMPLATE/config.yaml", + ".gitea/ISSUE_TEMPLATE/config.yml", + ".gitea/issue_template/config.yaml", + ".gitea/issue_template/config.yml", + ".github/config.yaml", + ".github/config.yml", + ".github/ISSUE_TEMPLATE/config.yaml", + ".github/ISSUE_TEMPLATE/config.yml", + ".github/issue_template/config.yaml", + ".github/issue_template/config.yml", +} + // PullRequest contains information to make a pull request type PullRequest struct { BaseRepo *repo_model.Repository @@ -1125,26 +1140,30 @@ func (ctx *Context) IssueConfigFromDefaultBranch() (api.IssueConfig, error) { return defaultIssueConfig, nil } - entry, err := commit.GetTreeEntryByPath(".gitea/issue_config.yaml") - if err != nil { - return defaultIssueConfig, nil - } + for _, configName := range IssueConfigCanidates { + entry, err := commit.GetTreeEntryByPath(configName) + if err != nil { + continue + } - r, err := entry.Blob().DataAsync() - if err != nil { - log.Debug("DataAsync: %v", err) - return defaultIssueConfig, nil - } + r, err := entry.Blob().DataAsync() + if err != nil { + log.Debug("DataAsync: %v", err) + return defaultIssueConfig, nil + } - configContent, err := io.ReadAll(r) - if err != nil { - return defaultIssueConfig, err - } + configContent, err := io.ReadAll(r) + if err != nil { + return defaultIssueConfig, err + } - issueConfig, err := ExtractIssueConfigFromYaml(configContent) - if err != nil { - return defaultIssueConfig, err + issueConfig, err := ExtractIssueConfigFromYaml(configContent) + if err != nil { + return defaultIssueConfig, err + } + + return issueConfig, nil } - return issueConfig, nil + return defaultIssueConfig, nil } From c7a8ee47c94620d79e334bc7475e25c74a232782 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 29 Aug 2022 16:53:51 +0200 Subject: [PATCH 03/25] Change config paths --- modules/context/repo.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index 32724adf586d..9ff573666a9c 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -51,14 +51,10 @@ var IssueTemplateDirCandidates = []string{ } var IssueConfigCanidates = []string{ - ".gitea/config.yaml", - ".gitea/config.yml", ".gitea/ISSUE_TEMPLATE/config.yaml", ".gitea/ISSUE_TEMPLATE/config.yml", ".gitea/issue_template/config.yaml", ".gitea/issue_template/config.yml", - ".github/config.yaml", - ".github/config.yml", ".github/ISSUE_TEMPLATE/config.yaml", ".github/ISSUE_TEMPLATE/config.yml", ".github/issue_template/config.yaml", From ecbbbe9bb626488274414d3bb118792a34fa8a99 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Fri, 2 Sep 2022 10:26:27 +0200 Subject: [PATCH 04/25] Fix bugs --- modules/context/repo.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/context/repo.go b/modules/context/repo.go index 3966a348c26b..29c98ae413b5 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -9,6 +9,7 @@ import ( "context" "fmt" "html" + "io" "net/http" "net/url" "path" @@ -1081,6 +1082,9 @@ func (ctx *Context) IssueTemplatesErrorsFromDefaultBranch() ([]*api.IssueTemplat return issueTemplates, nil } for _, entry := range entries { + if entry.Name() == "config.yaml" || entry.Name() == "config.yml" { + continue + } if !template.CouldBe(entry.Name()) { continue } From 7b4415bf61d6bdac0bda174212ec32ab835cf738 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Sun, 4 Sep 2022 20:47:48 +0200 Subject: [PATCH 05/25] Return error when getting default branch fails --- modules/context/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index 29c98ae413b5..31b7294232d9 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -1119,7 +1119,7 @@ func (ctx *Context) IssueConfigFromDefaultBranch() (api.IssueConfig, error) { commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) if err != nil { - return defaultIssueConfig, nil + return defaultIssueConfig, wee } for _, configName := range IssueConfigCanidates { From 146bd6b2c10d00356e0eb4680ed1bf5879cd9fa7 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 13 Dec 2022 13:02:18 +0100 Subject: [PATCH 06/25] Add documentation --- .../issue-pull-request-templates.en-us.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/content/doc/usage/issue-pull-request-templates.en-us.md b/docs/content/doc/usage/issue-pull-request-templates.en-us.md index 0cf63625b60d..7223948311e7 100644 --- a/docs/content/doc/usage/issue-pull-request-templates.en-us.md +++ b/docs/content/doc/usage/issue-pull-request-templates.en-us.md @@ -50,6 +50,18 @@ Possible file names for issue templates: - `.github/issue_template.yaml` - `.github/issue_template.yml` +Possible file names for issue config: + +- `.gitea/ISSUE_TEMPLATE/config.yaml` +- `.gitea/ISSUE_TEMPLATE/config.yml` +- `.gitea/issue_template/config.yaml` +- `.gitea/issue_template/config.yaml` +- `.gitea/issue_template/config.yml` +- `.github/ISSUE_TEMPLATE/config.yaml` +- `.github/ISSUE_TEMPLATE/config.yml` +- `.github/issue_template/config.yaml` +- `.github/issue_template/config.yml` + Possible file names for PR templates: - `PULL_REQUEST_TEMPLATE.md` @@ -267,3 +279,17 @@ For each value in the options array, you can set the following keys. |----------|------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------|---------| | label | The identifier for the option, which is displayed in the form. Markdown is supported for bold or italic text formatting, and hyperlinks. | Required | String | - | - | | required | Prevents form submission until element is completed. | Optional | Boolean | false | - | + +## Syntax for issue config + +This is a example for a issue config file + +```yaml +BlankIssuesEnabled: true +``` + +### Possible Options + +| Key | Description | Type | +|--------------------|-------------------------------------------------------------------------------------------------------|---------| +| BalnkIssuesEnabled | If set to false, the User is forced to use a Template | Boolean | From bb72aea04b765199af119f547957c2094e2b7313 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 20 Dec 2022 15:06:38 +0100 Subject: [PATCH 07/25] Refactor code --- .../issue-pull-request-templates.en-us.md | 6 +- modules/context/repo.go | 90 ++++++++++--------- routers/web/repo/view.go | 3 + 3 files changed, 56 insertions(+), 43 deletions(-) diff --git a/docs/content/doc/usage/issue-pull-request-templates.en-us.md b/docs/content/doc/usage/issue-pull-request-templates.en-us.md index 7223948311e7..e9871d2ce867 100644 --- a/docs/content/doc/usage/issue-pull-request-templates.en-us.md +++ b/docs/content/doc/usage/issue-pull-request-templates.en-us.md @@ -290,6 +290,6 @@ BlankIssuesEnabled: true ### Possible Options -| Key | Description | Type | -|--------------------|-------------------------------------------------------------------------------------------------------|---------| -| BalnkIssuesEnabled | If set to false, the User is forced to use a Template | Boolean | +| Key | Description | Type | +|----------------------|-------------------------------------------------------------------------------------------------------|---------| +| blank_issues_enabled | If set to false, the User is forced to use a Template | Boolean | diff --git a/modules/context/repo.go b/modules/context/repo.go index 620fd74fe0b7..421c19443c67 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -34,7 +34,7 @@ import ( asymkey_service "code.gitea.io/gitea/services/asymkey" "github.com/editorconfig/editorconfig-core-go/v2" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) // IssueTemplateDirCandidates issue templates directory @@ -50,14 +50,10 @@ var IssueTemplateDirCandidates = []string{ } var IssueConfigCanidates = []string{ - ".gitea/ISSUE_TEMPLATE/config.yaml", - ".gitea/ISSUE_TEMPLATE/config.yml", - ".gitea/issue_template/config.yaml", - ".gitea/issue_template/config.yml", - ".github/ISSUE_TEMPLATE/config.yaml", - ".github/ISSUE_TEMPLATE/config.yml", - ".github/issue_template/config.yaml", - ".github/issue_template/config.yml", + ".gitea/ISSUE_TEMPLATE/config", + ".gitea/issue_template/config", + ".github/ISSUE_TEMPLATE/config", + ".github/issue_template/config", } // PullRequest contains information to make a pull request @@ -1094,9 +1090,6 @@ func (ctx *Context) IssueTemplatesErrorsFromDefaultBranch() ([]*api.IssueTemplat return issueTemplates, nil } for _, entry := range entries { - if entry.Name() == "config.yaml" || entry.Name() == "config.yml" { - continue - } if !template.CouldBe(entry.Name()) { continue } @@ -1114,53 +1107,70 @@ func (ctx *Context) IssueTemplatesErrorsFromDefaultBranch() ([]*api.IssueTemplat return issueTemplates, invalidFiles } -func ExtractIssueConfigFromYaml(configContent []byte) (api.IssueConfig, error) { - config := api.IssueConfig{ + +func GetDefaultIssueConfig() (api.IssueConfig) { + return api.IssueConfig{ BlankIssuesEnabled: true, } +} + +func (r *Repository) GetIssueConfig(path string, commit *git.Commit) (api.IssueConfig, error) { + if r.GitRepo == nil { + return GetDefaultIssueConfig(), nil + } + + var err error - err := yaml.Unmarshal(configContent, &config) + treeEntry, err := commit.GetTreeEntryByPath(path) if err != nil { - return api.IssueConfig{}, err + return GetDefaultIssueConfig(), err } - return config, nil -} + reader, err := treeEntry.Blob().DataAsync() + if err != nil { + log.Debug("DataAsync: %v", err) + return GetDefaultIssueConfig(), nil + } -func (ctx *Context) IssueConfigFromDefaultBranch() (api.IssueConfig, error) { - defaultIssueConfig := api.IssueConfig{ - BlankIssuesEnabled: true, + configContent, err := io.ReadAll(reader) + if err != nil { + return GetDefaultIssueConfig(), err + } + + issueConfig := api.IssueConfig{} + if err := yaml.Unmarshal(configContent, &issueConfig); err != nil { + return GetDefaultIssueConfig(), err } + return issueConfig, nil +} + +func (ctx *Context) IssueConfigFromDefaultBranch() (api.IssueConfig, error) { commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) if err != nil { - return defaultIssueConfig, wee + return GetDefaultIssueConfig(), err } for _, configName := range IssueConfigCanidates { - entry, err := commit.GetTreeEntryByPath(configName) - if err != nil { - continue + _, err := commit.GetTreeEntryByPath(configName + ".yaml") + if err == nil { + return ctx.Repo.GetIssueConfig(configName + ".yaml", commit) } - r, err := entry.Blob().DataAsync() - if err != nil { - log.Debug("DataAsync: %v", err) - return defaultIssueConfig, nil + _, err2 := commit.GetTreeEntryByPath(configName + ".yml") + if err2 == nil { + return ctx.Repo.GetIssueConfig(configName + ".yml", commit) } + } - configContent, err := io.ReadAll(r) - if err != nil { - return defaultIssueConfig, err - } + return GetDefaultIssueConfig(), nil +} - issueConfig, err := ExtractIssueConfigFromYaml(configContent) - if err != nil { - return defaultIssueConfig, err +func (r *Repository) IsIssueConfig(path string) (bool) { + for _, configName := range IssueConfigCanidates { + if path == configName + ".yaml" || path == configName + ".yml" { + return true } - - return issueConfig, nil } - - return defaultIssueConfig, nil + return false } diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index fa4eb6d61f2c..fb3a2b5d0500 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -379,6 +379,9 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st if ctx.Repo.TreePath == ".editorconfig" { _, editorconfigErr := ctx.Repo.GetEditorconfig(ctx.Repo.Commit) ctx.Data["FileError"] = editorconfigErr + } else if ctx.Repo.IsIssueConfig(ctx.Repo.TreePath) { + _, issueConfigErr := ctx.Repo.GetIssueConfig(ctx.Repo.TreePath, ctx.Repo.Commit) + ctx.Data["FileError"] = issueConfigErr } buf := make([]byte, 1024) From 8624c968fdd823e9acbe9b7660265edfeedd6154 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 26 Dec 2022 11:16:57 +0100 Subject: [PATCH 08/25] Improve documentation --- .../doc/usage/issue-pull-request-templates.en-us.md | 8 ++++---- modules/context/repo.go | 5 +++++ routers/web/repo/issue.go | 2 +- templates/repo/issue/choose.tmpl | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/content/doc/usage/issue-pull-request-templates.en-us.md b/docs/content/doc/usage/issue-pull-request-templates.en-us.md index e9871d2ce867..12b80906415e 100644 --- a/docs/content/doc/usage/issue-pull-request-templates.en-us.md +++ b/docs/content/doc/usage/issue-pull-request-templates.en-us.md @@ -285,11 +285,11 @@ For each value in the options array, you can set the following keys. This is a example for a issue config file ```yaml -BlankIssuesEnabled: true +blank_issues_enabled: true ``` ### Possible Options -| Key | Description | Type | -|----------------------|-------------------------------------------------------------------------------------------------------|---------| -| blank_issues_enabled | If set to false, the User is forced to use a Template | Boolean | +| Key | Description | Type | Default | +|----------------------|-------------------------------------------------------------------------------------------------------|---------|---------| +| blank_issues_enabled | If set to false, the User is forced to use a Template | Boolean | true | diff --git a/modules/context/repo.go b/modules/context/repo.go index 421c19443c67..795b53b37d11 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -1114,6 +1114,8 @@ func GetDefaultIssueConfig() (api.IssueConfig) { } } +// GetIssueConfig loads the given issue config file. +// It never returns a nil config. func (r *Repository) GetIssueConfig(path string, commit *git.Commit) (api.IssueConfig, error) { if r.GitRepo == nil { return GetDefaultIssueConfig(), nil @@ -1145,6 +1147,8 @@ 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) { commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) if err != nil { @@ -1166,6 +1170,7 @@ func (ctx *Context) IssueConfigFromDefaultBranch() (api.IssueConfig, error) { return GetDefaultIssueConfig(), nil } +// IsIssueConfig returns if the given path is a issue config file. func (r *Repository) IsIssueConfig(path string) (bool) { for _, configName := range IssueConfigCanidates { if path == configName + ".yaml" || path == configName + ".yml" { diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index f002bd1ea8e0..778adb6e5783 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -906,7 +906,7 @@ func NewIssueChooseTemplate(ctx *context.Context) { issueConfig, err := ctx.IssueConfigFromDefaultBranch() ctx.Data["IssueConfig"] = issueConfig - ctx.Data["IssueConfigError"] = err + ctx.Data["IssueConfigError"] = err // ctx.Flash.Err makes problems here ctx.Data["milestone"] = ctx.FormInt64("milestone") ctx.Data["project"] = ctx.FormInt64("project") diff --git a/templates/repo/issue/choose.tmpl b/templates/repo/issue/choose.tmpl index 0ecf3f6d4a03..c7d1b4bcf5d6 100644 --- a/templates/repo/issue/choose.tmpl +++ b/templates/repo/issue/choose.tmpl @@ -33,7 +33,7 @@ {{end}} - {{- if .IssueConfigError}} + {{- if .IssueConfigError}}{{/* normal warning flash makes problems here*/}}
Your issue_config.yaml contains a error:
From 714e92e83bcd035431cee2d1d94476ef329647f9 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 2 Jan 2023 22:40:46 +0100 Subject: [PATCH 09/25] Add API --- routers/api/v1/api.go | 1 + routers/api/v1/repo/repo.go | 14 ++++++++++ templates/swagger/v1_json.tmpl | 50 ++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 82ff7ae0befc..f6363f7f0586 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1088,6 +1088,7 @@ func Routes(ctx gocontext.Context) *web.Route { }, reqAdmin()) }, reqAnyRepoReader()) m.Get("/issue_templates", context.ReferencesGitRepo(), repo.GetIssueTemplates) + m.Get("/issue_config", context.ReferencesGitRepo(), repo.GetIssueConfig) m.Get("/languages", reqRepoReader(unit.TypeCode), repo.GetLanguages) }, repoAssignment()) }) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 349040507810..aa049c4d9992 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -1095,3 +1095,17 @@ func GetIssueTemplates(ctx *context.APIContext) { ctx.JSON(http.StatusOK, ctx.IssueTemplatesFromDefaultBranch()) } + +// GetIssueConfig returns the issue config for a repo +func GetIssueConfig(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/issue_config repository repoGetIssueConfig + // --- + // summary: Returns the issue config for a repo + // produces: + // - application/json + // responses: + // "200": + // "$ref": "#/responses/IssueConfig" + issueConfig, _ := ctx.IssueConfigFromDefaultBranch() + ctx.JSON(http.StatusOK, issueConfig) +} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index c86c6744deec..c2f3bee7db94 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -4716,6 +4716,39 @@ } } } + }, + "/repos/{owner}/{repo}/issue_config": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Returns the issue config for a repo", + "operationId": "repoGetIssueConfig", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/IssueConfig" + } + } + } }, "/repos/{owner}/{repo}/issues": { "get": { @@ -17419,6 +17452,17 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "IssueConfig": { + "description": "IssueConfig represents an issue config for a repository", + "type": "object", + "properties": { + "blank_issues_enabled": { + "type": "boolean", + "x-go-name": "BlankIssuesEnabled" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "MarkdownOption": { "description": "MarkdownOption markdown options", "type": "object", @@ -20201,6 +20245,12 @@ } } }, + "IssueConfig": { + "description": "IssueConfig", + "schema": { + "$ref": "#/definitions/IssueConfig" + } + }, "Label": { "description": "Label", "schema": { From 18fe929d72df68fd1ba7569d733b7d4869572af3 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 2 Jan 2023 22:49:18 +0100 Subject: [PATCH 10/25] Make error text translatable --- options/locale/locale_en-US.ini | 1 + templates/repo/issue/choose.tmpl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 70f982b8dcc5..b937f431b2fb 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1256,6 +1256,7 @@ issues.choose.blank = Default issues.choose.blank_about = Create an issue from default template. issues.choose.ignore_invalid_templates = Invalid templates have been ignored issues.choose.invalid_templates = %v invalid template(s) found +issues.choose.invalid_config = Your issue_config.yaml contains a error: issues.no_ref = No Branch/Tag Specified issues.create = Create Issue issues.new_label = New Label diff --git a/templates/repo/issue/choose.tmpl b/templates/repo/issue/choose.tmpl index c7d1b4bcf5d6..e2714c41f339 100644 --- a/templates/repo/issue/choose.tmpl +++ b/templates/repo/issue/choose.tmpl @@ -36,7 +36,7 @@ {{- if .IssueConfigError}}{{/* normal warning flash makes problems here*/}}
-
Your issue_config.yaml contains a error:
+
{{.locale.Tr "repo.issues.choose.invalid_config"}}
{{.IssueConfigError}}
From 099def70f72aba364e387494486751ac57fa325c Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 9 Jan 2023 15:49:20 +0100 Subject: [PATCH 11/25] Apply suggestion from wolfogre Co-authored-by: Jason Song --- modules/context/repo.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index 795b53b37d11..1eac94d81204 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -1156,13 +1156,11 @@ func (ctx *Context) IssueConfigFromDefaultBranch() (api.IssueConfig, error) { } for _, configName := range IssueConfigCanidates { - _, err := commit.GetTreeEntryByPath(configName + ".yaml") - if err == nil { + if _, err := commit.GetTreeEntryByPath(configName + ".yaml"); err == nil { return ctx.Repo.GetIssueConfig(configName + ".yaml", commit) } - _, err2 := commit.GetTreeEntryByPath(configName + ".yml") - if err2 == nil { + if _, err := commit.GetTreeEntryByPath(configName + ".yml"); err == nil { return ctx.Repo.GetIssueConfig(configName + ".yml", commit) } } From 5ae2ed0d57ef24498afbd086128f34d43add8d34 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 23 Jan 2023 19:09:50 +0100 Subject: [PATCH 12/25] Fix linting --- modules/context/repo.go | 11 +++++------ routers/web/repo/issue.go | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index a4a6845f38cc..a0519086202a 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -1108,8 +1108,7 @@ func (ctx *Context) IssueTemplatesErrorsFromDefaultBranch() ([]*api.IssueTemplat return issueTemplates, invalidFiles } - -func GetDefaultIssueConfig() (api.IssueConfig) { +func GetDefaultIssueConfig() api.IssueConfig { return api.IssueConfig{ BlankIssuesEnabled: true, } @@ -1158,11 +1157,11 @@ func (ctx *Context) IssueConfigFromDefaultBranch() (api.IssueConfig, error) { for _, configName := range IssueConfigCanidates { if _, err := commit.GetTreeEntryByPath(configName + ".yaml"); err == nil { - return ctx.Repo.GetIssueConfig(configName + ".yaml", commit) + return ctx.Repo.GetIssueConfig(configName+".yaml", commit) } if _, err := commit.GetTreeEntryByPath(configName + ".yml"); err == nil { - return ctx.Repo.GetIssueConfig(configName + ".yml", commit) + return ctx.Repo.GetIssueConfig(configName+".yml", commit) } } @@ -1170,9 +1169,9 @@ func (ctx *Context) IssueConfigFromDefaultBranch() (api.IssueConfig, error) { } // IsIssueConfig returns if the given path is a issue config file. -func (r *Repository) IsIssueConfig(path string) (bool) { +func (r *Repository) IsIssueConfig(path string) bool { for _, configName := range IssueConfigCanidates { - if path == configName + ".yaml" || path == configName + ".yml" { + if path == configName+".yaml" || path == configName+".yml" { return true } } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 631f374e2de2..befec797909d 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -930,7 +930,7 @@ func NewIssueChooseTemplate(ctx *context.Context) { issueConfig, err := ctx.IssueConfigFromDefaultBranch() ctx.Data["IssueConfig"] = issueConfig - ctx.Data["IssueConfigError"] = err // ctx.Flash.Err makes problems here + ctx.Data["IssueConfigError"] = err // ctx.Flash.Err makes problems here ctx.Data["milestone"] = ctx.FormInt64("milestone") ctx.Data["project"] = ctx.FormInt64("project") From 0564f5c1512e1dd513d266219ceff327595946bd Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 23 Jan 2023 19:19:36 +0100 Subject: [PATCH 13/25] Run make generate-swagger --- templates/swagger/v1_json.tmpl | 49 ++++++---------------------------- 1 file changed, 8 insertions(+), 41 deletions(-) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 975c5831b8bc..5a8bc4b57302 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -4684,7 +4684,7 @@ } } }, - "/repos/{owner}/{repo}/issue_templates": { + "/repos/{owner}/{repo}/issue_config": { "get": { "produces": [ "application/json" @@ -4692,32 +4692,16 @@ "tags": [ "repository" ], - "summary": "Get available issue templates for a repository", - "operationId": "repoGetIssueTemplates", - "parameters": [ - { - "type": "string", - "description": "owner of the repo", - "name": "owner", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "name of the repo", - "name": "repo", - "in": "path", - "required": true - } - ], + "summary": "Returns the issue config for a repo", + "operationId": "repoGetIssueConfig", "responses": { "200": { - "$ref": "#/responses/IssueTemplates" + "$ref": "#/responses/IssueConfig" } } } }, - "/repos/{owner}/{repo}/issue_config": { + "/repos/{owner}/{repo}/issue_templates": { "get": { "produces": [ "application/json" @@ -4725,8 +4709,8 @@ "tags": [ "repository" ], - "summary": "Returns the issue config for a repo", - "operationId": "repoGetIssueConfig", + "summary": "Get available issue templates for a repository", + "operationId": "repoGetIssueTemplates", "parameters": [ { "type": "string", @@ -4745,7 +4729,7 @@ ], "responses": { "200": { - "$ref": "#/responses/IssueConfig" + "$ref": "#/responses/IssueTemplates" } } } @@ -17466,17 +17450,6 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "IssueConfig": { - "description": "IssueConfig represents an issue config for a repository", - "type": "object", - "properties": { - "blank_issues_enabled": { - "type": "boolean", - "x-go-name": "BlankIssuesEnabled" - } - }, - "x-go-package": "code.gitea.io/gitea/modules/structs" - }, "MarkdownOption": { "description": "MarkdownOption markdown options", "type": "object", @@ -20263,12 +20236,6 @@ } } }, - "IssueConfig": { - "description": "IssueConfig", - "schema": { - "$ref": "#/definitions/IssueConfig" - } - }, "Label": { "description": "Label", "schema": { From b34913f2582b614df4bbaf25f76e28e66623c517 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Fri, 27 Jan 2023 16:05:37 +0100 Subject: [PATCH 14/25] Add defer reader.Close() --- modules/context/repo.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/context/repo.go b/modules/context/repo.go index a0519086202a..3b4847efad63 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -1134,6 +1134,8 @@ func (r *Repository) GetIssueConfig(path string, commit *git.Commit) (api.IssueC return GetDefaultIssueConfig(), nil } + defer reader.Close() + configContent, err := io.ReadAll(reader) if err != nil { return GetDefaultIssueConfig(), err From abf14a5aa640904142974459610f8112344e349c Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 6 Feb 2023 15:03:46 +0100 Subject: [PATCH 15/25] Implement Contact Links --- .../issue-pull-request-templates.en-us.md | 19 +++++- modules/context/repo.go | 11 +++- modules/structs/issue.go | 7 +++ options/locale/locale_en-US.ini | 1 + routers/api/v1/repo/repo.go | 13 +++- routers/api/v1/swagger/repo.go | 7 +++ templates/repo/issue/choose.tmpl | 13 ++++ templates/swagger/v1_json.tmpl | 59 ++++++++++++++++++- 8 files changed, 122 insertions(+), 8 deletions(-) diff --git a/docs/content/doc/usage/issue-pull-request-templates.en-us.md b/docs/content/doc/usage/issue-pull-request-templates.en-us.md index 12b80906415e..0e83c54a45f7 100644 --- a/docs/content/doc/usage/issue-pull-request-templates.en-us.md +++ b/docs/content/doc/usage/issue-pull-request-templates.en-us.md @@ -286,10 +286,23 @@ This is a example for a issue config file ```yaml blank_issues_enabled: true +contact_links: + - name: Gitea + url: https://gitea.io + about: Visit the Gitea Website ``` ### Possible Options -| Key | Description | Type | Default | -|----------------------|-------------------------------------------------------------------------------------------------------|---------|---------| -| blank_issues_enabled | If set to false, the User is forced to use a Template | Boolean | true | +| Key | Description | Type | Default | +|----------------------|-------------------------------------------------------------------------------------------------------|--------------------|----------------| +| blank_issues_enabled | If set to false, the User is forced to use a Template | Boolean | true | +| contact_links | Custom Links to show in the Choose Box | Contact Link Array | Empty Array | + +### Contact Link + +| Key | Description | Type | Required | +|----------------------|-------------------------------------------------------------------------------------------------------|---------|----------| +| name | the name of your link | String | true | +| url | The URL of your Link | String | true | +| about | A short description of your Link | String | true | diff --git a/modules/context/repo.go b/modules/context/repo.go index 5843c6f99630..4b1aeea621eb 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -49,7 +49,7 @@ var IssueTemplateDirCandidates = []string{ ".gitlab/issue_template", } -var IssueConfigCanidates = []string{ +var IssueConfigCandidates = []string{ ".gitea/ISSUE_TEMPLATE/config", ".gitea/issue_template/config", ".github/ISSUE_TEMPLATE/config", @@ -1112,6 +1112,7 @@ func (ctx *Context) IssueTemplatesErrorsFromDefaultBranch() ([]*api.IssueTemplat func GetDefaultIssueConfig() api.IssueConfig { return api.IssueConfig{ BlankIssuesEnabled: true, + ContactLinks: make([]api.IssueConfigContactLink, 0), } } @@ -1153,12 +1154,16 @@ func (r *Repository) GetIssueConfig(path string, commit *git.Commit) (api.IssueC // 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 IssueConfigCanidates { + for _, configName := range IssueConfigCandidates { if _, err := commit.GetTreeEntryByPath(configName + ".yaml"); err == nil { return ctx.Repo.GetIssueConfig(configName+".yaml", commit) } @@ -1173,7 +1178,7 @@ func (ctx *Context) IssueConfigFromDefaultBranch() (api.IssueConfig, error) { // IsIssueConfig returns if the given path is a issue config file. func (r *Repository) IsIssueConfig(path string) bool { - for _, configName := range IssueConfigCanidates { + for _, configName := range IssueConfigCandidates { if path == configName+".yaml" || path == configName+".yml" { return true } diff --git a/modules/structs/issue.go b/modules/structs/issue.go index 17a54270c79d..effb62a05539 100644 --- a/modules/structs/issue.go +++ b/modules/structs/issue.go @@ -190,8 +190,15 @@ func (l *IssueTemplateLabels) UnmarshalYAML(value *yaml.Node) error { return fmt.Errorf("line %d: cannot unmarshal %s into IssueTemplateLabels", value.Line, value.ShortTag()) } +type IssueConfigContactLink struct { + Name string `json:"name" yaml:"name"` + URL string `json:"url" yaml:"url"` + About string `json:"about" yaml:"about"` +} + type IssueConfig struct { BlankIssuesEnabled bool `json:"blank_issues_enabled" yaml:"blank_issues_enabled"` + ContactLinks []IssueConfigContactLink `json:"contact_links" yaml:"contact_links"` } // IssueTemplateType defines issue template type diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 5505d79c76cf..9f56fe03374c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1263,6 +1263,7 @@ issues.new.no_assignees = No Assignees issues.new.no_reviewers = No reviewers issues.new.add_reviewer_title = Request review issues.choose.get_started = Get Started +issues.choose.open_external_link = Open issues.choose.blank = Default issues.choose.blank_about = Create an issue from default template. issues.choose.ignore_invalid_templates = Invalid templates have been ignored diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index d954ba512e2f..c6f7ef53e0c3 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -1103,9 +1103,20 @@ func GetIssueConfig(ctx *context.APIContext) { // summary: Returns the issue config for a repo // produces: // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true // responses: // "200": - // "$ref": "#/responses/IssueConfig" + // "$ref": "#/responses/RepoIssueConfig" issueConfig, _ := ctx.IssueConfigFromDefaultBranch() ctx.JSON(http.StatusOK, issueConfig) } diff --git a/routers/api/v1/swagger/repo.go b/routers/api/v1/swagger/repo.go index bd867213a62d..c94df91ce527 100644 --- a/routers/api/v1/swagger/repo.go +++ b/routers/api/v1/swagger/repo.go @@ -386,3 +386,10 @@ type swaggerRepoCollaboratorPermission struct { // in:body Body api.RepoCollaboratorPermission `json:"body"` } + +// RepoIssueConfig +// swagger:response RepoIssueConfig +type swaggerRepoIssueConfig struct { + // in:body + Body api.IssueConfig `json:"body"` +} diff --git a/templates/repo/issue/choose.tmpl b/templates/repo/issue/choose.tmpl index 34e8a3ea7fb0..40b16134c693 100644 --- a/templates/repo/issue/choose.tmpl +++ b/templates/repo/issue/choose.tmpl @@ -20,6 +20,19 @@
{{end}} + {{range .IssueConfig.ContactLinks}} +
+
+
+ {{.Name | RenderEmojiPlain}} +
{{.About | RenderEmojiPlain}} +
+ +
+
+ {{end}} {{if .IssueConfig.BlankIssuesEnabled}}
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 59b975728843..0042dbbc945f 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -4845,9 +4845,25 @@ ], "summary": "Returns the issue config for a repo", "operationId": "repoGetIssueConfig", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + } + ], "responses": { "200": { - "$ref": "#/responses/IssueConfig" + "$ref": "#/responses/RepoIssueConfig" } } } @@ -17503,6 +17519,41 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "IssueConfig": { + "type": "object", + "properties": { + "blank_issues_enabled": { + "type": "boolean", + "x-go-name": "BlankIssuesEnabled" + }, + "contact_links": { + "type": "array", + "items": { + "$ref": "#/definitions/IssueConfigContactLink" + }, + "x-go-name": "ContactLinks" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, + "IssueConfigContactLink": { + "type": "object", + "properties": { + "about": { + "type": "string", + "x-go-name": "About" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "url": { + "type": "string", + "x-go-name": "URL" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "IssueDeadline": { "description": "IssueDeadline represents an issue deadline", "type": "object", @@ -20688,6 +20739,12 @@ "$ref": "#/definitions/RepoCollaboratorPermission" } }, + "RepoIssueConfig": { + "description": "RepoIssueConfig", + "schema": { + "$ref": "#/definitions/IssueConfig" + } + }, "Repository": { "description": "Repository", "schema": { From 2a164471fbcae30943ba9e2108c4a3fb0488f60c Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 6 Feb 2023 18:05:28 +0100 Subject: [PATCH 16/25] Show choose page when contact links exists --- modules/context/repo.go | 9 +++++++++ routers/web/repo/issue.go | 10 +++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index 4b1aeea621eb..03a2c690dc14 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -1185,3 +1185,12 @@ 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 +} diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 22c8a9024c91..32ae6762ad22 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -414,7 +414,7 @@ func Issues(ctx *context.Context) { } ctx.Data["Title"] = ctx.Tr("repo.issues") ctx.Data["PageIsIssueList"] = true - ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0 + ctx.Data["NewIssueChooseTemplate"] = ctx.HasIssueTemplatesOrContactLinks() } issues(ctx, ctx.FormInt64("milestone"), ctx.FormInt64("project"), util.OptionalBoolOf(isPullList)) @@ -827,7 +827,7 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles func NewIssue(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.issues.new") ctx.Data["PageIsIssueList"] = true - ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0 + ctx.Data["NewIssueChooseTemplate"] =ctx.HasIssueTemplatesOrContactLinks() ctx.Data["RequireTribute"] = true ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes title := ctx.FormString("title") @@ -925,7 +925,7 @@ func NewIssueChooseTemplate(ctx *context.Context) { ctx.Flash.Warning(renderErrorOfTemplates(ctx, errs), true) } - if len(issueTemplates) == 0 { + if !ctx.HasIssueTemplatesOrContactLinks() { // The "issues/new" and "issues/new/choose" share the same query parameters "project" and "milestone", if no template here, just redirect to the "issues/new" page with these parameters. ctx.Redirect(fmt.Sprintf("%s/issues/new?%s", ctx.Repo.Repository.HTMLURL(), ctx.Req.URL.RawQuery), http.StatusSeeOther) return @@ -1069,7 +1069,7 @@ func NewIssuePost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.CreateIssueForm) ctx.Data["Title"] = ctx.Tr("repo.issues.new") ctx.Data["PageIsIssueList"] = true - ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0 + ctx.Data["NewIssueChooseTemplate"] = ctx.HasIssueTemplatesOrContactLinks() ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "comment") @@ -1259,7 +1259,7 @@ func ViewIssue(ctx *context.Context) { return } ctx.Data["PageIsIssueList"] = true - ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0 + ctx.Data["NewIssueChooseTemplate"] = ctx.HasIssueTemplatesOrContactLinks() } if issue.IsPull && !ctx.Repo.CanRead(unit.TypeIssues) { From 579b8e55f165a6aefd676a246cf0bc1e08d8ab38 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 7 Feb 2023 11:34:47 +0100 Subject: [PATCH 17/25] Validate ContactLinks --- modules/context/repo.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index 03a2c690dc14..6ae55e85e38d 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -6,6 +6,7 @@ package context import ( "context" + "errors" "fmt" "html" "io" @@ -1112,7 +1113,7 @@ func (ctx *Context) IssueTemplatesErrorsFromDefaultBranch() ([]*api.IssueTemplat func GetDefaultIssueConfig() api.IssueConfig { return api.IssueConfig{ BlankIssuesEnabled: true, - ContactLinks: make([]api.IssueConfigContactLink, 0), + ContactLinks: make([]api.IssueConfigContactLink, 0), } } @@ -1148,6 +1149,25 @@ func (r *Repository) GetIssueConfig(path string, commit *git.Commit) (api.IssueC return GetDefaultIssueConfig(), err } + for pos, link := range issueConfig.ContactLinks { + if link.Name == "" { + return GetDefaultIssueConfig(), errors.New(fmt.Sprintf("contact_link at position %d is missing name key", pos+1)) + } + + if link.URL == "" { + return GetDefaultIssueConfig(), errors.New(fmt.Sprintf("contact_link at position %d is missing url key", pos+1)) + } + + if link.About == "" { + return GetDefaultIssueConfig(), errors.New(fmt.Sprintf("contact_link at position %d is missing about key", pos+1)) + } + + _, err = url.ParseRequestURI(link.URL) + if err != nil { + return GetDefaultIssueConfig(), errors.New(fmt.Sprintf("%s is not a valid URL", link.URL)) + } + } + return issueConfig, nil } @@ -1187,7 +1207,7 @@ func (r *Repository) IsIssueConfig(path string) bool { } func (ctx *Context) HasIssueTemplatesOrContactLinks() bool { - if len(ctx.IssueTemplatesFromDefaultBranch()) > 0 { + if len(ctx.IssueTemplatesFromDefaultBranch()) > 0 { return true } From 1f52bb7f5eed252dd0fb277023db855fbf578d9d Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 7 Feb 2023 11:49:22 +0100 Subject: [PATCH 18/25] Add API to validate issue config --- modules/structs/issue.go | 13 ++++++--- routers/api/v1/api.go | 1 + routers/api/v1/repo/repo.go | 30 +++++++++++++++++++ routers/api/v1/swagger/repo.go | 7 +++++ templates/swagger/v1_json.tmpl | 53 ++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 4 deletions(-) diff --git a/modules/structs/issue.go b/modules/structs/issue.go index effb62a05539..8aebaf9364b5 100644 --- a/modules/structs/issue.go +++ b/modules/structs/issue.go @@ -191,14 +191,19 @@ func (l *IssueTemplateLabels) UnmarshalYAML(value *yaml.Node) error { } type IssueConfigContactLink struct { - Name string `json:"name" yaml:"name"` - URL string `json:"url" yaml:"url"` + Name string `json:"name" yaml:"name"` + URL string `json:"url" yaml:"url"` About string `json:"about" yaml:"about"` } type IssueConfig struct { - BlankIssuesEnabled bool `json:"blank_issues_enabled" yaml:"blank_issues_enabled"` - ContactLinks []IssueConfigContactLink `json:"contact_links" yaml:"contact_links"` + BlankIssuesEnabled bool `json:"blank_issues_enabled" yaml:"blank_issues_enabled"` + ContactLinks []IssueConfigContactLink `json:"contact_links" yaml:"contact_links"` +} + +type IssueConfigValidate struct { + Valid bool `json:"valid"` + Message string `json:"message"` } // IssueTemplateType defines issue template type diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index af90ef5866d0..36cda1cb1624 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1153,6 +1153,7 @@ func Routes(ctx gocontext.Context) *web.Route { }, reqAnyRepoReader()) m.Get("/issue_templates", context.ReferencesGitRepo(), repo.GetIssueTemplates) m.Get("/issue_config", context.ReferencesGitRepo(), repo.GetIssueConfig) + m.Get("/issue_config/validate", context.ReferencesGitRepo(), repo.ValidateIssueConfig) m.Get("/languages", reqRepoReader(unit.TypeCode), repo.GetLanguages) }, repoAssignment()) }) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index c6f7ef53e0c3..3f58f3f69b2f 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -1120,3 +1120,33 @@ func GetIssueConfig(ctx *context.APIContext) { issueConfig, _ := ctx.IssueConfigFromDefaultBranch() ctx.JSON(http.StatusOK, issueConfig) } + +// ValidateIssueConfig returns validation errors for the issue config +func ValidateIssueConfig(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/issue_config/validate repository repoValidateIssueConfig + // --- + // summary: Returns the validation information for a issue config + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // responses: + // "200": + // "$ref": "#/responses/RepoIssueConfigValidate" + _, err := ctx.IssueConfigFromDefaultBranch() + + if err == nil { + ctx.JSON(http.StatusOK, api.IssueConfigValidate{Valid: true, Message: ""}) + } else { + ctx.JSON(http.StatusOK, api.IssueConfigValidate{Valid: false, Message: err.Error()}) + } +} diff --git a/routers/api/v1/swagger/repo.go b/routers/api/v1/swagger/repo.go index c94df91ce527..acd60eb68f13 100644 --- a/routers/api/v1/swagger/repo.go +++ b/routers/api/v1/swagger/repo.go @@ -393,3 +393,10 @@ type swaggerRepoIssueConfig struct { // in:body Body api.IssueConfig `json:"body"` } + +// RepoIssueConfigValidate +// swagger:response RepoIssueConfigValidate +type swaggerRepoIssueConfigValidate struct { + // in:body + Body api.IssueConfigValidate `json:"body"` +} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 0042dbbc945f..b23daeff9271 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -4868,6 +4868,39 @@ } } }, + "/repos/{owner}/{repo}/issue_config/validate": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Returns the validation information for a issue config", + "operationId": "repoValidateIssueConfig", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/RepoIssueConfigValidate" + } + } + } + }, "/repos/{owner}/{repo}/issue_templates": { "get": { "produces": [ @@ -17554,6 +17587,20 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "IssueConfigValidate": { + "type": "object", + "properties": { + "message": { + "type": "string", + "x-go-name": "Message" + }, + "valid": { + "type": "boolean", + "x-go-name": "Valid" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "IssueDeadline": { "description": "IssueDeadline represents an issue deadline", "type": "object", @@ -20745,6 +20792,12 @@ "$ref": "#/definitions/IssueConfig" } }, + "RepoIssueConfigValidate": { + "description": "RepoIssueConfigValidate", + "schema": { + "$ref": "#/definitions/IssueConfigValidate" + } + }, "Repository": { "description": "Repository", "schema": { From ed098346d2725af6b427c8c4f132f08162ea272c Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 7 Feb 2023 11:59:45 +0100 Subject: [PATCH 19/25] Fix lint --- modules/context/repo.go | 9 ++++----- routers/web/repo/issue.go | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index 6ae55e85e38d..b150a8039e4a 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -6,7 +6,6 @@ package context import ( "context" - "errors" "fmt" "html" "io" @@ -1151,20 +1150,20 @@ func (r *Repository) GetIssueConfig(path string, commit *git.Commit) (api.IssueC for pos, link := range issueConfig.ContactLinks { if link.Name == "" { - return GetDefaultIssueConfig(), errors.New(fmt.Sprintf("contact_link at position %d is missing name key", pos+1)) + return GetDefaultIssueConfig(), fmt.Errorf("contact_link at position %d is missing name key", pos+1) } if link.URL == "" { - return GetDefaultIssueConfig(), errors.New(fmt.Sprintf("contact_link at position %d is missing url key", pos+1)) + return GetDefaultIssueConfig(), fmt.Errorf("contact_link at position %d is missing url key", pos+1) } if link.About == "" { - return GetDefaultIssueConfig(), errors.New(fmt.Sprintf("contact_link at position %d is missing about key", pos+1)) + return GetDefaultIssueConfig(), fmt.Errorf("contact_link at position %d is missing about key", pos+1) } _, err = url.ParseRequestURI(link.URL) if err != nil { - return GetDefaultIssueConfig(), errors.New(fmt.Sprintf("%s is not a valid URL", link.URL)) + return GetDefaultIssueConfig(), fmt.Errorf("%s is not a valid URL", link.URL) } } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 32ae6762ad22..e61b477883e4 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -827,7 +827,7 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles func NewIssue(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.issues.new") ctx.Data["PageIsIssueList"] = true - ctx.Data["NewIssueChooseTemplate"] =ctx.HasIssueTemplatesOrContactLinks() + ctx.Data["NewIssueChooseTemplate"] = ctx.HasIssueTemplatesOrContactLinks() ctx.Data["RequireTribute"] = true ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes title := ctx.FormString("title") From 0e01deb591772d46526fd8ef75df2fbb470ff17c Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 7 Feb 2023 12:32:40 +0100 Subject: [PATCH 20/25] Add API tests --- tests/integration/api_issue_config_test.go | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/integration/api_issue_config_test.go diff --git a/tests/integration/api_issue_config_test.go b/tests/integration/api_issue_config_test.go new file mode 100644 index 000000000000..857102be19fe --- /dev/null +++ b/tests/integration/api_issue_config_test.go @@ -0,0 +1,52 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package integration + +import ( + "fmt" + "net/http" + "testing" + + repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" + api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/tests" + + "github.com/stretchr/testify/assert" +) + +func TestAPIReposGetDefaultIssueConfig(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) + owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) + + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issue_config", owner.Name, repo.Name) + req := NewRequest(t, "GET", urlStr) + resp := MakeRequest(t, req, http.StatusOK) + + var issueConfig api.IssueConfig + DecodeJSON(t, resp, &issueConfig) + + assert.True(t, issueConfig.BlankIssuesEnabled) + assert.Equal(t, issueConfig.ContactLinks, make([]api.IssueConfigContactLink, 0)) +} + +func TestAPIReposValidateDefaultIssueConfig(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) + owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) + + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issue_config/validate", owner.Name, repo.Name) + req := NewRequest(t, "GET", urlStr) + resp := MakeRequest(t, req, http.StatusOK) + + var issueConfigValidate api.IssueConfigValidate + DecodeJSON(t, resp, &issueConfigValidate) + + assert.True(t, issueConfigValidate.Valid) + assert.Equal(t, issueConfigValidate.Message, "") +} From 17185ab8fd7850961dc020b3431ebd3cd45c2458 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Wed, 8 Feb 2023 13:30:31 +0100 Subject: [PATCH 21/25] Changes requested by wolfogre --- docs/content/doc/usage/issue-pull-request-templates.en-us.md | 1 - options/locale/locale_en-US.ini | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/content/doc/usage/issue-pull-request-templates.en-us.md b/docs/content/doc/usage/issue-pull-request-templates.en-us.md index 0e83c54a45f7..f36037956a5c 100644 --- a/docs/content/doc/usage/issue-pull-request-templates.en-us.md +++ b/docs/content/doc/usage/issue-pull-request-templates.en-us.md @@ -55,7 +55,6 @@ Possible file names for issue config: - `.gitea/ISSUE_TEMPLATE/config.yaml` - `.gitea/ISSUE_TEMPLATE/config.yml` - `.gitea/issue_template/config.yaml` -- `.gitea/issue_template/config.yaml` - `.gitea/issue_template/config.yml` - `.github/ISSUE_TEMPLATE/config.yaml` - `.github/ISSUE_TEMPLATE/config.yml` diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 9f56fe03374c..21a6cc52f62b 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1268,7 +1268,7 @@ issues.choose.blank = Default issues.choose.blank_about = Create an issue from default template. issues.choose.ignore_invalid_templates = Invalid templates have been ignored issues.choose.invalid_templates = %v invalid template(s) found -issues.choose.invalid_config = Your issue_config.yaml contains a error: +issues.choose.invalid_config = The issue config contains errors: issues.no_ref = No Branch/Tag Specified issues.create = Create Issue issues.new_label = New Label From 062375fbe7e87cbe4c1acf38dca1e6fe51459ab0 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Wed, 8 Feb 2023 13:31:09 +0100 Subject: [PATCH 22/25] Run make fmt --- tests/integration/api_issue_config_test.go | 104 ++++++++++----------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/tests/integration/api_issue_config_test.go b/tests/integration/api_issue_config_test.go index 857102be19fe..77de4cfad598 100644 --- a/tests/integration/api_issue_config_test.go +++ b/tests/integration/api_issue_config_test.go @@ -1,52 +1,52 @@ -// Copyright 2023 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package integration - -import ( - "fmt" - "net/http" - "testing" - - repo_model "code.gitea.io/gitea/models/repo" - "code.gitea.io/gitea/models/unittest" - user_model "code.gitea.io/gitea/models/user" - api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/tests" - - "github.com/stretchr/testify/assert" -) - -func TestAPIReposGetDefaultIssueConfig(t *testing.T) { - defer tests.PrepareTestEnv(t)() - - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) - owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) - - urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issue_config", owner.Name, repo.Name) - req := NewRequest(t, "GET", urlStr) - resp := MakeRequest(t, req, http.StatusOK) - - var issueConfig api.IssueConfig - DecodeJSON(t, resp, &issueConfig) - - assert.True(t, issueConfig.BlankIssuesEnabled) - assert.Equal(t, issueConfig.ContactLinks, make([]api.IssueConfigContactLink, 0)) -} - -func TestAPIReposValidateDefaultIssueConfig(t *testing.T) { - defer tests.PrepareTestEnv(t)() - - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) - owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) - - urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issue_config/validate", owner.Name, repo.Name) - req := NewRequest(t, "GET", urlStr) - resp := MakeRequest(t, req, http.StatusOK) - - var issueConfigValidate api.IssueConfigValidate - DecodeJSON(t, resp, &issueConfigValidate) - - assert.True(t, issueConfigValidate.Valid) - assert.Equal(t, issueConfigValidate.Message, "") -} +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package integration + +import ( + "fmt" + "net/http" + "testing" + + repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" + api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/tests" + + "github.com/stretchr/testify/assert" +) + +func TestAPIReposGetDefaultIssueConfig(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) + owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) + + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issue_config", owner.Name, repo.Name) + req := NewRequest(t, "GET", urlStr) + resp := MakeRequest(t, req, http.StatusOK) + + var issueConfig api.IssueConfig + DecodeJSON(t, resp, &issueConfig) + + assert.True(t, issueConfig.BlankIssuesEnabled) + assert.Equal(t, issueConfig.ContactLinks, make([]api.IssueConfigContactLink, 0)) +} + +func TestAPIReposValidateDefaultIssueConfig(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) + owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) + + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issue_config/validate", owner.Name, repo.Name) + req := NewRequest(t, "GET", urlStr) + resp := MakeRequest(t, req, http.StatusOK) + + var issueConfigValidate api.IssueConfigValidate + DecodeJSON(t, resp, &issueConfigValidate) + + assert.True(t, issueConfigValidate.Valid) + assert.Equal(t, issueConfigValidate.Message, "") +} From 159c0f72cdd365f08b32fa4b14cad18501bc0718 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 27 Mar 2023 10:34:02 +0200 Subject: [PATCH 23/25] Rename IssueConfigValidate to IssueConfigValidation --- modules/structs/issue.go | 2 +- routers/api/v1/repo/repo.go | 6 +++--- routers/api/v1/swagger/repo.go | 8 ++++---- templates/swagger/v1_json.tmpl | 10 +++++----- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/structs/issue.go b/modules/structs/issue.go index 8aebaf9364b5..960d28bb2ede 100644 --- a/modules/structs/issue.go +++ b/modules/structs/issue.go @@ -201,7 +201,7 @@ type IssueConfig struct { ContactLinks []IssueConfigContactLink `json:"contact_links" yaml:"contact_links"` } -type IssueConfigValidate struct { +type IssueConfigValidation struct { Valid bool `json:"valid"` Message string `json:"message"` } diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index ac0f78131e3b..60e71495e87b 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -1190,12 +1190,12 @@ func ValidateIssueConfig(ctx *context.APIContext) { // required: true // responses: // "200": - // "$ref": "#/responses/RepoIssueConfigValidate" + // "$ref": "#/responses/RepoIssueConfigValidation" _, err := ctx.IssueConfigFromDefaultBranch() if err == nil { - ctx.JSON(http.StatusOK, api.IssueConfigValidate{Valid: true, Message: ""}) + ctx.JSON(http.StatusOK, api.IssueConfigValidation{Valid: true, Message: ""}) } else { - ctx.JSON(http.StatusOK, api.IssueConfigValidate{Valid: false, Message: err.Error()}) + ctx.JSON(http.StatusOK, api.IssueConfigValidation{Valid: false, Message: err.Error()}) } } diff --git a/routers/api/v1/swagger/repo.go b/routers/api/v1/swagger/repo.go index acd60eb68f13..e0418e99dc44 100644 --- a/routers/api/v1/swagger/repo.go +++ b/routers/api/v1/swagger/repo.go @@ -394,9 +394,9 @@ type swaggerRepoIssueConfig struct { Body api.IssueConfig `json:"body"` } -// RepoIssueConfigValidate -// swagger:response RepoIssueConfigValidate -type swaggerRepoIssueConfigValidate struct { +// RepoIssueConfigValidation +// swagger:response RepoIssueConfigValidation +type swaggerRepoIssueConfigValidation struct { // in:body - Body api.IssueConfigValidate `json:"body"` + Body api.IssueConfigValidation `json:"body"` } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 6bcc32ec4007..f75cfc00cb10 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -5074,7 +5074,7 @@ ], "responses": { "200": { - "$ref": "#/responses/RepoIssueConfigValidate" + "$ref": "#/responses/RepoIssueConfigValidation" } } } @@ -17976,7 +17976,7 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "IssueConfigValidate": { + "IssueConfigValidation": { "type": "object", "properties": { "message": { @@ -21255,10 +21255,10 @@ "$ref": "#/definitions/IssueConfig" } }, - "RepoIssueConfigValidate": { - "description": "RepoIssueConfigValidate", + "RepoIssueConfigValidation": { + "description": "RepoIssueConfigValidation", "schema": { - "$ref": "#/definitions/IssueConfigValidate" + "$ref": "#/definitions/IssueConfigValidation" } }, "Repository": { From 68f508be398e56b3c63b247685949da37af09966 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 27 Mar 2023 10:35:47 +0200 Subject: [PATCH 24/25] Missed test --- tests/integration/api_issue_config_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/api_issue_config_test.go b/tests/integration/api_issue_config_test.go index 77de4cfad598..a81e0e5a1099 100644 --- a/tests/integration/api_issue_config_test.go +++ b/tests/integration/api_issue_config_test.go @@ -44,9 +44,9 @@ func TestAPIReposValidateDefaultIssueConfig(t *testing.T) { req := NewRequest(t, "GET", urlStr) resp := MakeRequest(t, req, http.StatusOK) - var issueConfigValidate api.IssueConfigValidate - DecodeJSON(t, resp, &issueConfigValidate) + var issueConfigValidation api.IssueConfigValidation + DecodeJSON(t, resp, &IssueConfigValidation) - assert.True(t, issueConfigValidate.Valid) - assert.Equal(t, issueConfigValidate.Message, "") + assert.True(t, issueConfigValidation.Valid) + assert.Equal(t, issueConfigValidation.Message, "") } From 609840ca6c81e624b21175d86f87566b9475bfc9 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 27 Mar 2023 10:52:18 +0200 Subject: [PATCH 25/25] Typo --- tests/integration/api_issue_config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/api_issue_config_test.go b/tests/integration/api_issue_config_test.go index a81e0e5a1099..b9b3765c4e56 100644 --- a/tests/integration/api_issue_config_test.go +++ b/tests/integration/api_issue_config_test.go @@ -45,7 +45,7 @@ func TestAPIReposValidateDefaultIssueConfig(t *testing.T) { resp := MakeRequest(t, req, http.StatusOK) var issueConfigValidation api.IssueConfigValidation - DecodeJSON(t, resp, &IssueConfigValidation) + DecodeJSON(t, resp, &issueConfigValidation) assert.True(t, issueConfigValidation.Valid) assert.Equal(t, issueConfigValidation.Message, "")