Skip to content

Commit 2a8c8e3

Browse files
authored
Merge branch 'main' into issue-comment-event
2 parents 6e33761 + 182b9c1 commit 2a8c8e3

File tree

86 files changed

+1266
-552
lines changed

Some content is hidden

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

86 files changed

+1266
-552
lines changed

.eslintrc.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ rules:
296296
jquery/no-delegate: [2]
297297
jquery/no-each: [0]
298298
jquery/no-extend: [2]
299-
jquery/no-fade: [0]
299+
jquery/no-fade: [2]
300300
jquery/no-filter: [0]
301301
jquery/no-find: [0]
302302
jquery/no-global-eval: [2]
@@ -309,7 +309,7 @@ rules:
309309
jquery/no-is-function: [2]
310310
jquery/no-is: [0]
311311
jquery/no-load: [2]
312-
jquery/no-map: [0]
312+
jquery/no-map: [2]
313313
jquery/no-merge: [2]
314314
jquery/no-param: [2]
315315
jquery/no-parent: [0]
@@ -451,7 +451,7 @@ rules:
451451
no-jquery/no-load: [2]
452452
no-jquery/no-map-collection: [0]
453453
no-jquery/no-map-util: [2]
454-
no-jquery/no-map: [0]
454+
no-jquery/no-map: [2]
455455
no-jquery/no-merge: [2]
456456
no-jquery/no-node-name: [2]
457457
no-jquery/no-noop: [2]

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,7 @@ test-mssql\#%: integrations.mssql.test generate-ini-mssql
602602
test-mssql-migration: migrations.mssql.test migrations.individual.mssql.test
603603

604604
.PHONY: playwright
605-
playwright: $(PLAYWRIGHT_DIR)
606-
npm install --no-save @playwright/test
605+
playwright: deps-frontend
607606
npx playwright install $(PLAYWRIGHT_FLAGS)
608607

609608
.PHONY: test-e2e%

docs/content/usage/issue-pull-request-templates.en-us.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ menu:
1919

2020
Some projects have a standard list of questions that users need to answer
2121
when creating an issue or pull request. Gitea supports adding templates to the
22-
main branch of the repository so that they can autopopulate the form when users are
22+
**default branch of the repository** so that they can autopopulate the form when users are
2323
creating issues and pull requests. This will cut down on the initial back and forth
2424
of getting some clarifying details.
25+
It is currently not possible to provide generic issue/pull-request templates globally.
2526

2627
Additionally, the New Issue page URL can be suffixed with `?title=Issue+Title&body=Issue+Text` and the form will be populated with those strings. Those strings will be used instead of the template if there is one.
2728

