Skip to content

Commit 81b5af7

Browse files
authored
Merge branch 'main' into clonetweaks
2 parents cb12635 + e663c4a commit 81b5af7

Some content is hidden

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

60 files changed

+947
-978
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ COMMA := ,
2626
XGO_VERSION := go-1.23.x
2727

2828
AIR_PACKAGE ?= github.com/air-verse/air@v1
29-
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.0.3
29+
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.1.2
3030
GOFUMPT_PACKAGE ?= mvdan.cc/[email protected]
31-
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
31+
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.63.4
3232
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
3333
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/[email protected]
3434
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/[email protected]
3535
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
3636
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1
3737
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1
3838
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1
39-
GOPLS_PACKAGE ?= golang.org/x/tools/[email protected].0
39+
GOPLS_PACKAGE ?= golang.org/x/tools/[email protected].1
4040

4141
DOCKER_IMAGE ?= gitea/gitea
4242
DOCKER_TAG ?= latest

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,9 @@ LEVEL = Info
11291129
;; In default merge messages only include approvers who are official
11301130
;DEFAULT_MERGE_MESSAGE_OFFICIAL_APPROVERS_ONLY = true
11311131
;;
1132+
;; In default squash-merge messages include the commit message of all commits comprising the pull request.
1133+
;POPULATE_SQUASH_COMMENT_WITH_COMMIT_MESSAGES = false
1134+
;;
11321135
;; Add co-authored-by and co-committed-by trailers if committer does not match author
11331136
;ADD_CO_COMMITTER_TRAILERS = true
11341137
;;

models/db/name.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"code.gitea.io/gitea/modules/util"
1212
)
1313

