Skip to content

Commit e96565b

Browse files
committed
Merge remote-tracking branch 'origin/main' into really-escape
2 parents 141e0bf + 0db7a32 commit e96565b

Some content is hidden

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

52 files changed

+2309
-3989
lines changed

.eslintrc

+2
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

-1
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

+16-1
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

models/consistency.go

+33-20
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ import (
1010
"testing"
1111

1212
"code.gitea.io/gitea/models/db"
13+
1314
"github.com/stretchr/testify/assert"
1415
"xorm.io/builder"
1516
)
1617

17-
// consistencyCheckable a type that can be tested for database consistency
18-
type consistencyCheckable interface {
19-
checkForConsistency(t *testing.T)
20-
}
21-
2218
// CheckConsistencyForAll test that the entire database is consistent
2319
func CheckConsistencyForAll(t *testing.T) {
2420
CheckConsistencyFor(t,
@@ -46,17 +42,34 @@ func CheckConsistencyFor(t *testing.T, beansToCheck ...interface{}) {
4642

4743
for i := 0; i < sliceValue.Len(); i++ {
4844
entity := sliceValue.Index(i).Interface()
49-
checkable, ok := entity.(consistencyCheckable)
50-
if !ok {
51-
t.Errorf("Expected %+v (of type %T) to be checkable for consistency",
52-
entity, entity)
53-
} else {
54-
checkable.checkForConsistency(t)
55-
}
45+
checkForConsistency(entity, t)
5646
}
5747
}
5848
}
5949

50+
func checkForConsistency(bean interface{}, t *testing.T) {
51+
switch b := bean.(type) {
52+
case *User:
53+
checkForUserConsistency(b, t)
54+
case *Repository:
55+
checkForRepoConsistency(b, t)
56+
case *Issue:
57+
checkForIssueConsistency(b, t)
58+
case *PullRequest:
59+
checkForPullRequestConsistency(b, t)
60+
case *Milestone:
61+
checkForMilestoneConsistency(b, t)
62+
case *Label:
63+
checkForLabelConsistency(b, t)
64+
case *Team:
65+
checkForTeamConsistency(b, t)
66+
case *Action:
67+
checkForActionConsistency(b, t)
68+
default:
69+
t.Errorf("unknown bean type: %#v", bean)
70+
}
71+
}
72+
6073
// getCount get the count of database entries matching bean
6174
func getCount(t *testing.T, e db.Engine, bean interface{}) int64 {
6275
count, err := e.Count(bean)
@@ -70,7 +83,7 @@ func assertCount(t *testing.T, bean interface{}, expected int) {
7083
"Failed consistency test, the counted bean (of type %T) was %+v", bean, bean)
7184
}
7285

73-
func (user *User) checkForConsistency(t *testing.T) {
86+
func checkForUserConsistency(user *User, t *testing.T) {
7487
assertCount(t, &Repository{OwnerID: user.ID}, user.NumRepos)
7588
assertCount(t, &Star{UID: user.ID}, user.NumStars)
7689
assertCount(t, &OrgUser{OrgID: user.ID}, user.NumMembers)
@@ -83,7 +96,7 @@ func (user *User) checkForConsistency(t *testing.T) {
8396
}
8497
}
8598

86-
func (repo *Repository) checkForConsistency(t *testing.T) {
99+
func checkForRepoConsistency(repo *Repository, t *testing.T) {
87100
assert.Equal(t, repo.LowerName, strings.ToLower(repo.Name), "repo: %+v", repo)
88101
assertCount(t, &Star{RepoID: repo.ID}, repo.NumStars)
89102
assertCount(t, &Milestone{RepoID: repo.ID}, repo.NumMilestones)
@@ -117,7 +130,7 @@ func (repo *Repository) checkForConsistency(t *testing.T) {
117130
"Unexpected number of closed milestones for repo %+v", repo)
118131
}
119132

120-
func (issue *Issue) checkForConsistency(t *testing.T) {
133+
func checkForIssueConsistency(issue *Issue, t *testing.T) {
121134
actual := getCount(t, db.GetEngine(db.DefaultContext).Where("type=?", CommentTypeComment), &Comment{IssueID: issue.ID})
122135
assert.EqualValues(t, issue.NumComments, actual,
123136
"Unexpected number of comments for issue %+v", issue)
@@ -127,13 +140,13 @@ func (issue *Issue) checkForConsistency(t *testing.T) {
127140
}
128141
}
129142

130-
func (pr *PullRequest) checkForConsistency(t *testing.T) {
143+
func checkForPullRequestConsistency(pr *PullRequest, t *testing.T) {
131144
issue := db.AssertExistsAndLoadBean(t, &Issue{ID: pr.IssueID}).(*Issue)
132145
assert.True(t, issue.IsPull)
133146
assert.EqualValues(t, issue.Index, pr.Index)
134147
}
135148

136-
func (milestone *Milestone) checkForConsistency(t *testing.T) {
149+
func checkForMilestoneConsistency(milestone *Milestone, t *testing.T) {
137150
assertCount(t, &Issue{MilestoneID: milestone.ID}, milestone.NumIssues)
138151

139152
actual := getCount(t, db.GetEngine(db.DefaultContext).Where("is_closed=?", true), &Issue{MilestoneID: milestone.ID})
@@ -147,7 +160,7 @@ func (milestone *Milestone) checkForConsistency(t *testing.T) {
147160
assert.Equal(t, completeness, milestone.Completeness)
148161
}
149162

150-
func (label *Label) checkForConsistency(t *testing.T) {
163+
func checkForLabelConsistency(label *Label, t *testing.T) {
151164
issueLabels := make([]*IssueLabel, 0, 10)
152165
assert.NoError(t, db.GetEngine(db.DefaultContext).Find(&issueLabels, &IssueLabel{LabelID: label.ID}))
153166
assert.EqualValues(t, label.NumIssues, len(issueLabels),
@@ -166,12 +179,12 @@ func (label *Label) checkForConsistency(t *testing.T) {
166179
"Unexpected number of closed issues for label %+v", label)
167180
}
168181

169-
func (team *Team) checkForConsistency(t *testing.T) {
182+
func checkForTeamConsistency(team *Team, t *testing.T) {
170183
assertCount(t, &TeamUser{TeamID: team.ID}, team.NumMembers)
171184
assertCount(t, &TeamRepo{TeamID: team.ID}, team.NumRepos)
172185
}
173186

174-
func (action *Action) checkForConsistency(t *testing.T) {
187+
func checkForActionConsistency(action *Action, t *testing.T) {
175188
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: action.RepoID}).(*Repository)
176189
assert.Equal(t, repo.IsPrivate, action.IsPrivate, "action: %+v", action)
177190
}

models/error.go

-75
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,6 @@ func (err ErrUserNotExist) Error() string {
123123
return fmt.Sprintf("user does not exist [uid: %d, name: %s, keyid: %d]", err.UID, err.Name, err.KeyID)
124124
}
125125

126-
// ErrUserRedirectNotExist represents a "UserRedirectNotExist" kind of error.
127-
type ErrUserRedirectNotExist struct {
128-
Name string
129-
}
130-
131-
// IsErrUserRedirectNotExist check if an error is an ErrUserRedirectNotExist.
132-
func IsErrUserRedirectNotExist(err error) bool {
133-
_, ok := err.(ErrUserRedirectNotExist)
134-
return ok
135-
}
136-
137-
func (err ErrUserRedirectNotExist) Error() string {
138-
return fmt.Sprintf("user redirect does not exist [name: %s]", err.Name)
139-
}
140-
141126
// ErrUserProhibitLogin represents a "ErrUserProhibitLogin" kind of error.
142127
type ErrUserProhibitLogin struct {
143128
UID int64
@@ -170,66 +155,6 @@ func (err ErrUserInactive) Error() string {
170155
return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name)
171156
}
172157

173-
// ErrEmailAlreadyUsed represents a "EmailAlreadyUsed" kind of error.
174-
type ErrEmailAlreadyUsed struct {
175-
Email string
176-
}
177-
178-
// IsErrEmailAlreadyUsed checks if an error is a ErrEmailAlreadyUsed.
179-
func IsErrEmailAlreadyUsed(err error) bool {
180-
_, ok := err.(ErrEmailAlreadyUsed)
181-
return ok
182-
}
183-
184-
func (err ErrEmailAlreadyUsed) Error() string {
185-
return fmt.Sprintf("e-mail already in use [email: %s]", err.Email)
186-
}
187-
188-
// ErrEmailInvalid represents an error where the email address does not comply with RFC 5322
189-
type ErrEmailInvalid struct {
190-
Email string
191-
}
192-
193-
// IsErrEmailInvalid checks if an error is an ErrEmailInvalid
194-
func IsErrEmailInvalid(err error) bool {
195-
_, ok := err.(ErrEmailInvalid)
196-
return ok
197-
}
198-
199-
func (err ErrEmailInvalid) Error() string {
200-
return fmt.Sprintf("e-mail invalid [email: %s]", err.Email)
201-
}
202-
203-
// ErrEmailAddressNotExist email address not exist
204-
type ErrEmailAddressNotExist struct {
205-
Email string
206-
}
207-
208-
// IsErrEmailAddressNotExist checks if an error is an ErrEmailAddressNotExist
209-
func IsErrEmailAddressNotExist(err error) bool {
210-
_, ok := err.(ErrEmailAddressNotExist)
211-
return ok
212-
}
213-
214-
func (err ErrEmailAddressNotExist) Error() string {
215-
return fmt.Sprintf("Email address does not exist [email: %s]", err.Email)
216-
}
217-
218-
// ErrPrimaryEmailCannotDelete primary email address cannot be deleted
219-
type ErrPrimaryEmailCannotDelete struct {
220-
Email string
221-
}
222-
223-
// IsErrPrimaryEmailCannotDelete checks if an error is an ErrPrimaryEmailCannotDelete
224-
func IsErrPrimaryEmailCannotDelete(err error) bool {
225-
_, ok := err.(ErrPrimaryEmailCannotDelete)
226-
return ok
227-
}
228-
229-
func (err ErrPrimaryEmailCannotDelete) Error() string {
230-
return fmt.Sprintf("Primary email address cannot be deleted [email: %s]", err.Email)
231-
}
232-
233158
// ErrOpenIDAlreadyUsed represents a "OpenIDAlreadyUsed" kind of error.
234159
type ErrOpenIDAlreadyUsed struct {
235160
OpenID string

models/error_oauth2.go

-24
This file was deleted.

models/gpg_key.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"code.gitea.io/gitea/models/db"
13+
user_model "code.gitea.io/gitea/models/user"
1314
"code.gitea.io/gitea/modules/log"
1415
"code.gitea.io/gitea/modules/timeutil"
1516

@@ -36,7 +37,7 @@ type GPGKey struct {
3637
ExpiredUnix timeutil.TimeStamp
3738
AddedUnix timeutil.TimeStamp
3839
SubsKey []*GPGKey `xorm:"-"`
39-
Emails []*EmailAddress
40+
Emails []*user_model.EmailAddress
4041
Verified bool `xorm:"NOT NULL DEFAULT false"`
4142
CanSign bool
4243
CanEncryptComms bool
@@ -148,12 +149,12 @@ func parseGPGKey(ownerID int64, e *openpgp.Entity, verified bool) (*GPGKey, erro
148149
}
149150

150151
// Check emails
151-
userEmails, err := GetEmailAddresses(ownerID)
152+
userEmails, err := user_model.GetEmailAddresses(ownerID)
152153
if err != nil {
153154
return nil, err
154155
}
155156

156-
emails := make([]*EmailAddress, 0, len(e.Identities))
157+
emails := make([]*user_model.EmailAddress, 0, len(e.Identities))
157158
for _, ident := range e.Identities {
158159
if ident.Revocation != nil {
159160
continue
@@ -242,7 +243,7 @@ func DeleteGPGKey(doer *User, id int64) (err error) {
242243

243244
func checkKeyEmails(email string, keys ...*GPGKey) (bool, string) {
244245
uid := int64(0)
245-
var userEmails []*EmailAddress
246+
var userEmails []*user_model.EmailAddress
246247
var user *User
247248
for _, key := range keys {
248249
for _, e := range key.Emails {
@@ -252,7 +253,7 @@ func checkKeyEmails(email string, keys ...*GPGKey) (bool, string) {
252253
}
253254
if key.Verified && key.OwnerID != 0 {
254255
if uid != key.OwnerID {
255-
userEmails, _ = GetEmailAddresses(key.OwnerID)
256+
userEmails, _ = user_model.GetEmailAddresses(key.OwnerID)
256257
uid = key.OwnerID
257258
user = &User{ID: uid}
258259
_, _ = GetUser(user)

models/gpg_key_commit_verification.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
"code.gitea.io/gitea/models/db"
13+
user_model "code.gitea.io/gitea/models/user"
1314
"code.gitea.io/gitea/modules/git"
1415
"code.gitea.io/gitea/modules/log"
1516
"code.gitea.io/gitea/modules/setting"
@@ -167,7 +168,7 @@ func ParseCommitWithSignature(c *git.Commit) *CommitVerification {
167168
}
168169
}
169170

170-
committerEmailAddresses, _ := GetEmailAddresses(committer.ID)
171+
committerEmailAddresses, _ := user_model.GetEmailAddresses(committer.ID)
171172
activated := false
172173
for _, e := range committerEmailAddresses {
173174
if e.IsActivated && strings.EqualFold(e.Email, c.Committer.Email) {

models/issue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type Issue struct {
7171
IsLocked bool `xorm:"NOT NULL DEFAULT false"`
7272

7373
// For view issue page.
74-
ShowTag CommentTag `xorm:"-"`
74+
ShowRole RoleDescriptor `xorm:"-"`
7575
}
7676

7777
var (

0 commit comments

Comments
 (0)