Skip to content

Commit dfbd08f

Browse files
committed
Merge remote-tracking branch 'origin/main' into really-escape
2 parents 55eedb9 + 43bbc54 commit dfbd08f

File tree

174 files changed

+1743
-1524
lines changed

Some content is hidden

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

174 files changed

+1743
-1524
lines changed

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Alexey Makhov <amakhov@avito.ru> (@makhov)
2-
Andrey Nering <andrey.nering@gmail.com> (@andreynering)
32
Bo-Yi Wu <appleboy.tw@gmail.com> (@appleboy)
43
Ethan Koenig <ethantkoenig@gmail.com> (@ethantkoenig)
54
Kees de Vries <bouwko@gmail.com> (@Bwko)

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/pull_merge_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"code.gitea.io/gitea/models"
2020
"code.gitea.io/gitea/models/db"
21+
"code.gitea.io/gitea/models/webhook"
2122
"code.gitea.io/gitea/modules/git"
2223
api "code.gitea.io/gitea/modules/structs"
2324
"code.gitea.io/gitea/modules/test"
@@ -62,7 +63,7 @@ func testPullCleanUp(t *testing.T, session *TestSession, user, repo, pullnum str
6263

6364
func TestPullMerge(t *testing.T) {
6465
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
65-
hookTasks, err := models.HookTasks(1, 1) //Retrieve previous hook number
66+
hookTasks, err := webhook.HookTasks(1, 1) //Retrieve previous hook number
6667
assert.NoError(t, err)
6768
hookTasksLenBefore := len(hookTasks)
6869

@@ -76,15 +77,15 @@ func TestPullMerge(t *testing.T) {
7677
assert.EqualValues(t, "pulls", elem[3])
7778
testPullMerge(t, session, elem[1], elem[2], elem[4], models.MergeStyleMerge)
7879

79-
hookTasks, err = models.HookTasks(1, 1)
80+
hookTasks, err = webhook.HookTasks(1, 1)
8081
assert.NoError(t, err)
8182
assert.Len(t, hookTasks, hookTasksLenBefore+1)
8283
})
8384
}
8485

8586
func TestPullRebase(t *testing.T) {
8687
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
87-
hookTasks, err := models.HookTasks(1, 1) //Retrieve previous hook number
88+
hookTasks, err := webhook.HookTasks(1, 1) //Retrieve previous hook number
8889
assert.NoError(t, err)
8990
hookTasksLenBefore := len(hookTasks)
9091

@@ -98,15 +99,15 @@ func TestPullRebase(t *testing.T) {
9899
assert.EqualValues(t, "pulls", elem[3])
99100
testPullMerge(t, session, elem[1], elem[2], elem[4], models.MergeStyleRebase)
100101

101-
hookTasks, err = models.HookTasks(1, 1)
102+
hookTasks, err = webhook.HookTasks(1, 1)
102103
assert.NoError(t, err)
103104
assert.Len(t, hookTasks, hookTasksLenBefore+1)
104105
})
105106
}
106107

107108
func TestPullRebaseMerge(t *testing.T) {
108109
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
109-
hookTasks, err := models.HookTasks(1, 1) //Retrieve previous hook number
110+
hookTasks, err := webhook.HookTasks(1, 1) //Retrieve previous hook number
110111
assert.NoError(t, err)
111112
hookTasksLenBefore := len(hookTasks)
112113

@@ -120,15 +121,15 @@ func TestPullRebaseMerge(t *testing.T) {
120121
assert.EqualValues(t, "pulls", elem[3])
121122
testPullMerge(t, session, elem[1], elem[2], elem[4], models.MergeStyleRebaseMerge)
122123

123-
hookTasks, err = models.HookTasks(1, 1)
124+
hookTasks, err = webhook.HookTasks(1, 1)
124125
assert.NoError(t, err)
125126
assert.Len(t, hookTasks, hookTasksLenBefore+1)
126127
})
127128
}
128129

129130
func TestPullSquash(t *testing.T) {
130131
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
131-
hookTasks, err := models.HookTasks(1, 1) //Retrieve previous hook number
132+
hookTasks, err := webhook.HookTasks(1, 1) //Retrieve previous hook number
132133
assert.NoError(t, err)
133134
hookTasksLenBefore := len(hookTasks)
134135

@@ -143,7 +144,7 @@ func TestPullSquash(t *testing.T) {
143144
assert.EqualValues(t, "pulls", elem[3])
144145
testPullMerge(t, session, elem[1], elem[2], elem[4], models.MergeStyleSquash)
145146

146-
hookTasks, err = models.HookTasks(1, 1)
147+
hookTasks, err = webhook.HookTasks(1, 1)
147148
assert.NoError(t, err)
148149
assert.Len(t, hookTasks, hookTasksLenBefore+1)
149150
})

