Skip to content

Commit 7cbf05f

Browse files
committed
Merge remote-tracking branch 'forgejo/forgejo-dependency' into wip-forgejo
Conflicts: .forgejo/workflows/testing.yml trivial conflict
2 parents 36fc9a9 + 12e289f commit 7cbf05f

File tree

10 files changed

+288
-37
lines changed

10 files changed

+288
-37
lines changed

.forgejo/workflows/testing.yml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- 'v*/forgejo*'
99

1010
jobs:
11-
lint-backend:
11+
backend-checks:
1212
if: ${{ !startsWith(vars.ROLE, 'forgejo-') }}
1313
runs-on: docker
1414
container:
@@ -20,26 +20,13 @@ jobs:
2020
go-version: "1.21"
2121
check-latest: true
2222
- run: make deps-backend deps-tools
23-
- run: make lint-backend
23+
- run: make --always-make -j$(nproc) lint-backend checks-backend # ensure the "go-licenses" make target runs
2424
env:
2525
TAGS: bindata sqlite sqlite_unlock_notify
26-
checks-backend:
27-
if: ${{ !startsWith(vars.ROLE, 'forgejo-') }}
28-
runs-on: docker
29-
container:
30-
image: 'docker.io/node:20-bookworm'
31-
steps:
32-
- uses: https://code.forgejo.org/actions/checkout@v3
33-
- uses: https://code.forgejo.org/actions/setup-go@v4
34-
with:
35-
go-version: "1.21"
36-
check-latest: true
37-
- run: make deps-backend deps-tools
38-
- run: make --always-make checks-backend # ensure the "go-licenses" make target runs
3926
test-unit:
4027
if: ${{ !startsWith(vars.ROLE, 'forgejo-') }}
4128
runs-on: docker
42-
needs: [lint-backend, checks-backend]
29+
needs: [backend-checks]
4330
container:
4431
image: 'docker.io/node:20-bookworm'
4532
services:
@@ -80,7 +67,7 @@ jobs:
8067
test-mysql:
8168
if: ${{ !startsWith(vars.ROLE, 'forgejo-') }}
8269
runs-on: docker
83-
needs: [lint-backend, checks-backend]
70+
needs: [backend-checks]
8471
container:
8572
image: 'docker.io/node:20-bookworm'
8673
services:
@@ -126,7 +113,7 @@ jobs:
126113
test-pgsql:
127114
if: ${{ !startsWith(vars.ROLE, 'forgejo-') }}
128115
runs-on: docker
129-
needs: [lint-backend, checks-backend]
116+
needs: [backend-checks]
130117
container:
131118
image: 'docker.io/node:20-bookworm'
132119
services:
@@ -174,7 +161,7 @@ jobs:
174161
test-sqlite:
175162
if: ${{ !startsWith(vars.ROLE, 'forgejo-') }}
176163
runs-on: docker
177-
needs: [lint-backend, checks-backend]
164+
needs: [backend-checks]
178165
container:
179166
image: 'docker.io/node:20-bookworm'
180167
steps:

routers/api/v1/repo/repo.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,11 +1174,7 @@ func GetIssueTemplates(ctx *context.APIContext) {
11741174
// "$ref": "#/responses/IssueTemplates"
11751175
// "404":
11761176
// "$ref": "#/responses/notFound"
1177-
ret, err := issue.GetTemplatesFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo)
1178-
if err != nil {
1179-
ctx.Error(http.StatusInternalServerError, "GetTemplatesFromDefaultBranch", err)
1180-
return
1181-
}
1177+
ret, _ := issue.GetTemplatesFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo)
11821178
ctx.JSON(http.StatusOK, ret)
11831179
}
11841180

