Skip to content

Commit b8a4432

Browse files
committed
Merge branch 'main' into lunny/transaction_merge
2 parents 3e320f8 + 0f3e717 commit b8a4432

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

+615
-476
lines changed

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
code.gitea.io/sdk/gitea v0.17.1
99
codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570
1010
connectrpc.com/connect v1.15.0
11-
gitea.com/go-chi/binding v0.0.0-20240316035258-17450c5f3028
11+
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed
1212
gitea.com/go-chi/cache v0.2.0
1313
gitea.com/go-chi/captcha v0.0.0-20240315150714-fb487f629098
1414
gitea.com/go-chi/session v0.0.0-20240316035857-16768d98ec96
@@ -59,6 +59,7 @@ require (
5959
github.com/google/uuid v1.6.0
6060
github.com/gorilla/feeds v1.1.2
6161
github.com/gorilla/sessions v1.2.2
62+
github.com/h2non/gock v1.2.0
6263
github.com/hashicorp/go-version v1.6.0
6364
github.com/hashicorp/golang-lru/v2 v2.0.7
6465
github.com/huandu/xstrings v1.4.0
@@ -209,6 +210,7 @@ require (
209210
github.com/gorilla/handlers v1.5.2 // indirect
210211
github.com/gorilla/mux v1.8.1 // indirect
211212
github.com/gorilla/securecookie v1.1.2 // indirect
213+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
212214
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
213215
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
214216
github.com/hashicorp/hcl v1.0.0 // indirect

go.sum

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:cliQ4H
2020
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs=
2121
gitea.com/gitea/act v0.259.1 h1:8GG1o/xtUHl3qjn5f0h/2FXrT5ubBn05TJOM5ry+FBw=
2222
gitea.com/gitea/act v0.259.1/go.mod h1:UxZWRYqQG2Yj4+4OqfGWW5a3HELwejyWFQyU7F1jUD8=
23-
gitea.com/go-chi/binding v0.0.0-20240316035258-17450c5f3028 h1:6/QAx4+s0dyRwdaTFPTnhGppuiuu0OqxIH9szyTpvKw=
24-
gitea.com/go-chi/binding v0.0.0-20240316035258-17450c5f3028/go.mod h1:E3i3cgB04dDx0v3CytCgRTTn9Z/9x891aet3r456RVw=
23+
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed h1:EZZBtilMLSZNWtHHcgq2mt6NSGhJSZBuduAlinMEmso=
24+
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed/go.mod h1:E3i3cgB04dDx0v3CytCgRTTn9Z/9x891aet3r456RVw=
2525
gitea.com/go-chi/cache v0.2.0 h1:E0npuTfDW6CT1yD8NMDVc1SK6IeRjfmRL2zlEsCEd7w=
2626
gitea.com/go-chi/cache v0.2.0/go.mod h1:iQlVK2aKTZ/rE9UcHyz9pQWGvdP9i1eI2spOpzgCrtE=
2727
gitea.com/go-chi/captcha v0.0.0-20240315150714-fb487f629098 h1:p2ki+WK0cIeNQuqjR98IP2KZQKRzJJiV7aTeMAFwaWo=
@@ -430,6 +430,10 @@ github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pw
430430
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
431431
github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY=
432432
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
433+
github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE=
434+
github.com/h2non/gock v1.2.0/go.mod h1:tNhoxHYW2W42cYkYb1WqzdbYIieALC99kpYr7rH/BQk=
435+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
436+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
433437
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
434438
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
435439
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
@@ -591,6 +595,8 @@ github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM=
591595
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
592596
github.com/msteinert/pam v1.2.0 h1:mYfjlvN2KYs2Pb9G6nb/1f/nPfAttT/Jee5Sq9r3bGE=
593597
github.com/msteinert/pam v1.2.0/go.mod h1:d2n0DCUK8rGecChV3JzvmsDjOY4R7AYbsNxAT+ftQl0=
598+
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
599+
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
594600
github.com/niklasfasching/go-org v1.7.0 h1:vyMdcMWWTe/XmANk19F4k8XGBYg0GQ/gJGMimOjGMek=
595601
github.com/niklasfasching/go-org v1.7.0/go.mod h1:WuVm4d45oePiE0eX25GqTDQIt/qPW1T9DGkRscqLW5o=
596602
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=

models/issues/issue_update.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -429,62 +429,6 @@ func UpdateIssueMentions(ctx context.Context, issueID int64, mentions []*user_mo
429429
return nil
430430
}
431431

432-
// UpdateIssueByAPI updates all allowed fields of given issue.
433-
// If the issue status is changed a statusChangeComment is returned
434-
// similarly if the title is changed the titleChanged bool is set to true
435-
func UpdateIssueByAPI(ctx context.Context, issue *Issue, doer *user_model.User) (statusChangeComment *Comment, titleChanged bool, err error) {
436-
ctx, committer, err := db.TxContext(ctx)
437-
if err != nil {
438-
return nil, false, err
439-
}
440-
defer committer.Close()
441-
442-
if err := issue.LoadRepo(ctx); err != nil {
443-
return nil, false, fmt.Errorf("loadRepo: %w", err)
444-
}
445-
446-
// Reload the issue
447-
currentIssue, err := GetIssueByID(ctx, issue.ID)
448-
if err != nil {
449-
return nil, false, err
450-
}
451-
452-
if _, err := db.GetEngine(ctx).ID(issue.ID).Cols(
453-
"name", "content", "milestone_id", "priority",
454-
"deadline_unix", "updated_unix", "is_locked").
455-
Update(issue); err != nil {
456-
return nil, false, err
457-
}
458-
459-
titleChanged = currentIssue.Title != issue.Title
460-
if titleChanged {
461-
opts := &CreateCommentOptions{
462-
Type: CommentTypeChangeTitle,
463-
Doer: doer,
464-
Repo: issue.Repo,
465-
Issue: issue,
466-
OldTitle: currentIssue.Title,
467-
NewTitle: issue.Title,
468-
}
469-
_, err := CreateComment(ctx, opts)
470-
if err != nil {
471-
return nil, false, fmt.Errorf("createComment: %w", err)
472-
}
473-
}
474-
475-
if currentIssue.IsClosed != issue.IsClosed {
476-
statusChangeComment, err = doChangeIssueStatus(ctx, issue, doer, false)
477-
if err != nil {
478-
return nil, false, err
479-
}
480-
}
481-
482-
if err := issue.AddCrossReferences(ctx, doer, true); err != nil {
483-
return nil, false, err
484-
}
485-
return statusChangeComment, titleChanged, committer.Commit()
486-
}
487-
488432
// UpdateIssueDeadline updates an issue deadline and adds comments. Setting a deadline to 0 means deleting it.
489433
func UpdateIssueDeadline(ctx context.Context, issue *Issue, deadlineUnix timeutil.TimeStamp, doer *user_model.User) (err error) {
490434
// if the deadline hasn't changed do nothing

modules/auth/password/pwn/pwn_test.go

Lines changed: 23 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
package pwn
55

66
import (
7-
"math/rand/v2"
87
"net/http"
9-
"strings"
108
"testing"
119
"time"
1210

11+
"github.com/h2non/gock"
1312
"github.com/stretchr/testify/assert"
1413
)
1514

@@ -18,86 +17,34 @@ var client = New(WithHTTP(&http.Client{
1817
}))
1918

2019
func TestPassword(t *testing.T) {
21-
// Check input error
22-
_, err := client.CheckPassword("", false)
20+
defer gock.Off()
21+
22+
count, err := client.CheckPassword("", false)
2323
assert.ErrorIs(t, err, ErrEmptyPassword, "blank input should return ErrEmptyPassword")
24+
assert.Equal(t, -1, count)
2425

25-
// Should fail
26-
fail := "password1234"
27-
count, err := client.CheckPassword(fail, false)
28-
assert.NotEmpty(t, count, "%s should fail as a password", fail)
26+
gock.New("https://api.pwnedpasswords.com").Get("/range/5c1d8").Times(1).Reply(200).BodyString("EAF2F254732680E8AC339B84F3266ECCBB5:1\r\nFC446EB88938834178CB9322C1EE273C2A7:2")
27+
count, err = client.CheckPassword("pwned", false)
2928
assert.NoError(t, err)
29+
assert.Equal(t, 1, count)
3030

31-
// Should fail (with padding)
32-
failPad := "administrator"
33-
count, err = client.CheckPassword(failPad, true)
34-
assert.NotEmpty(t, count, "%s should fail as a password", failPad)
31+
gock.New("https://api.pwnedpasswords.com").Get("/range/ba189").Times(1).Reply(200).BodyString("FD4CB34F0378BCB15D23F6FFD28F0775C9E:3\r\nFDF342FCD8C3611DAE4D76E8A992A3E4169:4")
32+
count, err = client.CheckPassword("notpwned", false)
3533
assert.NoError(t, err)
34+
assert.Equal(t, 0, count)
3635

37-
// Checking for a "good" password isn't going to be perfect, but we can give it a good try
38-
// with hopefully minimal error. Try five times?
39-
assert.Condition(t, func() bool {
40-
for i := 0; i <= 5; i++ {
41-
count, err = client.CheckPassword(testPassword(), false)
42-
assert.NoError(t, err)
43-
if count == 0 {
44-
return true
45-
}
46-
}
47-
return false
48-
}, "no generated passwords passed. there is a chance this is a fluke")
49-
50-
// Again, but with padded responses
51-
assert.Condition(t, func() bool {
52-
for i := 0; i <= 5; i++ {
53-
count, err = client.CheckPassword(testPassword(), true)
54-
assert.NoError(t, err)
55-
if count == 0 {
56-
return true
57-
}
58-
}
59-
return false
60-
}, "no generated passwords passed. there is a chance this is a fluke")
61-
}
62-
63-
// Credit to https://golangbyexample.com/generate-random-password-golang/
64-
// DO NOT USE THIS FOR AN ACTUAL PASSWORD GENERATOR
65-
var (
66-
lowerCharSet = "abcdedfghijklmnopqrst"
67-
upperCharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
68-
specialCharSet = "!@#$%&*"
69-
numberSet = "0123456789"
70-
allCharSet = lowerCharSet + upperCharSet + specialCharSet + numberSet
71-
)
72-
73-
func testPassword() string {
74-
var password strings.Builder
75-
76-
// Set special character
77-
for i := 0; i < 5; i++ {
78-
random := rand.IntN(len(specialCharSet))
79-
password.WriteString(string(specialCharSet[random]))
80-
}
81-
82-
// Set numeric
83-
for i := 0; i < 5; i++ {
84-
random := rand.IntN(len(numberSet))
85-
password.WriteString(string(numberSet[random]))
86-
}
36+
gock.New("https://api.pwnedpasswords.com").Get("/range/a1733").Times(1).Reply(200).BodyString("C4CE0F1F0062B27B9E2F41AF0C08218017C:1\r\nFC446EB88938834178CB9322C1EE273C2A7:2\r\nFE81480327C992FE62065A827429DD1318B:0")
37+
count, err = client.CheckPassword("paddedpwned", true)
38+
assert.NoError(t, err)
39+
assert.Equal(t, 1, count)
8740

88-
// Set uppercase
89-
for i := 0; i < 5; i++ {
90-
random := rand.IntN(len(upperCharSet))
91-
password.WriteString(string(upperCharSet[random]))
92-
}
41+
gock.New("https://api.pwnedpasswords.com").Get("/range/5617b").Times(1).Reply(200).BodyString("FD4CB34F0378BCB15D23F6FFD28F0775C9E:3\r\nFDF342FCD8C3611DAE4D76E8A992A3E4169:4\r\nFE81480327C992FE62065A827429DD1318B:0")
42+
count, err = client.CheckPassword("paddednotpwned", true)
43+
assert.NoError(t, err)
44+
assert.Equal(t, 0, count)
9345

94-
for i := 0; i < 5; i++ {
95-
random := rand.IntN(len(allCharSet))
96-
password.WriteString(string(allCharSet[random]))
97-
}
98-
inRune := []rune(password.String())
99-
rand.Shuffle(len(inRune), func(i, j int) {
100-
inRune[i], inRune[j] = inRune[j], inRune[i]
101-
})
102-
return string(inRune)
46+
gock.New("https://api.pwnedpasswords.com").Get("/range/79082").Times(1).Reply(200).BodyString("FDF342FCD8C3611DAE4D76E8A992A3E4169:4\r\nFE81480327C992FE62065A827429DD1318B:0\r\nAFEF386F56EB0B4BE314E07696E5E6E6536:0")
47+
count, err = client.CheckPassword("paddednotpwnedzero", true)
48+
assert.NoError(t, err)
49+
assert.Equal(t, 0, count)
10350
}

modules/git/grep.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type GrepOptions struct {
2929
ContextLineNumber int
3030
IsFuzzy bool
3131
MaxLineLength int // the maximum length of a line to parse, exceeding chars will be truncated
32+
PathspecList []string
3233
}
3334

3435
func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepOptions) ([]*GrepResult, error) {
@@ -62,6 +63,7 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
6263
cmd.AddOptionValues("-e", strings.TrimLeft(search, "-"))
6364
}
6465
cmd.AddDynamicArguments(util.IfZero(opts.RefName, "HEAD"))
66+
cmd.AddDashesAndList(opts.PathspecList...)
6567
opts.MaxResultLimit = util.IfZero(opts.MaxResultLimit, 50)
6668
stderr := bytes.Buffer{}
6769
err = cmd.Run(&RunOpts{

modules/git/grep_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ func TestGrepSearch(t *testing.T) {
3131
},
3232
}, res)
3333

34+
res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{PathspecList: []string{":(glob)java-hello/*"}})
35+
assert.NoError(t, err)
36+
assert.Equal(t, []*GrepResult{
37+
{
38+
Filename: "java-hello/main.java",
39+
LineNumbers: []int{3},
40+
LineCodes: []string{" public static void main(String[] args)"},
41+
},
42+
}, res)
43+
44+
res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{PathspecList: []string{":(glob,exclude)java-hello/*"}})
45+
assert.NoError(t, err)
46+
assert.Equal(t, []*GrepResult{
47+
{
48+
Filename: "main.vendor.java",
49+
LineNumbers: []int{3},
50+
LineCodes: []string{" public static void main(String[] args)"},
51+
},
52+
}, res)
53+
3454
res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{MaxResultLimit: 1})
3555
assert.NoError(t, err)
3656
assert.Equal(t, []*GrepResult{

modules/setting/glob.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package setting
5+
6+
import "github.com/gobwas/glob"
7+
8+
type GlobMatcher struct {
9+
compiledGlob glob.Glob
10+
patternString string
11+
}
12+
13+
var _ glob.Glob = (*GlobMatcher)(nil)
14+
15+
func (g *GlobMatcher) Match(s string) bool {
16+
return g.compiledGlob.Match(s)
17+
}
18+
19+
func (g *GlobMatcher) PatternString() string {
20+
return g.patternString
21+
}
22+
23+
func GlobMatcherCompile(pattern string, separators ...rune) (*GlobMatcher, error) {
24+
g, err := glob.Compile(pattern, separators...)
25+
if err != nil {
26+
return nil, err
27+
}
28+
return &GlobMatcher{
29+
compiledGlob: g,
30+
patternString: pattern,
31+
}, nil
32+
}

modules/setting/indexer.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"time"
1111

1212
"code.gitea.io/gitea/modules/log"
13-
14-
"github.com/gobwas/glob"
1513
)
1614

1715
// Indexer settings
@@ -30,8 +28,8 @@ var Indexer = struct {
3028
RepoConnStr string
3129
RepoIndexerName string
3230
MaxIndexerFileSize int64
33-
IncludePatterns []glob.Glob
34-
ExcludePatterns []glob.Glob
31+
IncludePatterns []*GlobMatcher
32+
ExcludePatterns []*GlobMatcher
3533
ExcludeVendored bool
3634
}{
3735
IssueType: "bleve",
@@ -93,12 +91,12 @@ func loadIndexerFrom(rootCfg ConfigProvider) {
9391
}
9492

9593
// IndexerGlobFromString parses a comma separated list of patterns and returns a glob.Glob slice suited for repo indexing
96-
func IndexerGlobFromString(globstr string) []glob.Glob {
97-
extarr := make([]glob.Glob, 0, 10)
94+
func IndexerGlobFromString(globstr string) []*GlobMatcher {
95+
extarr := make([]*GlobMatcher, 0, 10)
9896
for _, expr := range strings.Split(strings.ToLower(globstr), ",") {
9997
expr = strings.TrimSpace(expr)
10098
if expr != "" {
101-
if g, err := glob.Compile(expr, '.', '/'); err != nil {
99+
if g, err := GlobMatcherCompile(expr, '.', '/'); err != nil {
102100
log.Info("Invalid glob expression '%s' (skipped): %v", expr, err)
103101
} else {
104102
extarr = append(extarr, g)

modules/structs/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type CreatePullRequestOption struct {
8585
// EditPullRequestOption options when modify pull request
8686
type EditPullRequestOption struct {
8787
Title string `json:"title"`
88-
Body string `json:"body"`
88+
Body *string `json:"body"`
8989
Base string `json:"base"`
9090
Assignee string `json:"assignee"`
9191
Assignees []string `json:"assignees"`

0 commit comments

Comments
 (0)