Skip to content

Commit 340abb2

Browse files
committed
Merge remote-tracking branch 'origin/main' into add-gitattribute-assisted-language-detection
2 parents 5d9870f + 4744808 commit 340abb2

File tree

338 files changed

+5298
-6468
lines changed

Some content is hidden

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

338 files changed

+5298
-6468
lines changed

.eslintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ rules:
368368
unicorn/no-array-push-push: [2]
369369
unicorn/no-console-spaces: [0]
370370
unicorn/no-document-cookie: [2]
371+
unicorn/no-empty-file: [2]
371372
unicorn/no-fn-reference-in-iterator: [0]
372373
unicorn/no-for-loop: [0]
373374
unicorn/no-hex-escape: [0]
@@ -404,6 +405,7 @@ rules:
404405
unicorn/prefer-date-now: [2]
405406
unicorn/prefer-default-parameters: [0]
406407
unicorn/prefer-event-key: [2]
408+
unicorn/prefer-export-from: [2]
407409
unicorn/prefer-includes: [2]
408410
unicorn/prefer-math-trunc: [2]
409411
unicorn/prefer-modern-dom-apis: [0]

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ linters:
99
- unused
1010
- structcheck
1111
- varcheck
12-
- golint
1312
- dupl
1413
#- gocyclo # The cyclomatic complexety of a lot of functions is too high, we should refactor those another time.
1514
- gofmt

.stylelintrc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
extends: stylelint-config-standard
22

3+
overrides:
4+
- files: ["**/*.less"]
5+
customSyntax: postcss-less
6+
37
rules:
8+
alpha-value-notation: null
49
at-rule-empty-line-before: null
510
block-closing-brace-empty-line-before: null
11+
color-function-notation: null
612
color-hex-length: null
713
comment-empty-line-before: null
14+
declaration-block-no-redundant-longhand-properties: null
815
declaration-block-single-line-max-declarations: null
916
declaration-empty-line-before: null
17+
hue-degree-notation: null
1018
indentation: 2
19+
max-line-length: null
1120
no-descending-specificity: null
21+
no-invalid-position-at-import-rule: null
1222
number-leading-zero: never
23+
number-max-precision: null
24+
property-no-vendor-prefix: null
1325
rule-empty-line-before: null
26+
selector-class-pattern: null
27+
selector-id-pattern: null
1428
selector-pseudo-element-colon-notation: double
1529
shorthand-property-no-redundant-values: true
16-
no-invalid-position-at-import-rule: null
30+
string-quotes: null
31+
value-no-vendor-prefix: null

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Alexey Makhov <[email protected]> (@makhov)
2-
Andrey Nering <[email protected]> (@andreynering)
32
Bo-Yi Wu <[email protected]> (@appleboy)
43
Ethan Koenig <[email protected]> (@ethantkoenig)
54
Kees de Vries <[email protected]> (@Bwko)

contrib/fixtures/fixture_generation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"path/filepath"
1111

1212
"code.gitea.io/gitea/models"
13-
"code.gitea.io/gitea/models/db"
13+
"code.gitea.io/gitea/models/unittest"
1414
)
1515

