Skip to content

Commit 7319f8d

Browse files
author
Gusted
authored
Merge branch 'main' into improve-dashboard-list
2 parents 3b67a8c + deffe9e commit 7319f8d

File tree

51 files changed

+251
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+251
-131
lines changed

docs/content/doc/developers/guidelines-frontend.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ menu:
2323

2424
Gitea uses [Less CSS](https://lesscss.org), [Fomantic-UI](https://fomantic-ui.com/introduction/getting-started.html) (based on [jQuery](https://api.jquery.com)) and [Vue2](https://vuejs.org/v2/guide/) for its frontend.
2525

26-
The HTML pages are rendered by [Go HTML Template](https://pkg.go.dev/html/template)
26+
The HTML pages are rendered by [Go HTML Template](https://pkg.go.dev/html/template).
27+
28+
The source files can be found in the following directories:
29+
* **Less styles:** `web_src/less/`
30+
* **Javascript files:** `web_src/js/`
31+
* **Vue layouts:** `web_src/js/components/`
32+
* **HTML templates:** `templates/`
2733

2834
## General Guidelines
2935

models/admin/main_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import (
1212
)
1313

1414
func TestMain(m *testing.M) {
15-
unittest.MainTest(m, filepath.Join("..", ".."),
16-
"notice.yml",
17-
)
15+
unittest.MainTest(m, &unittest.TestOptions{
16+
GiteaRootPath: filepath.Join("..", ".."),
17+
FixtureFiles: []string{"notice.yml"},
18+
})
1819
}

models/asymkey/main_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ func init() {
1818
}
1919

2020
func TestMain(m *testing.M) {
21-
unittest.MainTest(m, filepath.Join("..", ".."),
22-
"gpg_key.yml",
23-
"public_key.yml",
24-
"deploy_key.yml",
25-
"gpg_key_import.yml",
26-
"user.yml",
27-
"email_address.yml",
28-
)
21+
unittest.MainTest(m, &unittest.TestOptions{
22+
GiteaRootPath: filepath.Join("..", ".."),
23+
FixtureFiles: []string{
24+
"gpg_key.yml",
25+
"public_key.yml",
26+
"deploy_key.yml",
27+
"gpg_key_import.yml",
28+
"user.yml",
29+
"email_address.yml",
30+
},
31+
})
2932
}

models/auth/main_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ import (
1212
)
1313

1414
func TestMain(m *testing.M) {
15-
unittest.MainTest(m, filepath.Join("..", ".."),
16-
"login_source.yml",
17-
"oauth2_application.yml",
18-
"oauth2_authorization_code.yml",
19-
"oauth2_grant.yml",
20-
"webauthn_credential.yml",
21-
)
15+
unittest.MainTest(m, &unittest.TestOptions{
16+
GiteaRootPath: filepath.Join("..", ".."),
17+
FixtureFiles: []string{
18+
"login_source.yml",
19+
"oauth2_application.yml",
20+
"oauth2_authorization_code.yml",
21+
"oauth2_grant.yml",
22+
"webauthn_credential.yml",
23+
},
24+
})
2225
}

models/db/paginator/main_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ import (
1212
)
1313

1414
func TestMain(m *testing.M) {
15-
unittest.MainTest(m, filepath.Join("..", "..", ".."))
15+
unittest.MainTest(m, &unittest.TestOptions{
16+
GiteaRootPath: filepath.Join("..", "..", ".."),
17+
})
1618
}

models/issues/main_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ func init() {
1818
}
1919

2020
func TestMain(m *testing.M) {
21-
unittest.MainTest(m, filepath.Join("..", ".."),
22-
"reaction.yml",
23-
"user.yml",
24-
"repository.yml",
25-
"milestone.yml",
26-
)
21+
unittest.MainTest(m, &unittest.TestOptions{
22+
GiteaRootPath: filepath.Join("..", ".."),
23+
FixtureFiles: []string{
24+
"reaction.yml",
25+
"user.yml",
26+
"repository.yml",
27+
"milestone.yml",
28+
},
29+
})
2730
}

models/main_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ func TestFixturesAreConsistent(t *testing.T) {
3737
}
3838

3939
func TestMain(m *testing.M) {
40-
unittest.MainTest(m, "..")
40+
unittest.MainTest(m, &unittest.TestOptions{
41+
GiteaRootPath: "..",
42+
})
4143
}

models/organization/main_test.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ import (
1212
)
1313

1414
func TestMain(m *testing.M) {
15-
unittest.MainTest(m, filepath.Join("..", ".."),
16-
"user.yml",
17-
"org_user.yml",
18-
"team.yml",
19-
"team_repo.yml",
20-
"team_unit.yml",
21-
"team_user.yml",
22-
"repository.yml",
23-
)
15+
unittest.MainTest(m, &unittest.TestOptions{
16+
GiteaRootPath: filepath.Join("..", ".."),
17+
FixtureFiles: []string{
18+
"user.yml",
19+
"org_user.yml",
20+
"team.yml",
21+
"team_repo.yml",
22+
"team_unit.yml",
23+
"team_user.yml",
24+
"repository.yml",
25+
},
26+
})
2427
}

models/project/main_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ import (
1414
)
1515

1616
func TestMain(m *testing.M) {
17-
unittest.MainTest(m, filepath.Join("..", ".."),
18-
"project.yml",
19-
"project_board.yml",
20-
"project_issue.yml",
21-
"repository.yml",
22-
)
17+
unittest.MainTest(m, &unittest.TestOptions{
18+
GiteaRootPath: filepath.Join("..", ".."),
19+
FixtureFiles: []string{
20+
"project.yml",
21+
"project_board.yml",
22+
"project_issue.yml",
23+
"repository.yml",
24+
},
25+
})
2326
}

models/repo/main_test.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ import (
1212
)
1313

1414
func TestMain(m *testing.M) {
15-
unittest.MainTest(m, filepath.Join("..", ".."),
16-
"attachment.yml",
17-
"repo_archiver.yml",
18-
"repository.yml",
19-
"repo_unit.yml",
20-
"repo_indexer_status.yml",
21-
"repo_redirect.yml",
22-
"watch.yml",
23-
"star.yml",
24-
"topic.yml",
25-
"repo_topic.yml",
26-
"user.yml",
27-
)
15+
unittest.MainTest(m, &unittest.TestOptions{
16+
GiteaRootPath: filepath.Join("..", ".."),
17+
FixtureFiles: []string{
18+
"attachment.yml",
19+
"repo_archiver.yml",
20+
"repository.yml",
21+
"repo_unit.yml",
22+
"repo_indexer_status.yml",
23+
"repo_redirect.yml",
24+
"watch.yml",
25+
"star.yml",
26+
"topic.yml",
27+
"repo_topic.yml",
28+
"user.yml",
29+
},
30+
})
2831
}

models/unittest/testdb.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,27 @@ func fatalTestError(fmtStr string, args ...interface{}) {
3939
os.Exit(1)
4040
}
4141

42+
// TestOptions represents test options
43+
type TestOptions struct {
44+
GiteaRootPath string
45+
FixtureFiles []string
46+
SetUp func() error // SetUp will be executed before all tests in this package
47+
TearDown func() error // TearDown will be executed after all tests in this package
48+
}
49+
4250
// MainTest a reusable TestMain(..) function for unit tests that need to use a
4351
// test database. Creates the test database, and sets necessary settings.
44-
func MainTest(m *testing.M, pathToGiteaRoot string, fixtureFiles ...string) {
52+
func MainTest(m *testing.M, testOpts *TestOptions) {
4553
var err error
4654

47-
giteaRoot = pathToGiteaRoot
48-
fixturesDir = filepath.Join(pathToGiteaRoot, "models", "fixtures")
55+
giteaRoot = testOpts.GiteaRootPath
56+
fixturesDir = filepath.Join(testOpts.GiteaRootPath, "models", "fixtures")
4957

5058
var opts FixturesOptions
51-
if len(fixtureFiles) == 0 {
59+
if len(testOpts.FixtureFiles) == 0 {
5260
opts.Dir = fixturesDir
5361
} else {
54-
for _, f := range fixtureFiles {
62+
for _, f := range testOpts.FixtureFiles {
5563
if len(f) != 0 {
5664
opts.Files = append(opts.Files, filepath.Join(fixturesDir, f))
5765
}
@@ -80,8 +88,8 @@ func MainTest(m *testing.M, pathToGiteaRoot string, fixtureFiles ...string) {
8088
fatalTestError("TempDir: %v\n", err)
8189
}
8290
setting.AppDataPath = appDataPath
83-
setting.AppWorkPath = pathToGiteaRoot
84-
setting.StaticRootPath = pathToGiteaRoot
91+
setting.AppWorkPath = testOpts.GiteaRootPath
92+
setting.StaticRootPath = testOpts.GiteaRootPath
8593
setting.GravatarSourceURL, err = url.Parse("https://secure.gravatar.com/avatar/")
8694
if err != nil {
8795
fatalTestError("url.Parse: %v\n", err)
@@ -105,7 +113,7 @@ func MainTest(m *testing.M, pathToGiteaRoot string, fixtureFiles ...string) {
105113
if err = util.RemoveAll(repoRootPath); err != nil {
106114
fatalTestError("util.RemoveAll: %v\n", err)
107115
}
108-
if err = CopyDir(filepath.Join(pathToGiteaRoot, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
116+
if err = CopyDir(filepath.Join(testOpts.GiteaRootPath, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
109117
fatalTestError("util.CopyDir: %v\n", err)
110118
}
111119

@@ -129,7 +137,20 @@ func MainTest(m *testing.M, pathToGiteaRoot string, fixtureFiles ...string) {
129137
}
130138
}
131139

140+
if testOpts.SetUp != nil {
141+
if err := testOpts.SetUp(); err != nil {
142+
fatalTestError("set up failed: %v\n", err)
143+
}
144+
}
145+
132146
exitStatus := m.Run()
147+
148+
if testOpts.TearDown != nil {
149+
if err := testOpts.TearDown(); err != nil {
150+
fatalTestError("tear down failed: %v\n", err)
151+
}
152+
}
153+
133154
if err = util.RemoveAll(repoRootPath); err != nil {
134155
fatalTestError("util.RemoveAll: %v\n", err)
135156
}

models/user/main_test.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ import (
1212
)
1313

1414
func TestMain(m *testing.M) {
15-
unittest.MainTest(m, filepath.Join("..", ".."),
16-
"email_address.yml",
17-
"user_redirect.yml",
18-
"follow.yml",
19-
"user_open_id.yml",
20-
"two_factor.yml",
21-
"oauth2_application.yml",
22-
"user.yml",
23-
)
15+
unittest.MainTest(m, &unittest.TestOptions{
16+
GiteaRootPath: filepath.Join("..", ".."),
17+
FixtureFiles: []string{
18+
"email_address.yml",
19+
"user_redirect.yml",
20+
"follow.yml",
21+
"user_open_id.yml",
22+
"two_factor.yml",
23+
"oauth2_application.yml",
24+
"user.yml",
25+
},
26+
})
2427
}

models/webhook/main_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ import (
1212
)
1313

1414
func TestMain(m *testing.M) {
15-
unittest.MainTest(m, filepath.Join("..", ".."), "webhook.yml", "hook_task.yml")
15+
unittest.MainTest(m, &unittest.TestOptions{
16+
GiteaRootPath: filepath.Join("..", ".."),
17+
FixtureFiles: []string{
18+
"webhook.yml",
19+
"hook_task.yml",
20+
},
21+
})
1622
}

modules/appstate/appstate_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import (
1414
)
1515

1616
func TestMain(m *testing.M) {
17-
unittest.MainTest(m, filepath.Join("..", ".."), "")
17+
unittest.MainTest(m, &unittest.TestOptions{
18+
GiteaRootPath: filepath.Join("..", ".."),
19+
FixtureFiles: []string{""}, // load nothing
20+
})
1821
}
1922

2023
type testItem1 struct {

modules/convert/main_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ import (
1212
)
1313

1414
func TestMain(m *testing.M) {
15-
unittest.MainTest(m, filepath.Join("..", ".."))
15+
unittest.MainTest(m, &unittest.TestOptions{
16+
GiteaRootPath: filepath.Join("..", ".."),
17+
})
1618
}

modules/indexer/code/indexer_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import (
1818
)
1919

2020
func TestMain(m *testing.M) {
21-
unittest.MainTest(m, filepath.Join("..", "..", ".."))
21+
unittest.MainTest(m, &unittest.TestOptions{
22+
GiteaRootPath: filepath.Join("..", "..", ".."),
23+
})
2224
}
2325

2426
func testIndexer(name string, t *testing.T, indexer Indexer) {

modules/indexer/issues/indexer_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323
)
2424

2525
func TestMain(m *testing.M) {
26-
unittest.MainTest(m, filepath.Join("..", "..", ".."))
26+
unittest.MainTest(m, &unittest.TestOptions{
27+
GiteaRootPath: filepath.Join("..", "..", ".."),
28+
})
2729
}
2830

2931
func TestBleveSearchIssues(t *testing.T) {

modules/indexer/stats/indexer_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323
)
2424

2525
func TestMain(m *testing.M) {
26-
unittest.MainTest(m, filepath.Join("..", "..", ".."))
26+
unittest.MainTest(m, &unittest.TestOptions{
27+
GiteaRootPath: filepath.Join("..", "..", ".."),
28+
})
2729
}
2830

2931
func TestRepoStatsIndex(t *testing.T) {

modules/notification/action/action_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import (
1818
)
1919

2020
func TestMain(m *testing.M) {
21-
unittest.MainTest(m, filepath.Join("..", "..", ".."))
21+
unittest.MainTest(m, &unittest.TestOptions{
22+
GiteaRootPath: filepath.Join("..", "..", ".."),
23+
})
2224
}
2325

2426
func TestRenameRepoAction(t *testing.T) {

modules/repository/main_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ import (
1212
)
1313

1414
func TestMain(m *testing.M) {
15-
unittest.MainTest(m, filepath.Join("..", ".."))
15+
unittest.MainTest(m, &unittest.TestOptions{
16+
GiteaRootPath: filepath.Join("..", ".."),
17+
})
1618
}

options/locale/locale_ru-RU.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ pulls.manually_merged=Слито вручную
14311431
pulls.manually_merged_as=Запрос на слияние был объединён вручную, как <a rel="nofollow" class="ui sha" href="%[1]s"><code>%[2]s</code></a>.
14321432
pulls.is_closed=Запрос на слияние был закрыт.
14331433
pulls.has_merged=Слияние этого запроса успешно завершено.
1434-
pulls.title_wip_desc=`<a href="#">Добавьте <strong>%s</strong> в начало заголовка</a> для защиты от случайного досрочного принятия запроса на слияние
1434+
pulls.title_wip_desc=`<a href="#">Добавьте <strong>%s</strong> в начало заголовка</a> для защиты от случайного досрочного принятия запроса на слияние`
14351435
pulls.cannot_merge_work_in_progress=Этот запрос на слияние помечен как в процессе работы.
14361436
pulls.still_in_progress=Всё ещё в процессе?
14371437
pulls.add_prefix=Добавить <strong>%s</strong> префикс

routers/api/v1/repo/main_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ import (
1212
)
1313

1414
func TestMain(m *testing.M) {
15-
unittest.MainTest(m, filepath.Join("..", "..", "..", ".."))
15+
unittest.MainTest(m, &unittest.TestOptions{
16+
GiteaRootPath: filepath.Join("..", "..", "..", ".."),
17+
})
1618
}

0 commit comments

Comments
 (0)