models/issues/review.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,14 @@ func IsOfficialReviewerTeam(ctx context.Context, issue *Issue, team *organizatio
292292

293293
// CreateReview creates a new review based on opts
294294
func CreateReview(ctx context.Context, opts CreateReviewOptions) (*Review, error) {
295+
ctx, committer, err := db.TxContext(ctx)
296+
if err != nil {
297+
return nil, err
298+
}
299+
defer committer.Close()
300+
sess := db.GetEngine(ctx)
301+
295302
review := &Review{
296-
Type: opts.Type,
297303
Issue: opts.Issue,
298304
IssueID: opts.Issue.ID,
299305
Reviewer: opts.Reviewer,
@@ -303,15 +309,39 @@ func CreateReview(ctx context.Context, opts CreateReviewOptions) (*Review, error
303309
CommitID: opts.CommitID,
304310
Stale: opts.Stale,
305311
}
312+
306313
if opts.Reviewer != nil {
314+
review.Type = opts.Type
307315
review.ReviewerID = opts.Reviewer.ID
308-
} else {
309-
if review.Type != ReviewTypeRequest {
310-
review.Type = ReviewTypeRequest
316+
317+
reviewCond := builder.Eq{"reviewer_id": opts.Reviewer.ID, "issue_id": opts.Issue.ID}
318+
// make sure user review requests are cleared
319+
if opts.Type != ReviewTypePending {
320+
if _, err := sess.Where(reviewCond.And(builder.Eq{"type": ReviewTypeRequest})).Delete(new(Review)); err != nil {
321+
return nil, err
322+
}
311323
}
324+
// make sure if the created review gets dismissed no old review surface
325+
// other types can be ignored, as they don't affect branch protection
326+
if opts.Type == ReviewTypeApprove || opts.Type == ReviewTypeReject {
327+
if _, err := sess.Where(reviewCond.And(builder.In("type", ReviewTypeApprove, ReviewTypeReject))).
328+
Cols("dismissed").Update(&Review{Dismissed: true}); err != nil {
329+
return nil, err
330+
}
331+
}
332+
333+
} else if opts.ReviewerTeam != nil {
334+
review.Type = ReviewTypeRequest
312335
review.ReviewerTeamID = opts.ReviewerTeam.ID
336+
337+
} else {
338+
return nil, fmt.Errorf("provide either reviewer or reviewer team")
339+
}
340+
341+
if _, err := sess.Insert(review); err != nil {
342+
return nil, err
313343
}
314-
return review, db.Insert(ctx, review)
344+
return review, committer.Commit()
315345
}
316346

317347
// GetCurrentReview returns the current pending review of reviewer for given issue

models/unittest/unit_tests.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ func AssertSuccessfulInsert(t assert.TestingT, beans ...any) {
131131
}
132132

133133
// AssertCount assert the count of a bean
134-
func AssertCount(t assert.TestingT, bean, expected any) {
135-
assert.EqualValues(t, expected, GetCount(t, bean))
134+
func AssertCount(t assert.TestingT, bean, expected any) bool {
135+
return assert.EqualValues(t, expected, GetCount(t, bean))
136136
}
137137

138138
// AssertInt64InRange assert value is in range [low, high]
@@ -150,7 +150,7 @@ func GetCountByCond(t assert.TestingT, tableName string, cond builder.Cond) int6
150150
}
151151

152152
// AssertCountByCond test the count of database entries matching bean
153-
func AssertCountByCond(t assert.TestingT, tableName string, cond builder.Cond, expected int) {
154-
assert.EqualValues(t, expected, GetCountByCond(t, tableName, cond),
153+
func AssertCountByCond(t assert.TestingT, tableName string, cond builder.Cond, expected int) bool {
154+
return assert.EqualValues(t, expected, GetCountByCond(t, tableName, cond),
155155
"Failed consistency test, the counted bean (of table %s) was %+v", tableName, cond)
156156
}

modules/context/context_template.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ package context
55

66
import (
77
"context"
8-
"errors"
98
"time"
10-
11-
"code.gitea.io/gitea/modules/log"
129
)
1310

1411
var _ context.Context = TemplateContext(nil)
@@ -36,14 +33,3 @@ func (c TemplateContext) Err() error {
3633
func (c TemplateContext) Value(key any) any {
3734
return c.parentContext().Value(key)
3835
}
39-
40-
// DataRaceCheck checks whether the template context function "ctx()" returns the consistent context
41-
// as the current template's rendering context (request context), to help to find data race issues as early as possible.
42-
// When the code is proven to be correct and stable, this function should be removed.
43-
func (c TemplateContext) DataRaceCheck(dataCtx context.Context) (string, error) {
44-
if c.parentContext() != dataCtx {
45-
log.Error("TemplateContext.DataRaceCheck: parent context mismatch\n%s", log.Stack(2))
46-
return "", errors.New("parent context mismatch")
47-
}
48-
return "", nil
49-
}

modules/git/batch_reader.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,7 @@ headerLoop:
203203
}
204204

205205
// Discard the rest of the tag
206-
discard := size - n + 1
207-
for discard > math.MaxInt32 {
208-
_, err := rd.Discard(math.MaxInt32)
209-
if err != nil {
210-
return id, err
211-
}
212-
discard -= math.MaxInt32
213-
}
214-
_, err := rd.Discard(int(discard))
215-
return id, err
206+
return id, DiscardFull(rd, size-n+1)
216207
}
217208

218209
// ReadTreeID reads a tree ID from a cat-file --batch stream, throwing away the rest of the stream.
@@ -238,16 +229,7 @@ headerLoop:
238229
}
239230

240231
// Discard the rest of the commit
241-
discard := size - n + 1
242-
for discard > math.MaxInt32 {
243-
_, err := rd.Discard(math.MaxInt32)
244-
if err != nil {
245-
return id, err
246-
}
247-
discard -= math.MaxInt32
248-
}
249-
_, err := rd.Discard(int(discard))
250-
return id, err
232+
return id, DiscardFull(rd, size-n+1)
251233
}
252234

253235
// git tree files are a list:
@@ -345,3 +327,21 @@ func init() {
345327
_, filename, _, _ := runtime.Caller(0)
346328
callerPrefix = strings.TrimSuffix(filename, "modules/git/batch_reader.go")
347329
}
330+
331+
func DiscardFull(rd *bufio.Reader, discard int64) error {
332+
if discard > math.MaxInt32 {
333+
n, err := rd.Discard(math.MaxInt32)
334+
discard -= int64(n)
335+
if err != nil {
336+
return err
337+
}
338+
}
339+
for discard > 0 {
340+
n, err := rd.Discard(int(discard))
341+
discard -= int64(n)
342+
if err != nil {
343+
return err
344+
}
345+
}
346+
return nil
347+
}

modules/git/blob_nogogit.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"bufio"
1010
"bytes"
1111
"io"
12-
"math"
1312

1413
"code.gitea.io/gitea/modules/log"
1514
)
@@ -104,25 +103,6 @@ func (b *blobReader) Read(p []byte) (n int, err error) {
104103
// Close implements io.Closer
105104
func (b *blobReader) Close() error {
106105
defer b.cancel()
107-
if b.n > 0 {
108-
for b.n > math.MaxInt32 {
109-
n, err := b.rd.Discard(math.MaxInt32)
110-
b.n -= int64(n)
111-
if err != nil {
112-
return err
113-
}
114-
b.n -= math.MaxInt32
115-
}
116-
n, err := b.rd.Discard(int(b.n))
117-
b.n -= int64(n)
118-
if err != nil {
119-
return err
120-
}
121-
}
122-
if b.n == 0 {
123-
_, err := b.rd.Discard(1)
124-
b.n--
125-
return err
126-
}
127-
return nil
106+
107+
return DiscardFull(b.rd, b.n+1)
128108
}

modules/git/commit_info_nogogit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ func GetLastCommitForPaths(ctx context.Context, commit *Commit, treePath string,
151151
return nil, err
152152
}
153153
if typ != "commit" {
154+
if err := DiscardFull(batchReader, size+1); err != nil {
155+
return nil, err
156+
}
154157
return nil, fmt.Errorf("unexpected type: %s for commit id: %s", typ, commitID)
155158
}
156159
c, err = CommitFromReader(commit.repo, MustIDFromString(commitID), io.LimitReader(batchReader, size))

modules/git/pipeline/lfs_nogogit.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
169169
} else {
170170
break commitReadingLoop
171171
}
172+
default:
173+
if err := git.DiscardFull(batchReader, size+1); err != nil {
174+
return nil, err
175+
}
172176
}
173177
}
174178
}