routers/web/repo/issue.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ var IssueTemplateCandidates = []string{
7777
"issue_template.md",
7878
"issue_template.yaml",
7979
"issue_template.yml",
80+
".forgejo/ISSUE_TEMPLATE.md",
81+
".forgejo/ISSUE_TEMPLATE.yaml",
82+
".forgejo/ISSUE_TEMPLATE.yml",
83+
".forgejo/issue_template.md",
84+
".forgejo/issue_template.yaml",
85+
".forgejo/issue_template.yml",
8086
".gitea/ISSUE_TEMPLATE.md",
8187
".gitea/ISSUE_TEMPLATE.yaml",
8288
".gitea/ISSUE_TEMPLATE.yml",

routers/web/repo/pull.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ var pullRequestTemplateCandidates = []string{
6565
"pull_request_template.md",
6666
"pull_request_template.yaml",
6767
"pull_request_template.yml",
68+
".forgejo/PULL_REQUEST_TEMPLATE.md",
69+
".forgejo/PULL_REQUEST_TEMPLATE.yaml",
70+
".forgejo/PULL_REQUEST_TEMPLATE.yml",
71+
".forgejo/pull_request_template.md",
72+
".forgejo/pull_request_template.yaml",
73+
".forgejo/pull_request_template.yml",
6874
".gitea/PULL_REQUEST_TEMPLATE.md",
6975
".gitea/PULL_REQUEST_TEMPLATE.yaml",
7076
".gitea/PULL_REQUEST_TEMPLATE.yml",

routers/web/repo/view.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ func findReadmeFileInEntries(ctx *context.Context, entries []*git.TreeEntry, try
9494
if entry.Name() == "docs" || docsEntries[0] == nil {
9595
docsEntries[0] = entry
9696
}
97+
case ".forgejo":
98+
if entry.Name() == ".forgejo" || docsEntries[1] == nil {
99+
docsEntries[1] = entry
100+
}
97101
case ".gitea":
98102
if entry.Name() == ".gitea" || docsEntries[1] == nil {
99103
docsEntries[1] = entry

services/issue/template.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
var templateDirCandidates = []string{
2424
"ISSUE_TEMPLATE",
2525
"issue_template",
26+
".forgejo/ISSUE_TEMPLATE",
27+
".forgejo/issue_template",
2628
".gitea/ISSUE_TEMPLATE",
2729
".gitea/issue_template",
2830
".github/ISSUE_TEMPLATE",
@@ -32,6 +34,8 @@ var templateDirCandidates = []string{
3234
}
3335

3436
var templateConfigCandidates = []string{
37+
".forgejo/ISSUE_TEMPLATE/config",
38+
".forgejo/issue_template/config",
3539
".gitea/ISSUE_TEMPLATE/config",
3640
".gitea/issue_template/config",
3741
".github/ISSUE_TEMPLATE/config",

services/pull/merge.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,18 @@ func getMergeMessage(ctx context.Context, baseGitRepo *git.Repository, pr *issue
5555
}
5656

5757
if mergeStyle != "" {
58-
templateFilepath := fmt.Sprintf(".gitea/default_merge_message/%s_TEMPLATE.md", strings.ToUpper(string(mergeStyle)))
5958
commit, err := baseGitRepo.GetBranchCommit(pr.BaseRepo.DefaultBranch)
6059
if err != nil {
6160
return "", "", err
6261
}
63-
templateContent, err := commit.GetFileContent(templateFilepath, setting.Repository.PullRequest.DefaultMergeMessageSize)
62+
63+
templateFilepathForgejo := fmt.Sprintf(".forgejo/default_merge_message/%s_TEMPLATE.md", strings.ToUpper(string(mergeStyle)))
64+
templateFilepathGitea := fmt.Sprintf(".gitea/default_merge_message/%s_TEMPLATE.md", strings.ToUpper(string(mergeStyle)))
65+
66+
templateContent, err := commit.GetFileContent(templateFilepathForgejo, setting.Repository.PullRequest.DefaultMergeMessageSize)
67+
if _, ok := err.(git.ErrNotExist); ok {
68+
templateContent, err = commit.GetFileContent(templateFilepathGitea, setting.Repository.PullRequest.DefaultMergeMessageSize)
69+
}
6470
if err != nil {
6571
if !git.IsErrNotExist(err) {
6672
return "", "", err

tests/integration/api_issue_config_test.go

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
23
// SPDX-License-Identifier: MIT
34

45
package integration
@@ -18,14 +19,18 @@ import (
1819
"gopkg.in/yaml.v3"
1920
)
2021

21-
func createIssueConfig(t *testing.T, user *user_model.User, repo *repo_model.Repository, issueConfig map[string]any) {
22+
func createIssueConfigInDirectory(t *testing.T, user *user_model.User, repo *repo_model.Repository, dir string, issueConfig map[string]any) {
2223
config, err := yaml.Marshal(issueConfig)
2324
assert.NoError(t, err)
2425

25-
err = createOrReplaceFileInBranch(user, repo, ".gitea/ISSUE_TEMPLATE/config.yaml", repo.DefaultBranch, string(config))
26+
err = createOrReplaceFileInBranch(user, repo, fmt.Sprintf("%s/ISSUE_TEMPLATE/config.yaml", dir), repo.DefaultBranch, string(config))
2627
assert.NoError(t, err)
2728
}
2829

30+
func createIssueConfig(t *testing.T, user *user_model.User, repo *repo_model.Repository, issueConfig map[string]any) {
31+
createIssueConfigInDirectory(t, user, repo, ".gitea", issueConfig)
32+
}
33+
2934
func getIssueConfig(t *testing.T, owner, repo string) api.IssueConfig {
3035
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issue_config", owner, repo)
3136
req := NewRequest(t, "GET", urlStr)
@@ -44,13 +49,17 @@ func TestAPIRepoGetIssueConfig(t *testing.T) {
4449
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
4550

4651
t.Run("Default", func(t *testing.T) {
52+
defer tests.PrintCurrentTest(t)()
53+
4754
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
4855

4956
assert.True(t, issueConfig.BlankIssuesEnabled)
5057
assert.Len(t, issueConfig.ContactLinks, 0)
5158
})
5259

5360
t.Run("DisableBlankIssues", func(t *testing.T) {
61+
defer tests.PrintCurrentTest(t)()
62+
5463
config := make(map[string]any)
5564
config["blank_issues_enabled"] = false
5665

@@ -63,6 +72,8 @@ func TestAPIRepoGetIssueConfig(t *testing.T) {
6372
})
6473

6574
t.Run("ContactLinks", func(t *testing.T) {
75+
defer tests.PrintCurrentTest(t)()
76+
6677
contactLink := make(map[string]string)
6778
contactLink["name"] = "TestName"
6879
contactLink["url"] = "https://example.com"
@@ -84,6 +95,8 @@ func TestAPIRepoGetIssueConfig(t *testing.T) {
8495
})
8596

8697
t.Run("Full", func(t *testing.T) {
98+
defer tests.PrintCurrentTest(t)()
99+
87100
contactLink := make(map[string]string)
88101
contactLink["name"] = "TestName"
89102
contactLink["url"] = "https://example.com"
@@ -113,6 +126,8 @@ func TestAPIRepoIssueConfigPaths(t *testing.T) {
113126
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
114127

115128
templateConfigCandidates := []string{
129+
".forgejo/ISSUE_TEMPLATE/config",
130+
".forgejo/issue_template/config",
116131
".gitea/ISSUE_TEMPLATE/config",
117132
".gitea/issue_template/config",
118133
".github/ISSUE_TEMPLATE/config",
@@ -123,6 +138,8 @@ func TestAPIRepoIssueConfigPaths(t *testing.T) {
123138
for _, extension := range []string{".yaml", ".yml"} {
124139
fullPath := canidate + extension
125140
t.Run(fullPath, func(t *testing.T) {
141+
defer tests.PrintCurrentTest(t)()
142+
126143
configMap := make(map[string]any)
127144
configMap["blank_issues_enabled"] = false
128145

@@ -153,6 +170,8 @@ func TestAPIRepoValidateIssueConfig(t *testing.T) {
153170
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issue_config/validate", owner.Name, repo.Name)
154171

155172
t.Run("Valid", func(t *testing.T) {
173+
defer tests.PrintCurrentTest(t)()
174+
156175
req := NewRequest(t, "GET", urlStr)
157176
resp := MakeRequest(t, req, http.StatusOK)
158177

@@ -164,18 +183,28 @@ func TestAPIRepoValidateIssueConfig(t *testing.T) {
164183
})
165184

166185
t.Run("Invalid", func(t *testing.T) {
167-
config := make(map[string]any)
168-
config["blank_issues_enabled"] = "Test"
186+
dirs := []string{".gitea", ".forgejo"}
187+
for _, dir := range dirs {
188+
t.Run(dir, func(t *testing.T) {
189+
defer tests.PrintCurrentTest(t)()
190+
defer func() {
191+
deleteFileInBranch(owner, repo, fmt.Sprintf("%s/ISSUE_TEMPLATE/config.yaml", dir), repo.DefaultBranch)
192+
}()
169193

170-
createIssueConfig(t, owner, repo, config)
194+
config := make(map[string]any)
195+
config["blank_issues_enabled"] = "Test"
171196

172-
req := NewRequest(t, "GET", urlStr)
173-
resp := MakeRequest(t, req, http.StatusOK)
197+
createIssueConfigInDirectory(t, owner, repo, dir, config)
174198

175-
var issueConfigValidation api.IssueConfigValidation
176-
DecodeJSON(t, resp, &issueConfigValidation)
199+
req := NewRequest(t, "GET", urlStr)
200+
resp := MakeRequest(t, req, http.StatusOK)
201+
202+
var issueConfigValidation api.IssueConfigValidation
203+
DecodeJSON(t, resp, &issueConfigValidation)
177204

178-
assert.False(t, issueConfigValidation.Valid)
179-
assert.NotEmpty(t, issueConfigValidation.Message)
205+
assert.False(t, issueConfigValidation.Valid)
206+
assert.NotEmpty(t, issueConfigValidation.Message)
207+
})
208+
}
180209
})
181210
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package integration
5+
6+
import (
7+
"fmt"
8+
"net/http"
9+
"net/url"
10+
"testing"
11+
12+
repo_model "code.gitea.io/gitea/models/repo"
13+
"code.gitea.io/gitea/models/unittest"
14+
user_model "code.gitea.io/gitea/models/user"
15+
api "code.gitea.io/gitea/modules/structs"
16+
"code.gitea.io/gitea/tests"
17+
18+
"github.com/stretchr/testify/assert"
19+
)
20+
21+
func TestAPIIssueTemplateList(t *testing.T) {
22+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
23+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
24+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
25+
26+
t.Run("no templates", func(t *testing.T) {
27+
defer tests.PrintCurrentTest(t)()
28+
29+
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/issue_templates", repo.FullName()))
30+
resp := MakeRequest(t, req, http.StatusOK)
31+
var issueTemplates []*api.IssueTemplate
32+
DecodeJSON(t, resp, &issueTemplates)
33+
assert.Empty(t, issueTemplates)
34+
})
35+
36+
t.Run("existing template", func(t *testing.T) {
37+
templateCandidates := []string{
38+
".forgejo/ISSUE_TEMPLATE/test.md",
39+
".forgejo/issue_template/test.md",
40+
".gitea/ISSUE_TEMPLATE/test.md",
41+
".gitea/issue_template/test.md",
42+
".github/ISSUE_TEMPLATE/test.md",
43+
".github/issue_template/test.md",
44+
}
45+
46+
for _, template := range templateCandidates {
47+
t.Run(template, func(t *testing.T) {
48+
defer tests.PrintCurrentTest(t)()
49+
defer func() {
50+
deleteFileInBranch(user, repo, template, repo.DefaultBranch)
51+
}()
52+
53+
err := createOrReplaceFileInBranch(user, repo, template, repo.DefaultBranch,
54+
`---
55+
name: 'Template Name'
56+
about: 'This template is for testing!'
57+
title: '[TEST] '
58+
ref: 'main'
59+
---
60+
61+
This is the template!`)
62+
assert.NoError(t, err)
63+
64+
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/issue_templates", repo.FullName()))
65+
resp := MakeRequest(t, req, http.StatusOK)
66+
var issueTemplates []*api.IssueTemplate
67+
DecodeJSON(t, resp, &issueTemplates)
68+
assert.Len(t, issueTemplates, 1)
69+
assert.Equal(t, "Template Name", issueTemplates[0].Name)
70+
assert.Equal(t, "This template is for testing!", issueTemplates[0].About)
71+
assert.Equal(t, "refs/heads/main", issueTemplates[0].Ref)
72+
assert.Equal(t, template, issueTemplates[0].FileName)
73+
})
74+
}
75+
})
76+
77+
t.Run("multiple templates", func(t *testing.T) {
78+
defer tests.PrintCurrentTest(t)()
79+
templatePriority := []string{
80+
".forgejo/issue_template/test.md",
81+
".gitea/issue_template/test.md",
82+
".github/issue_template/test.md",
83+
}
84+
defer func() {
85+
for _, template := range templatePriority {
86+
deleteFileInBranch(user, repo, template, repo.DefaultBranch)
87+
}
88+
}()
89+
90+
for _, template := range templatePriority {
91+
err := createOrReplaceFileInBranch(user, repo, template, repo.DefaultBranch,
92+
`---
93+
name: 'Template Name'
94+
about: 'This template is for testing!'
95+
title: '[TEST] '
96+
ref: 'main'
97+
---
98+
99+
This is the template!`)
100+
assert.NoError(t, err)
101+
}
102+
103+
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/issue_templates", repo.FullName()))
104+
resp := MakeRequest(t, req, http.StatusOK)
105+
var issueTemplates []*api.IssueTemplate
106+
DecodeJSON(t, resp, &issueTemplates)
107+
108+
// If templates have the same filename and content, but in different
109+
// directories, they count as different templates, and all are
110+
// considered.
111+
assert.Len(t, issueTemplates, 3)
112+
})
113+
})
114+
}

0 commit comments

Comments
 (0)