models/attachment.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path"
1212

1313
"code.gitea.io/gitea/models/db"
14+
"code.gitea.io/gitea/models/unit"
1415
"code.gitea.io/gitea/modules/setting"
1516
"code.gitea.io/gitea/modules/storage"
1617
"code.gitea.io/gitea/modules/timeutil"
@@ -63,25 +64,25 @@ func (a *Attachment) DownloadURL() string {
6364
}
6465

6566
// LinkedRepository returns the linked repo if any
66-
func (a *Attachment) LinkedRepository() (*Repository, UnitType, error) {
67+
func (a *Attachment) LinkedRepository() (*Repository, unit.Type, error) {
6768
if a.IssueID != 0 {
6869
iss, err := GetIssueByID(a.IssueID)
6970
if err != nil {
70-
return nil, UnitTypeIssues, err
71+
return nil, unit.TypeIssues, err
7172
}
7273
repo, err := GetRepositoryByID(iss.RepoID)
73-
unitType := UnitTypeIssues
74+
unitType := unit.TypeIssues
7475
if iss.IsPull {
75-
unitType = UnitTypePullRequests
76+
unitType = unit.TypePullRequests
7677
}
7778
return repo, unitType, err
7879
} else if a.ReleaseID != 0 {
7980
rel, err := GetReleaseByID(a.ReleaseID)
8081
if err != nil {
81-
return nil, UnitTypeReleases, err
82+
return nil, unit.TypeReleases, err
8283
}
8384
repo, err := GetRepositoryByID(rel.RepoID)
84-
return repo, UnitTypeReleases, err
85+
return repo, unit.TypeReleases, err
8586
}
8687
return nil, -1, nil
8788
}

models/attachment_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"code.gitea.io/gitea/models/db"
11+
"code.gitea.io/gitea/models/unit"
1112
"github.com/stretchr/testify/assert"
1213
)
1314