1616
// To generate derivative fixtures, execute the following from Gitea's repository base dir:
@@ -31,13 +31,13 @@ var (
3131
func main() {
3232
pathToGiteaRoot := "."
3333
fixturesDir = filepath.Join(pathToGiteaRoot, "models", "fixtures")
34-
if err := db.CreateTestEngine(db.FixturesOptions{
34+
if err := unittest.CreateTestEngine(unittest.FixturesOptions{
3535
Dir: fixturesDir,
3636
}); err != nil {
3737
fmt.Printf("CreateTestEngine: %+v", err)
3838
os.Exit(1)
3939
}
40-
if err := db.PrepareTestDatabase(); err != nil {
40+
if err := unittest.PrepareTestDatabase(); err != nil {
4141
fmt.Printf("PrepareTestDatabase: %+v\n", err)
4242
os.Exit(1)
4343
}

contrib/pr/checkout.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"code.gitea.io/gitea/models"
2828
"code.gitea.io/gitea/models/db"
29+
"code.gitea.io/gitea/models/unittest"
2930
gitea_git "code.gitea.io/gitea/modules/git"
3031
"code.gitea.io/gitea/modules/markup"
3132
"code.gitea.io/gitea/modules/markup/external"
@@ -99,16 +100,16 @@ func runPR() {
99100
})
100101
db.HasEngine = true
101102
//x.ShowSQL(true)
102-
err = db.InitFixtures(
103-
db.FixturesOptions{
103+
err = unittest.InitFixtures(
104+
unittest.FixturesOptions{
104105
Dir: path.Join(curDir, "models/fixtures/"),
105106
},
106107
)
107108
if err != nil {
108109
fmt.Printf("Error initializing test database: %v\n", err)
109110
os.Exit(1)
110111
}
111-
db.LoadFixtures()
112+
unittest.LoadFixtures()
112113
util.RemoveAll(setting.RepoRootPath)
113114
util.RemoveAll(models.LocalCopyPath())
114115
util.CopyDir(path.Join(curDir, "integrations/gitea-repositories-meta"), setting.RepoRootPath)

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,65 @@ We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/h
3939
6. The backend can pass complex data to the frontend by using `ctx.PageData["myModuleData"] = map[]{}`
4040
7. Simple pages and SEO-related pages use Go HTML Template render to generate static Fomantic-UI HTML output. Complex pages can use Vue2 (or Vue3 in future).
4141

42+
43+
### `async` Functions
44+
45+
Only mark a function as `async` if and only if there are `await` calls
46+
or `Promise` returns inside the function.
47+
48+
It's not recommended to use `async` event listeners, which may lead to problems.
49+
The reason is that the code after await is executed outside the event dispatch.
50+
Reference: https://github.com/github/eslint-plugin-github/blob/main/docs/rules/async-preventdefault.md
51+
52+
If we want to call an `async` function in a non-async context,
53+
it's recommended to use `const _promise = asyncFoo()` to tell readers
54+
that this is done by purpose, we want to call the async function and ignore the Promise.
55+
Some lint rules and IDEs also have warnings if the returned Promise is not handled.
56+
57+
#### DOM Event Listener
58+
59+
```js
60+
el.addEventListener('click', (e) => {
61+
(async () => {
62+
await asyncFoo(); // recommended
63+
// then we shound't do e.preventDefault() after await, no effect
64+
})();
65+
66+
const _promise = asyncFoo(); // recommended
67+
68+
e.preventDefault(); // correct
69+
});
70+
71+
el.addEventListener('async', async (e) => { // not recommended but acceptable
72+
e.preventDefault(); // acceptable
73+
await asyncFoo(); // skip out event dispath
74+
e.preventDefault(); // WRONG
75+
});
76+
```
77+
78+
#### jQuery Event Listener
79+
80+
```js
81+
$('#el').on('click', (e) => {
82+
(async () => {
83+
await asyncFoo(); // recommended
84+
// then we shound't do e.preventDefault() after await, no effect
85+
})();
86+
87+
const _promise = asyncFoo(); // recommended
88+
89+
e.preventDefault(); // correct
90+
return false; // correct
91+
});
92+
93+
$('#el').on('click', async (e) => { // not recommended but acceptable
94+
e.preventDefault(); // acceptable
95+
return false; // WRONG, jQuery expects the returned value is a boolean, not a Promise
96+
await asyncFoo(); // skip out event dispath
97+
return false; // WRONG
98+
});
99+
```
100+
42101
### Vue2/Vue3 and JSX
43102

44103
Gitea is using Vue2 now, we plan to upgrade to Vue3. We decided not to introduce JSX to keep the HTML and the JavaScript code separated.

integrations/api_issue_label_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"strings"
1111
"testing"
1212

13+
"code.gitea.io/gitea/models/unittest"
14+
1315
"code.gitea.io/gitea/models"
1416
"code.gitea.io/gitea/models/db"
1517
api "code.gitea.io/gitea/modules/structs"
@@ -18,7 +20,7 @@ import (
1820
)
1921

2022
func TestAPIModifyLabels(t *testing.T) {
21-
assert.NoError(t, db.LoadFixtures())
23+
assert.NoError(t, unittest.LoadFixtures())
2224

2325
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
2426
owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -88,7 +90,7 @@ func TestAPIModifyLabels(t *testing.T) {
8890
}
8991

9092
func TestAPIAddIssueLabels(t *testing.T) {
91-
assert.NoError(t, db.LoadFixtures())
93+
assert.NoError(t, unittest.LoadFixtures())
9294

9395
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
9496
issue := db.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
@@ -111,7 +113,7 @@ func TestAPIAddIssueLabels(t *testing.T) {
111113
}
112114

113115
func TestAPIReplaceIssueLabels(t *testing.T) {
114-
assert.NoError(t, db.LoadFixtures())
116+
assert.NoError(t, unittest.LoadFixtures())
115117

116118
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
117119
issue := db.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
@@ -137,7 +139,7 @@ func TestAPIReplaceIssueLabels(t *testing.T) {
137139
}
138140

139141
func TestAPIModifyOrgLabels(t *testing.T) {
140-
assert.NoError(t, db.LoadFixtures())
142+
assert.NoError(t, unittest.LoadFixtures())
141143

142144
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
143145
owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)

integrations/api_repo_edit_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"code.gitea.io/gitea/models"
1414
"code.gitea.io/gitea/models/db"
15+
unit_model "code.gitea.io/gitea/models/unit"
1516
api "code.gitea.io/gitea/modules/structs"
1617

1718
"github.com/stretchr/testify/assert"
@@ -26,15 +27,15 @@ func getRepoEditOptionFromRepo(repo *models.Repository) *api.EditRepoOption {
2627
hasIssues := false
2728
var internalTracker *api.InternalTracker
2829
var externalTracker *api.ExternalTracker
29-
if unit, err := repo.GetUnit(models.UnitTypeIssues); err == nil {
30+
if unit, err := repo.GetUnit(unit_model.TypeIssues); err == nil {
3031
config := unit.IssuesConfig()
3132
hasIssues = true
3233
internalTracker = &api.InternalTracker{
3334
EnableTimeTracker: config.EnableTimetracker,
3435
AllowOnlyContributorsToTrackTime: config.AllowOnlyContributorsToTrackTime,
3536
EnableIssueDependencies: config.EnableDependencies,
3637
}
37-
} else if unit, err := repo.GetUnit(models.UnitTypeExternalTracker); err == nil {
38+
} else if unit, err := repo.GetUnit(unit_model.TypeExternalTracker); err == nil {
3839
config := unit.ExternalTrackerConfig()
3940
hasIssues = true
4041
externalTracker = &api.ExternalTracker{
@@ -45,9 +46,9 @@ func getRepoEditOptionFromRepo(repo *models.Repository) *api.EditRepoOption {
4546
}
4647
hasWiki := false
4748
var externalWiki *api.ExternalWiki
48-
if _, err := repo.GetUnit(models.UnitTypeWiki); err == nil {
49+
if _, err := repo.GetUnit(unit_model.TypeWiki); err == nil {
4950
hasWiki = true
50-
} else if unit, err := repo.GetUnit(models.UnitTypeExternalWiki); err == nil {
51+
} else if unit, err := repo.GetUnit(unit_model.TypeExternalWiki); err == nil {
5152
hasWiki = true
5253
config := unit.ExternalWikiConfig()
5354
externalWiki = &api.ExternalWiki{
@@ -61,7 +62,7 @@ func getRepoEditOptionFromRepo(repo *models.Repository) *api.EditRepoOption {
6162
allowRebase := false
6263
allowRebaseMerge := false
6364
allowSquash := false
64-
if unit, err := repo.GetUnit(models.UnitTypePullRequests); err == nil {
65+
if unit, err := repo.GetUnit(unit_model.TypePullRequests); err == nil {
6566
config := unit.PullRequestsConfig()
6667
hasPullRequests = true
6768
ignoreWhitespaceConflicts = config.IgnoreWhitespaceConflicts

integrations/integration_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"time"
2626

2727
"code.gitea.io/gitea/models"
28-
"code.gitea.io/gitea/models/db"
28+
"code.gitea.io/gitea/models/unittest"
2929
"code.gitea.io/gitea/modules/base"
3030
"code.gitea.io/gitea/modules/git"
3131
"code.gitea.io/gitea/modules/graceful"
@@ -84,6 +84,7 @@ func NewNilResponseHashSumRecorder() *NilResponseHashSumRecorder {
8484
func TestMain(m *testing.M) {
8585
defer log.Close()
8686

87+
unittest.InitUnitTestBridge()
8788
managerCtx, cancel := context.WithCancel(context.Background())
8889
graceful.InitManager(managerCtx)
8990
defer cancel()
@@ -112,8 +113,8 @@ func TestMain(m *testing.M) {
112113
}
113114
}
114115

115-
err := db.InitFixtures(
116-
db.FixturesOptions{
116+
err := unittest.InitFixtures(
117+
unittest.FixturesOptions{
117118
Dir: filepath.Join(filepath.Dir(setting.AppPath), "models/fixtures/"),
118119
},
119120
)
@@ -250,7 +251,7 @@ func prepareTestEnv(t testing.TB, skip ...int) func() {
250251
ourSkip += skip[0]
251252
}
252253
deferFn := PrintCurrentTest(t, ourSkip)
253-
assert.NoError(t, db.LoadFixtures())
254+
assert.NoError(t, unittest.LoadFixtures())
254255
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
255256

256257
assert.NoError(t, util.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
@@ -527,7 +528,7 @@ func GetCSRF(t testing.TB, session *TestSession, urlStr string) string {
527528
// within a single test this is required
528529
func resetFixtures(t *testing.T) {
529530
assert.NoError(t, queue.GetManager().FlushAll(context.Background(), -1))
530-
assert.NoError(t, db.LoadFixtures())
531+
assert.NoError(t, unittest.LoadFixtures())
531532
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
532533
assert.NoError(t, util.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
533534
}

integrations/migrate_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"os"
99
"testing"
1010

11+
"code.gitea.io/gitea/models/unittest"
12+
1113
"code.gitea.io/gitea/models"
1214
"code.gitea.io/gitea/models/db"
1315
"code.gitea.io/gitea/modules/migrations"
@@ -17,7 +19,7 @@ import (
1719
)
1820

1921
func TestMigrateLocalPath(t *testing.T) {
20-
assert.NoError(t, db.PrepareTestDatabase())
22+
assert.NoError(t, unittest.PrepareTestDatabase())
2123

2224
adminUser := db.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
2325

0 commit comments

Comments
 (0)