14-
var ErrNameEmpty = util.SilentWrap{Message: "name is empty", Err: util.ErrInvalidArgument}
15-
1614
// ErrNameReserved represents a "reserved name" error.
1715
type ErrNameReserved struct {
1816
Name string
@@ -79,7 +77,7 @@ func (err ErrNameCharsNotAllowed) Unwrap() error {
7977
func IsUsableName(reservedNames, reservedPatterns []string, name string) error {
8078
name = strings.TrimSpace(strings.ToLower(name))
8179
if utf8.RuneCountInString(name) == 0 {
82-
return ErrNameEmpty
80+
return util.SilentWrap{Message: "name is empty", Err: util.ErrInvalidArgument}
8381
}
8482

8583
for i := range reservedNames {

models/repo/repo.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"regexp"
1515
"strconv"
1616
"strings"
17+
"sync"
1718

1819
"code.gitea.io/gitea/models/db"
1920
"code.gitea.io/gitea/models/unit"
@@ -61,20 +62,30 @@ func (err ErrRepoIsArchived) Error() string {
6162
return fmt.Sprintf("%s is archived", err.Repo.LogString())
6263
}
6364

64-
var (
65-
validRepoNamePattern = regexp.MustCompile(`[-.\w]+`)
66-
invalidRepoNamePattern = regexp.MustCompile(`[.]{2,}`)
67-
reservedRepoNames = []string{".", "..", "-"}
68-
reservedRepoPatterns = []string{"*.git", "*.wiki", "*.rss", "*.atom"}
69-
)
65+
type globalVarsStruct struct {
66+
validRepoNamePattern *regexp.Regexp
67+
invalidRepoNamePattern *regexp.Regexp
68+
reservedRepoNames []string
69+
reservedRepoPatterns []string
70+
}
71+
72+
var globalVars = sync.OnceValue(func() *globalVarsStruct {
73+
return &globalVarsStruct{
74+
validRepoNamePattern: regexp.MustCompile(`[-.\w]+`),
75+
invalidRepoNamePattern: regexp.MustCompile(`[.]{2,}`),
76+
reservedRepoNames: []string{".", "..", "-"},
77+
reservedRepoPatterns: []string{"*.git", "*.wiki", "*.rss", "*.atom"},
78+
}
79+
})
7080

7181
// IsUsableRepoName returns true when name is usable
7282
func IsUsableRepoName(name string) error {
73-
if !validRepoNamePattern.MatchString(name) || invalidRepoNamePattern.MatchString(name) {
83+
vars := globalVars()
84+
if !vars.validRepoNamePattern.MatchString(name) || vars.invalidRepoNamePattern.MatchString(name) {
7485
// Note: usually this error is normally caught up earlier in the UI
7586
return db.ErrNameCharsNotAllowed{Name: name}
7687
}
77-
return db.IsUsableName(reservedRepoNames, reservedRepoPatterns, name)
88+
return db.IsUsableName(vars.reservedRepoNames, vars.reservedRepoPatterns, name)
7889
}
7990

8091
// TrustModelType defines the types of trust model for this repository

models/repo/repo_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,5 @@ func TestIsUsableRepoName(t *testing.T) {
219219
assert.Error(t, IsUsableRepoName("the..repo"))
220220
assert.Error(t, IsUsableRepoName("foo.wiki"))
221221
assert.Error(t, IsUsableRepoName("foo.git"))
222+
assert.Error(t, IsUsableRepoName("foo.RSS"))
222223
}

models/user/user.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,10 @@ func (u *User) IsMailable() bool {
502502
return u.IsActive
503503
}
504504

505-
// IsUserExist checks if given user name exist,
506-
// the user name should be noncased unique.
505+
// IsUserExist checks if given username exist,
506+
// the username should be non-cased unique.
507507
// If uid is presented, then check will rule out that one,
508-
// it is used when update a user name in settings page.
508+
// it is used when update a username in settings page.
509509
func IsUserExist(ctx context.Context, uid int64, name string) (bool, error) {
510510
if len(name) == 0 {
511511
return false, nil
@@ -515,7 +515,7 @@ func IsUserExist(ctx context.Context, uid int64, name string) (bool, error) {
515515
Get(&User{LowerName: strings.ToLower(name)})
516516
}
517517

518-
// Note: As of the beginning of 2022, it is recommended to use at least
518+
// SaltByteLength as of the beginning of 2022, it is recommended to use at least
519519
// 64 bits of salt, but NIST is already recommending to use to 128 bits.
520520
// (16 bytes = 16 * 8 = 128 bits)
521521
const SaltByteLength = 16

models/user/user_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ import (
2525
"github.com/stretchr/testify/assert"
2626
)
2727

28+
func TestIsUsableUsername(t *testing.T) {
29+
assert.NoError(t, user_model.IsUsableUsername("a"))
30+
assert.NoError(t, user_model.IsUsableUsername("foo.wiki"))
31+
assert.NoError(t, user_model.IsUsableUsername("foo.git"))
32+
33+
assert.Error(t, user_model.IsUsableUsername("a--b"))
34+
assert.Error(t, user_model.IsUsableUsername("-1_."))
35+
assert.Error(t, user_model.IsUsableUsername(".profile"))
36+
assert.Error(t, user_model.IsUsableUsername("-"))
37+
assert.Error(t, user_model.IsUsableUsername("🌞"))
38+
assert.Error(t, user_model.IsUsableUsername("the..repo"))
39+
assert.Error(t, user_model.IsUsableUsername("foo.RSS"))
40+
assert.Error(t, user_model.IsUsableUsername("foo.PnG"))
41+
}
42+
2843
func TestOAuth2Application_LoadUser(t *testing.T) {
2944
assert.NoError(t, unittest.PrepareTestDatabase())
3045
app := unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ID: 1})

models/webhook/webhook.go

Lines changed: 27 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -167,186 +167,39 @@ func (w *Webhook) UpdateEvent() error {
167167
return err
168168
}
169169

170-
// HasCreateEvent returns true if hook enabled create event.
171-
func (w *Webhook) HasCreateEvent() bool {
172-
return w.SendEverything ||
173-
(w.ChooseEvents && w.HookEvents.Create)
174-
}
175-
176-
// HasDeleteEvent returns true if hook enabled delete event.
177-
func (w *Webhook) HasDeleteEvent() bool {
178-
return w.SendEverything ||
179-
(w.ChooseEvents && w.HookEvents.Delete)
180-
}
181-
182-
// HasForkEvent returns true if hook enabled fork event.
183-
func (w *Webhook) HasForkEvent() bool {
184-
return w.SendEverything ||
185-
(w.ChooseEvents && w.HookEvents.Fork)
186-
}
187-
188-
// HasIssuesEvent returns true if hook enabled issues event.
189-
func (w *Webhook) HasIssuesEvent() bool {
190-
return w.SendEverything ||
191-
(w.ChooseEvents && w.HookEvents.Issues)
192-
}
193-
194-
// HasIssuesAssignEvent returns true if hook enabled issues assign event.
195-
func (w *Webhook) HasIssuesAssignEvent() bool {
196-
return w.SendEverything ||
197-
(w.ChooseEvents && w.HookEvents.IssueAssign)
198-
}
199-
200-
// HasIssuesLabelEvent returns true if hook enabled issues label event.
201-
func (w *Webhook) HasIssuesLabelEvent() bool {
202-
return w.SendEverything ||
203-
(w.ChooseEvents && w.HookEvents.IssueLabel)
204-
}
205-
206-
// HasIssuesMilestoneEvent returns true if hook enabled issues milestone event.
207-
func (w *Webhook) HasIssuesMilestoneEvent() bool {
208-
return w.SendEverything ||
209-
(w.ChooseEvents && w.HookEvents.IssueMilestone)
210-
}
211-
212-
// HasIssueCommentEvent returns true if hook enabled issue_comment event.
213-
func (w *Webhook) HasIssueCommentEvent() bool {
214-
return w.SendEverything ||
215-
(w.ChooseEvents && w.HookEvents.IssueComment)
216-
}
217-
218-
// HasPushEvent returns true if hook enabled push event.
219-
func (w *Webhook) HasPushEvent() bool {
220-
return w.PushOnly || w.SendEverything ||
221-
(w.ChooseEvents && w.HookEvents.Push)
222-
}
223-
224-
// HasPullRequestEvent returns true if hook enabled pull request event.
225-
func (w *Webhook) HasPullRequestEvent() bool {
226-
return w.SendEverything ||
227-
(w.ChooseEvents && w.HookEvents.PullRequest)
228-
}
229-
230-
// HasPullRequestAssignEvent returns true if hook enabled pull request assign event.
231-
func (w *Webhook) HasPullRequestAssignEvent() bool {
232-
return w.SendEverything ||
233-
(w.ChooseEvents && w.HookEvents.PullRequestAssign)
234-
}
235-
236-
// HasPullRequestLabelEvent returns true if hook enabled pull request label event.
237-
func (w *Webhook) HasPullRequestLabelEvent() bool {
238-
return w.SendEverything ||
239-
(w.ChooseEvents && w.HookEvents.PullRequestLabel)
240-
}
241-
242-
// HasPullRequestMilestoneEvent returns true if hook enabled pull request milestone event.
243-
func (w *Webhook) HasPullRequestMilestoneEvent() bool {
244-
return w.SendEverything ||
245-
(w.ChooseEvents && w.HookEvents.PullRequestMilestone)
246-
}
247-
248-
// HasPullRequestCommentEvent returns true if hook enabled pull_request_comment event.
249-
func (w *Webhook) HasPullRequestCommentEvent() bool {
250-
return w.SendEverything ||
251-
(w.ChooseEvents && w.HookEvents.PullRequestComment)
252-
}
253-
254-
// HasPullRequestApprovedEvent returns true if hook enabled pull request review event.
255-
func (w *Webhook) HasPullRequestApprovedEvent() bool {
256-
return w.SendEverything ||
257-
(w.ChooseEvents && w.HookEvents.PullRequestReview)
258-
}
259-
260-
// HasPullRequestRejectedEvent returns true if hook enabled pull request review event.
261-
func (w *Webhook) HasPullRequestRejectedEvent() bool {
262-
return w.SendEverything ||
263-
(w.ChooseEvents && w.HookEvents.PullRequestReview)
264-
}
265-
266-
// HasPullRequestReviewCommentEvent returns true if hook enabled pull request review event.
267-
func (w *Webhook) HasPullRequestReviewCommentEvent() bool {
268-
return w.SendEverything ||
269-
(w.ChooseEvents && w.HookEvents.PullRequestReview)
270-
}
271-
272-
// HasPullRequestSyncEvent returns true if hook enabled pull request sync event.
273-
func (w *Webhook) HasPullRequestSyncEvent() bool {
274-
return w.SendEverything ||
275-
(w.ChooseEvents && w.HookEvents.PullRequestSync)
276-
}
277-
278-
// HasWikiEvent returns true if hook enabled wiki event.
279-
func (w *Webhook) HasWikiEvent() bool {
280-
return w.SendEverything ||
281-
(w.ChooseEvents && w.HookEvent.Wiki)
282-
}
283-
284-
// HasReleaseEvent returns if hook enabled release event.
285-
func (w *Webhook) HasReleaseEvent() bool {
286-
return w.SendEverything ||
287-
(w.ChooseEvents && w.HookEvents.Release)
288-
}
289-
290-
// HasRepositoryEvent returns if hook enabled repository event.
291-
func (w *Webhook) HasRepositoryEvent() bool {
292-
return w.SendEverything ||
293-
(w.ChooseEvents && w.HookEvents.Repository)
294-
}
295-
296-
// HasPackageEvent returns if hook enabled package event.
297-
func (w *Webhook) HasPackageEvent() bool {
298-
return w.SendEverything ||
299-
(w.ChooseEvents && w.HookEvents.Package)
300-
}
301-
302-
// HasPullRequestReviewRequestEvent returns true if hook enabled pull request review request event.
303-
func (w *Webhook) HasPullRequestReviewRequestEvent() bool {
304-
return w.SendEverything ||
305-
(w.ChooseEvents && w.HookEvents.PullRequestReviewRequest)
306-
}
307-
308-
// EventCheckers returns event checkers
309-
func (w *Webhook) EventCheckers() []struct {
310-
Has func() bool
311-
Type webhook_module.HookEventType
312-
} {
313-
return []struct {
314-
Has func() bool
315-
Type webhook_module.HookEventType
316-
}{
317-
{w.HasCreateEvent, webhook_module.HookEventCreate},
318-
{w.HasDeleteEvent, webhook_module.HookEventDelete},
319-
{w.HasForkEvent, webhook_module.HookEventFork},
320-
{w.HasPushEvent, webhook_module.HookEventPush},
321-
{w.HasIssuesEvent, webhook_module.HookEventIssues},
322-
{w.HasIssuesAssignEvent, webhook_module.HookEventIssueAssign},
323-
{w.HasIssuesLabelEvent, webhook_module.HookEventIssueLabel},
324-
{w.HasIssuesMilestoneEvent, webhook_module.HookEventIssueMilestone},
325-
{w.HasIssueCommentEvent, webhook_module.HookEventIssueComment},
326-
{w.HasPullRequestEvent, webhook_module.HookEventPullRequest},
327-
{w.HasPullRequestAssignEvent, webhook_module.HookEventPullRequestAssign},
328-
{w.HasPullRequestLabelEvent, webhook_module.HookEventPullRequestLabel},
329-
{w.HasPullRequestMilestoneEvent, webhook_module.HookEventPullRequestMilestone},
330-
{w.HasPullRequestCommentEvent, webhook_module.HookEventPullRequestComment},
331-
{w.HasPullRequestApprovedEvent, webhook_module.HookEventPullRequestReviewApproved},
332-
{w.HasPullRequestRejectedEvent, webhook_module.HookEventPullRequestReviewRejected},
333-
{w.HasPullRequestCommentEvent, webhook_module.HookEventPullRequestReviewComment},
334-
{w.HasPullRequestSyncEvent, webhook_module.HookEventPullRequestSync},
335-
{w.HasWikiEvent, webhook_module.HookEventWiki},
336-
{w.HasRepositoryEvent, webhook_module.HookEventRepository},
337-
{w.HasReleaseEvent, webhook_module.HookEventRelease},
338-
{w.HasPackageEvent, webhook_module.HookEventPackage},
339-
{w.HasPullRequestReviewRequestEvent, webhook_module.HookEventPullRequestReviewRequest},
170+
func (w *Webhook) HasEvent(evt webhook_module.HookEventType) bool {
171+
if w.SendEverything {
172+
return true
340173
}
174+
if w.PushOnly {
175+
return evt == webhook_module.HookEventPush
176+
}
177+
checkEvt := evt
178+
switch evt {
179+
case webhook_module.HookEventPullRequestReviewApproved, webhook_module.HookEventPullRequestReviewRejected, webhook_module.HookEventPullRequestReviewComment:
180+
checkEvt = webhook_module.HookEventPullRequestReview
181+
}
182+
return w.HookEvents[checkEvt]
341183
}
342184

343185
// EventsArray returns an array of hook events
344186
func (w *Webhook) EventsArray() []string {
345-
events := make([]string, 0, 7)
187+
if w.SendEverything {
188+
events := make([]string, 0, len(webhook_module.AllEvents()))
189+
for _, evt := range webhook_module.AllEvents() {
190+
events = append(events, string(evt))
191+
}
192+
return events
193+
}
194+
195+
if w.PushOnly {
196+
return []string{string(webhook_module.HookEventPush)}
197+
}
346198

347-
for _, c := range w.EventCheckers() {
348-
if c.Has() {
349-
events = append(events, string(c.Type))
199+
events := make([]string, 0, len(w.HookEvents))
200+
for event, enabled := range w.HookEvents {
201+
if enabled {
202+
events = append(events, string(event))
350203
}
351204
}
352205
return events

models/webhook/webhook_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ func TestWebhook_UpdateEvent(t *testing.T) {
5454
SendEverything: false,
5555
ChooseEvents: false,
5656
HookEvents: webhook_module.HookEvents{
57-
Create: false,
58-
Push: true,
59-
PullRequest: false,
57+
webhook_module.HookEventCreate: false,
58+
webhook_module.HookEventPush: true,
59+
webhook_module.HookEventPullRequest: false,
6060
},
6161
}
6262
webhook.HookEvent = hookEvent
@@ -68,13 +68,13 @@ func TestWebhook_UpdateEvent(t *testing.T) {
6868
}
6969

7070
func TestWebhook_EventsArray(t *testing.T) {
71-
assert.Equal(t, []string{
71+
assert.EqualValues(t, []string{
7272
"create", "delete", "fork", "push",
7373
"issues", "issue_assign", "issue_label", "issue_milestone", "issue_comment",
7474
"pull_request", "pull_request_assign", "pull_request_label", "pull_request_milestone",
7575
"pull_request_comment", "pull_request_review_approved", "pull_request_review_rejected",
76-
"pull_request_review_comment", "pull_request_sync", "wiki", "repository", "release",
77-
"package", "pull_request_review_request",
76+
"pull_request_review_comment", "pull_request_sync", "pull_request_review_request", "wiki", "repository", "release",
77+
"package", "status",
7878
},
7979
(&Webhook{
8080
HookEvent: &webhook_module.HookEvent{SendEverything: true},

0 commit comments

Comments
 (0)