@@ -107,11 +108,11 @@ func TestLinkedRepository(t *testing.T) {
107108
name string
108109
attachID int64
109110
expectedRepo *Repository
110-
expectedUnitType UnitType
111+
expectedUnitType unit.Type
111112
}{
112-
{"LinkedIssue", 1, &Repository{ID: 1}, UnitTypeIssues},
113-
{"LinkedComment", 3, &Repository{ID: 1}, UnitTypePullRequests},
114-
{"LinkedRelease", 9, &Repository{ID: 1}, UnitTypeReleases},
113+
{"LinkedIssue", 1, &Repository{ID: 1}, unit.TypeIssues},
114+
{"LinkedComment", 3, &Repository{ID: 1}, unit.TypePullRequests},
115+
{"LinkedRelease", 9, &Repository{ID: 1}, unit.TypeReleases},
115116
{"Notlinked", 10, nil, -1},
116117
}
117118
for _, tc := range testCases {

models/branches.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"code.gitea.io/gitea/models/db"
14+
"code.gitea.io/gitea/models/unit"
1415
"code.gitea.io/gitea/modules/base"
1516
"code.gitea.io/gitea/modules/log"
1617
"code.gitea.io/gitea/modules/timeutil"
@@ -74,7 +75,7 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
7475
} else if repo, err := GetRepositoryByID(protectBranch.RepoID); err != nil {
7576
log.Error("GetRepositoryByID: %v", err)
7677
return false
77-
} else if writeAccess, err := HasAccessUnit(user, repo, UnitTypeCode, AccessModeWrite); err != nil {
78+
} else if writeAccess, err := HasAccessUnit(user, repo, unit.TypeCode, AccessModeWrite); err != nil {
7879
log.Error("HasAccessUnit: %v", err)
7980
return false
8081
} else {
@@ -102,7 +103,7 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
102103
func (protectBranch *ProtectedBranch) IsUserMergeWhitelisted(userID int64, permissionInRepo Permission) bool {
103104
if !protectBranch.EnableMergeWhitelist {
104105
// Then we need to fall back on whether the user has write permission
105-
return permissionInRepo.CanWrite(UnitTypeCode)
106+
return permissionInRepo.CanWrite(unit.TypeCode)
106107
}
107108

108109
if base.Int64sContains(protectBranch.MergeWhitelistUserIDs, userID) {
@@ -134,7 +135,7 @@ func (protectBranch *ProtectedBranch) isUserOfficialReviewer(e db.Engine, user *
134135

135136
if !protectBranch.EnableApprovalsWhitelist {
136137
// Anyone with write access is considered official reviewer
137-
writeAccess, err := hasAccessUnit(e, user, repo, UnitTypeCode, AccessModeWrite)
138+
writeAccess, err := hasAccessUnit(e, user, repo, unit.TypeCode, AccessModeWrite)
138139
if err != nil {
139140
return false, err
140141
}
@@ -454,7 +455,7 @@ func updateUserWhitelist(repo *Repository, currentWhitelist, newWhitelist []int6
454455
return nil, fmt.Errorf("GetUserRepoPermission [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err)
455456
}
456457

457-
if !perm.CanWrite(UnitTypeCode) {
458+
if !perm.CanWrite(unit.TypeCode) {
458459
continue // Drop invalid user ID
459460
}
460461

models/db/error.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package db
6+
7+
import "fmt"
8+
9+
// ErrCancelled represents an error due to context cancellation
10+
type ErrCancelled struct {
11+
Message string
12+
}
13+
14+
// IsErrCancelled checks if an error is a ErrCancelled.
15+
func IsErrCancelled(err error) bool {
16+
_, ok := err.(ErrCancelled)
17+
return ok
18+
}
19+
20+
func (err ErrCancelled) Error() string {
21+
return "Cancelled: " + err.Message
22+
}
23+
24+
// ErrCancelledf returns an ErrCancelled for the provided format and args
25+
func ErrCancelledf(format string, args ...interface{}) error {
26+
return ErrCancelled{
27+
fmt.Sprintf(format, args...),
28+
}
29+
}

models/error.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,6 @@ func (err ErrSSHDisabled) Error() string {
8484
return "SSH is disabled"
8585
}
8686

87-
// ErrCancelled represents an error due to context cancellation
88-
type ErrCancelled struct {
89-
Message string
90-
}
91-
92-
// IsErrCancelled checks if an error is a ErrCancelled.
93-
func IsErrCancelled(err error) bool {
94-
_, ok := err.(ErrCancelled)
95-
return ok
96-
}
97-
98-
func (err ErrCancelled) Error() string {
99-
return "Cancelled: " + err.Message
100-
}
101-
102-
// ErrCancelledf returns an ErrCancelled for the provided format and args
103-
func ErrCancelledf(format string, args ...interface{}) error {
104-
return ErrCancelled{
105-
fmt.Sprintf(format, args...),
106-
}
107-
}
108-
10987
// ____ ___
11088
// | | \______ ___________
11189
// | | / ___// __ \_ __ \
@@ -1309,28 +1287,6 @@ func (err ErrSHAOrCommitIDNotProvided) Error() string {
13091287
return "a SHA or commit ID must be proved when updating a file"
13101288
}
13111289

1312-
// __ __ ___. .__ __
1313-
// / \ / \ ____\_ |__ | |__ ____ ____ | | __
1314-
// \ \/\/ // __ \| __ \| | \ / _ \ / _ \| |/ /
1315-
// \ /\ ___/| \_\ \ Y ( <_> | <_> ) <
1316-
// \__/\ / \___ >___ /___| /\____/ \____/|__|_ \
1317-
// \/ \/ \/ \/ \/
1318-
1319-
// ErrWebhookNotExist represents a "WebhookNotExist" kind of error.
1320-
type ErrWebhookNotExist struct {
1321-
ID int64
1322-
}
1323-
1324-
// IsErrWebhookNotExist checks if an error is a ErrWebhookNotExist.
1325-
func IsErrWebhookNotExist(err error) bool {
1326-
_, ok := err.(ErrWebhookNotExist)
1327-
return ok
1328-
}
1329-
1330-
func (err ErrWebhookNotExist) Error() string {
1331-
return fmt.Sprintf("webhook does not exist [id: %d]", err.ID)
1332-
}
1333-
13341290
// .___
13351291
// | | ______ ________ __ ____
13361292
// | |/ ___// ___/ | \_/ __ \

models/fixtures/u2f_registration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-
22
id: 1
33
name: "U2F Key"
4-
user_id: 1
4+
user_id: 32
55
counter: 0
66
created_unix: 946684800
77
updated_unix: 946684800

models/fixtures/user.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,19 @@
542542
avatar_email: user31@example.com
543543
num_repos: 0
544544
is_active: true
545+
546+
-
547+
id: 32
548+
lower_name: user32
549+
name: user32
550+
full_name: User 32 (U2F test)
551+
email: user32@example.com
552+
passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password
553+
type: 0 # individual
554+
salt: ZogKvWdyEx
555+
is_admin: false
556+
is_restricted: false
557+
avatar: avatar32
558+
avatar_email: user30@example.com
559+
num_repos: 0
560+
is_active: true

0 commit comments

Comments
 (0)