modules/git/repo_base_nogogit.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ type Repository struct {
2727

2828
gpgSettings *GPGSettings
2929

30+
batchInUse bool
3031
batchCancel context.CancelFunc
3132
batchReader *bufio.Reader
3233
batchWriter WriteCloserError
3334

35+
checkInUse bool
3436
checkCancel context.CancelFunc
3537
checkReader *bufio.Reader
3638
checkWriter WriteCloserError
@@ -79,23 +81,28 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
7981

8082
// CatFileBatch obtains a CatFileBatch for this repository
8183
func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bufio.Reader, func()) {
82-
if repo.batchCancel == nil || repo.batchReader.Buffered() > 0 {
84+
if repo.batchCancel == nil || repo.batchInUse {
8385
log.Debug("Opening temporary cat file batch for: %s", repo.Path)
8486
return CatFileBatch(ctx, repo.Path)
8587
}
86-
return repo.batchWriter, repo.batchReader, func() {}
88+
repo.batchInUse = true
89+
return repo.batchWriter, repo.batchReader, func() {
90+
repo.batchInUse = false
91+
}
8792
}
8893

8994
// CatFileBatchCheck obtains a CatFileBatchCheck for this repository
9095
func (repo *Repository) CatFileBatchCheck(ctx context.Context) (WriteCloserError, *bufio.Reader, func()) {
91-
if repo.checkCancel == nil || repo.checkReader.Buffered() > 0 {
92-
log.Debug("Opening temporary cat file batch-check: %s", repo.Path)
96+
if repo.checkCancel == nil || repo.checkInUse {
97+
log.Debug("Opening temporary cat file batch-check for: %s", repo.Path)
9398
return CatFileBatchCheck(ctx, repo.Path)
9499
}
95-
return repo.checkWriter, repo.checkReader, func() {}
100+
repo.checkInUse = true
101+
return repo.checkWriter, repo.checkReader, func() {
102+
repo.checkInUse = false
103+
}
96104
}
97105

98-
// Close this repository, in particular close the underlying gogitStorage if this is not nil
99106
func (repo *Repository) Close() (err error) {
100107
if repo == nil {
101108
return nil
@@ -105,12 +112,14 @@ func (repo *Repository) Close() (err error) {
105112
repo.batchReader = nil
106113
repo.batchWriter = nil
107114
repo.batchCancel = nil
115+
repo.batchInUse = false
108116
}
109117
if repo.checkCancel != nil {
110118
repo.checkCancel()
111119
repo.checkCancel = nil
112120
repo.checkReader = nil
113121
repo.checkWriter = nil
122+
repo.checkInUse = false
114123
}
115124
repo.LastCommitCache = nil
116125
repo.tagCache = nil

modules/git/repo_commit_nogogit.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id ObjectID)
121121
return commit, nil
122122
default:
123123
log.Debug("Unknown typ: %s", typ)
124-
_, err = rd.Discard(int(size) + 1)
125-
if err != nil {
124+
if err := DiscardFull(rd, size+1); err != nil {
126125
return nil, err
127126
}
128127
return nil, ErrNotExist{

modules/git/repo_language_stats_nogogit.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
package git
77

88
import (
9-
"bufio"
109
"bytes"
1110
"io"
12-
"math"
1311
"strings"
1412

1513
"code.gitea.io/gitea/modules/analyze"
@@ -168,8 +166,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
168166
return nil, err
169167
}
170168
content = contentBuf.Bytes()
171-
err = discardFull(batchReader, discard)
172-
if err != nil {
169+
if err := DiscardFull(batchReader, discard); err != nil {
173170
return nil, err
174171
}
175172
}
@@ -212,21 +209,3 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
212209

213210
return mergeLanguageStats(sizes), nil
214211
}
215-
216-
func discardFull(rd *bufio.Reader, discard int64) error {
217-
if discard > math.MaxInt32 {
218-
n, err := rd.Discard(math.MaxInt32)
219-
discard -= int64(n)
220-
if err != nil {
221-
return err
222-
}
223-
}
224-
for discard > 0 {
225-
n, err := rd.Discard(int(discard))
226-
discard -= int64(n)
227-
if err != nil {
228-
return err
229-
}
230-
}
231-
return nil
232-
}

modules/git/repo_tag_nogogit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ func (repo *Repository) getTag(tagID ObjectID, name string) (*Tag, error) {
103103
return nil, err
104104
}
105105
if typ != "tag" {
106+
if err := DiscardFull(rd, size+1); err != nil {
107+
return nil, err
108+
}
106109
return nil, ErrNotExist{ID: tagID.String()}
107110
}
108111

0 commit comments

Comments
 (0)