Skip to content

Commit 2f5df7e

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Add support for commit cross references (go-gitea#22645) Fix missing message in git hook when pull requests disabled on fork (go-gitea#22625) Check quota limits for container uploads (go-gitea#22450) Consume hcaptcha and pwn deps (go-gitea#22610) Issues: add Project filter to issues list and search (go-gitea#22544) Improve accessibility of navigation bar and footer (go-gitea#22635) Support system hook API (go-gitea#14537) Improve checkIfPRContentChanged (go-gitea#22611)
2 parents 683a2a1 + d0d257b commit 2f5df7e

37 files changed

+1338
-233
lines changed

assets/go-licenses.json

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/generate-go-licenses.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"io/fs"
1111
"os"
12+
goPath "path"
1213
"path/filepath"
1314
"regexp"
1415
"sort"
@@ -47,13 +48,15 @@ func main() {
4748

4849
entries := []LicenseEntry{}
4950
for _, path := range paths {
51+
path := filepath.ToSlash(path)
52+
5053
licenseText, err := os.ReadFile(path)
5154
if err != nil {
5255
panic(err)
5356
}
5457

55-
path := strings.Replace(path, base+string(os.PathSeparator), "", 1)
56-
name := filepath.Dir(path)
58+
path = strings.Replace(path, base+"/", "", 1)
59+
name := goPath.Dir(path)
5760

5861
// There might be a bug somewhere in go-licenses that sometimes interprets the
5962
// root package as "." and sometimes as "code.gitea.io/gitea". Workaround by

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ require (
9696
github.com/yuin/goldmark v1.5.3
9797
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20220924101305-151362477c87
9898
github.com/yuin/goldmark-meta v1.1.0
99-
go.jolheiser.com/hcaptcha v0.0.4
100-
go.jolheiser.com/pwn v0.0.3
10199
golang.org/x/crypto v0.4.0
102100
golang.org/x/net v0.4.0
103101
golang.org/x/oauth2 v0.3.0

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,10 +1267,6 @@ go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
12671267
go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU=
12681268
go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4=
12691269
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
1270-
go.jolheiser.com/hcaptcha v0.0.4 h1:RrDERcr/Tz/kWyJenjVtI+V09RtLinXxlAemiwN5F+I=
1271-
go.jolheiser.com/hcaptcha v0.0.4/go.mod h1:aw32WQOxnQZ6E06C0LypCf+sxNxPACyOnq+ZGnrIYho=
1272-
go.jolheiser.com/pwn v0.0.3 h1:MQowb3QvCL5r5NmHmCPxw93SdjfgJ0q6rAwYn4i1Hjg=
1273-
go.jolheiser.com/pwn v0.0.3/go.mod h1:/j5Dl8ftNqqJ8Dlx3YTrJV1wIR2lWOTyrNU3Qe7rk6I=
12741270
go.mongodb.org/mongo-driver v1.7.3/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R79oO62zWg=
12751271
go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng=
12761272
go.mongodb.org/mongo-driver v1.8.3/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY=

models/issues/issue.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,7 @@ type IssueStatsOptions struct {
15721572
RepoID int64
15731573
Labels string
15741574
MilestoneID int64
1575+
ProjectID int64
15751576
AssigneeID int64
15761577
MentionedID int64
15771578
PosterID int64
@@ -1650,6 +1651,11 @@ func getIssueStatsChunk(opts *IssueStatsOptions, issueIDs []int64) (*IssueStats,
16501651
sess.And("issue.milestone_id = ?", opts.MilestoneID)
16511652
}
16521653

1654+
if opts.ProjectID > 0 {
1655+
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
1656+
And("project_issue.project_id=?", opts.ProjectID)
1657+
}
1658+
16531659
if opts.AssigneeID > 0 {
16541660
applyAssigneeCondition(sess, opts.AssigneeID)
16551661
}

models/webhook/webhook.go

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -463,41 +463,6 @@ func CountWebhooksByOpts(opts *ListWebhookOptions) (int64, error) {
463463
return db.GetEngine(db.DefaultContext).Where(opts.toCond()).Count(&Webhook{})
464464
}
465465

466-
// GetDefaultWebhooks returns all admin-default webhooks.
467-
func GetDefaultWebhooks(ctx context.Context) ([]*Webhook, error) {
468-
webhooks := make([]*Webhook, 0, 5)
469-
return webhooks, db.GetEngine(ctx).
470-
Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, false).
471-
Find(&webhooks)
472-
}
473-
474-
// GetSystemOrDefaultWebhook returns admin system or default webhook by given ID.
475-
func GetSystemOrDefaultWebhook(id int64) (*Webhook, error) {
476-
webhook := &Webhook{ID: id}
477-
has, err := db.GetEngine(db.DefaultContext).
478-
Where("repo_id=? AND org_id=?", 0, 0).
479-
Get(webhook)
480-
if err != nil {
481-
return nil, err
482-
} else if !has {
483-
return nil, ErrWebhookNotExist{ID: id}
484-
}
485-
return webhook, nil
486-
}
487-
488-
// GetSystemWebhooks returns all admin system webhooks.
489-
func GetSystemWebhooks(ctx context.Context, isActive util.OptionalBool) ([]*Webhook, error) {
490-
webhooks := make([]*Webhook, 0, 5)
491-
if isActive.IsNone() {
492-
return webhooks, db.GetEngine(ctx).
493-
Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, true).
494-
Find(&webhooks)
495-
}
496-
return webhooks, db.GetEngine(ctx).
497-
Where("repo_id=? AND org_id=? AND is_system_webhook=? AND is_active = ?", 0, 0, true, isActive.IsTrue()).
498-
Find(&webhooks)
499-
}
500-
501466
// UpdateWebhook updates information of webhook.
502467
func UpdateWebhook(w *Webhook) error {
503468
_, err := db.GetEngine(db.DefaultContext).ID(w.ID).AllCols().Update(w)
@@ -545,44 +510,3 @@ func DeleteWebhookByOrgID(orgID, id int64) error {
545510
OrgID: orgID,
546511
})
547512
}
548-
549-
// DeleteDefaultSystemWebhook deletes an admin-configured default or system webhook (where Org and Repo ID both 0)
550-
func DeleteDefaultSystemWebhook(id int64) error {
551-
ctx, committer, err := db.TxContext(db.DefaultContext)
552-
if err != nil {
553-
return err
554-
}
555-
defer committer.Close()
556-
557-
count, err := db.GetEngine(ctx).
558-
Where("repo_id=? AND org_id=?", 0, 0).
559-
Delete(&Webhook{ID: id})
560-
if err != nil {
561-
return err
562-
} else if count == 0 {
563-
return ErrWebhookNotExist{ID: id}
564-
}
565-
566-
if _, err := db.DeleteByBean(ctx, &HookTask{HookID: id}); err != nil {
567-
return err
568-
}
569-
570-
return committer.Commit()
571-
}
572-
573-
// CopyDefaultWebhooksToRepo creates copies of the default webhooks in a new repo
574-
func CopyDefaultWebhooksToRepo(ctx context.Context, repoID int64) error {
575-
ws, err := GetDefaultWebhooks(ctx)
576-
if err != nil {
577-
return fmt.Errorf("GetDefaultWebhooks: %w", err)
578-
}
579-
580-
for _, w := range ws {
581-
w.ID = 0
582-
w.RepoID = repoID
583-
if err := CreateWebhook(ctx, w); err != nil {
584-
return fmt.Errorf("CreateWebhook: %w", err)
585-
}
586-
}
587-
return nil
588-
}

models/webhook/webhook_system.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package webhook
5+
6+
import (
7+
"context"
8+
"fmt"
9+
10+
"code.gitea.io/gitea/models/db"
11+
"code.gitea.io/gitea/modules/util"
12+
)
13+
14+
// GetDefaultWebhooks returns all admin-default webhooks.
15+
func GetDefaultWebhooks(ctx context.Context) ([]*Webhook, error) {
16+
webhooks := make([]*Webhook, 0, 5)
17+
return webhooks, db.GetEngine(ctx).
18+
Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, false).
19+
Find(&webhooks)
20+
}
21+
22+
// GetSystemOrDefaultWebhook returns admin system or default webhook by given ID.
23+
func GetSystemOrDefaultWebhook(ctx context.Context, id int64) (*Webhook, error) {
24+
webhook := &Webhook{ID: id}
25+
has, err := db.GetEngine(ctx).
26+
Where("repo_id=? AND org_id=?", 0, 0).
27+
Get(webhook)
28+
if err != nil {
29+
return nil, err
30+
} else if !has {
31+
return nil, ErrWebhookNotExist{ID: id}
32+
}
33+
return webhook, nil
34+
}
35+
36+
// GetSystemWebhooks returns all admin system webhooks.
37+
func GetSystemWebhooks(ctx context.Context, isActive util.OptionalBool) ([]*Webhook, error) {
38+
webhooks := make([]*Webhook, 0, 5)
39+
if isActive.IsNone() {
40+
return webhooks, db.GetEngine(ctx).
41+
Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, true).
42+
Find(&webhooks)
43+
}
44+
return webhooks, db.GetEngine(ctx).
45+
Where("repo_id=? AND org_id=? AND is_system_webhook=? AND is_active = ?", 0, 0, true, isActive.IsTrue()).
46+
Find(&webhooks)
47+
}
48+
49+
// DeleteDefaultSystemWebhook deletes an admin-configured default or system webhook (where Org and Repo ID both 0)
50+
func DeleteDefaultSystemWebhook(ctx context.Context, id int64) error {
51+
return db.WithTx(ctx, func(ctx context.Context) error {
52+
count, err := db.GetEngine(ctx).
53+
Where("repo_id=? AND org_id=?", 0, 0).
54+
Delete(&Webhook{ID: id})
55+
if err != nil {
56+
return err
57+
} else if count == 0 {
58+
return ErrWebhookNotExist{ID: id}
59+
}
60+
61+
_, err = db.DeleteByBean(ctx, &HookTask{HookID: id})
62+
return err
63+
})
64+
}
65+
66+
// CopyDefaultWebhooksToRepo creates copies of the default webhooks in a new repo
67+
func CopyDefaultWebhooksToRepo(ctx context.Context, repoID int64) error {
68+
ws, err := GetDefaultWebhooks(ctx)
69+
if err != nil {
70+
return fmt.Errorf("GetDefaultWebhooks: %v", err)
71+
}
72+
73+
for _, w := range ws {
74+
w.ID = 0
75+
w.RepoID = repoID
76+
if err := CreateWebhook(ctx, w); err != nil {
77+
return fmt.Errorf("CreateWebhook: %v", err)
78+
}
79+
}
80+
return nil
81+
}

modules/hcaptcha/error.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package hcaptcha
5+
6+
const (
7+
ErrMissingInputSecret ErrorCode = "missing-input-secret"
8+
ErrInvalidInputSecret ErrorCode = "invalid-input-secret"
9+
ErrMissingInputResponse ErrorCode = "missing-input-response"
10+
ErrInvalidInputResponse ErrorCode = "invalid-input-response"
11+
ErrBadRequest ErrorCode = "bad-request"
12+
ErrInvalidOrAlreadySeenResponse ErrorCode = "invalid-or-already-seen-response"
13+
ErrNotUsingDummyPasscode ErrorCode = "not-using-dummy-passcode"
14+
ErrSitekeySecretMismatch ErrorCode = "sitekey-secret-mismatch"
15+
)
16+
17+
// ErrorCode is any possible error from hCaptcha
18+
type ErrorCode string
19+
20+
// String fulfills the Stringer interface
21+
func (err ErrorCode) String() string {
22+
switch err {
23+
case ErrMissingInputSecret:
24+
return "Your secret key is missing."
25+
case ErrInvalidInputSecret:
26+
return "Your secret key is invalid or malformed."
27+
case ErrMissingInputResponse:
28+
return "The response parameter (verification token) is missing."
29+
case ErrInvalidInputResponse:
30+
return "The response parameter (verification token) is invalid or malformed."
31+
case ErrBadRequest:
32+
return "The request is invalid or malformed."
33+
case ErrInvalidOrAlreadySeenResponse:
34+
return "The response parameter has already been checked, or has another issue."
35+
case ErrNotUsingDummyPasscode:
36+
return "You have used a testing sitekey but have not used its matching secret."
37+
case ErrSitekeySecretMismatch:
38+
return "The sitekey is not registered with the provided secret."
39+
default:
40+
return ""
41+
}
42+
}
43+
44+
// Error fulfills the error interface
45+
func (err ErrorCode) Error() string {
46+
return err.String()
47+
}

0 commit comments

Comments
 (0)