Skip to content

Commit 49462d6

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: (28 commits) Forbid jQuery `.prop` and fix related issues (go-gitea#29832) Fix wrong test for TestPullView_CodeOwner (go-gitea#29838) Forbid HTML injection using jQuery (go-gitea#29843) Meilisearch double quote on "match" query (go-gitea#29740) Forbid variables containing jQuery collections not having the `$` prefix (go-gitea#29839) Remove AddParamIfExist(AddParam) (go-gitea#29841) Refactor markdown attention render (go-gitea#29833) Refactor code_indexer to use an SearchOptions struct for PerformSearch (go-gitea#29724) Refactor AddParam to AddParamIfExist (go-gitea#29834) Forbid jQuery AJAX (go-gitea#29818) Remove jQuery AJAX from the notifications (go-gitea#29817) Light theme color enhancements (go-gitea#29830) Better highlighting of archved labels (go-gitea#29749) Remove the `time-since` class (go-gitea#29826) Remove jQuery AJAX from the project page (go-gitea#29814) Upgrade `htmx` to v1.9.11 (go-gitea#29821) Dark theme color enhancements (go-gitea#29822) Remove jQuery AJAX from the comment edit box (go-gitea#29812) Tweak labeler (go-gitea#29809) Fix `for` attribute not pointing to the ID of the color picker (go-gitea#29813) ... # Conflicts: # routers/web/user/home.go
2 parents 9859580 + 21fe512 commit 49462d6

File tree

128 files changed

+1607
-1228
lines changed

Some content is hidden

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

128 files changed

+1607
-1228
lines changed

.eslintrc.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ rules:
283283
i/unambiguous: [0]
284284
init-declarations: [0]
285285
jquery/no-ajax-events: [2]
286-
jquery/no-ajax: [0]
286+
jquery/no-ajax: [2]
287287
jquery/no-animate: [2]
288288
jquery/no-attr: [0]
289289
jquery/no-bind: [2]
@@ -315,7 +315,7 @@ rules:
315315
jquery/no-parent: [0]
316316
jquery/no-parents: [0]
317317
jquery/no-parse-html: [2]
318-
jquery/no-prop: [0]
318+
jquery/no-prop: [2]
319319
jquery/no-proxy: [2]
320320
jquery/no-ready: [2]
321321
jquery/no-serialize: [2]
@@ -396,11 +396,11 @@ rules:
396396
no-irregular-whitespace: [2]
397397
no-iterator: [2]
398398
no-jquery/no-ajax-events: [2]
399-
no-jquery/no-ajax: [0]
399+
no-jquery/no-ajax: [2]
400400
no-jquery/no-and-self: [2]
401401
no-jquery/no-animate-toggle: [2]
402402
no-jquery/no-animate: [2]
403-
no-jquery/no-append-html: [0]
403+
no-jquery/no-append-html: [2]
404404
no-jquery/no-attr: [0]
405405
no-jquery/no-bind: [2]
406406
no-jquery/no-box-model: [2]
@@ -466,7 +466,7 @@ rules:
466466
no-jquery/no-parse-html: [2]
467467
no-jquery/no-parse-json: [2]
468468
no-jquery/no-parse-xml: [2]
469-
no-jquery/no-prop: [0]
469+
no-jquery/no-prop: [2]
470470
no-jquery/no-proxy: [2]
471471
no-jquery/no-ready-shorthand: [2]
472472
no-jquery/no-ready: [2]
@@ -487,7 +487,7 @@ rules:
487487
no-jquery/no-visibility: [2]
488488
no-jquery/no-when: [2]
489489
no-jquery/no-wrap: [2]
490-
no-jquery/variable-pattern: [0]
490+
no-jquery/variable-pattern: [2]
491491
no-label-var: [2]
492492
no-labels: [0] # handled by no-restricted-syntax
493493
no-lone-blocks: [2]

.github/labeler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ modifies/dependencies:
6767
- any-glob-to-any-file:
6868
- "package.json"
6969
- "package-lock.json"
70-
- "poetry.toml"
70+
- "pyproject.toml"
7171
- "poetry.lock"
7272
- "go.mod"
7373
- "go.sum"
74-
- "pyproject.toml"
7574

7675
modifies/go:
7776
- changed-files:
@@ -82,3 +81,4 @@ modifies/js:
8281
- changed-files:
8382
- any-glob-to-any-file:
8483
- "**/*.js"
84+
- "**/*.vue"

models/issues/pull.go

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
repo_model "code.gitea.io/gitea/models/repo"
2020
user_model "code.gitea.io/gitea/models/user"
2121
"code.gitea.io/gitea/modules/git"
22-
"code.gitea.io/gitea/modules/gitrepo"
2322
"code.gitea.io/gitea/modules/log"
2423
"code.gitea.io/gitea/modules/setting"
2524
"code.gitea.io/gitea/modules/timeutil"
@@ -884,77 +883,6 @@ func MergeBlockedByOutdatedBranch(protectBranch *git_model.ProtectedBranch, pr *
884883
return protectBranch.BlockOnOutdatedBranch && pr.CommitsBehind > 0
885884
}
886885

887-
func PullRequestCodeOwnersReview(ctx context.Context, pull *Issue, pr *PullRequest) error {
888-
files := []string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"}
889-
890-
if pr.IsWorkInProgress(ctx) {
891-
return nil
892-
}
893-
894-
if err := pr.LoadBaseRepo(ctx); err != nil {
895-
return err
896-
}
897-
898-
repo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
899-
if err != nil {
900-
return err
901-
}
902-
defer repo.Close()
903-
904-
commit, err := repo.GetBranchCommit(pr.BaseRepo.DefaultBranch)
905-
if err != nil {
906-
return err
907-
}
908-
909-
var data string
910-
for _, file := range files {
911-
if blob, err := commit.GetBlobByPath(file); err == nil {
912-
data, err = blob.GetBlobContent(setting.UI.MaxDisplayFileSize)
913-
if err == nil {
914-
break
915-
}
916-
}
917-
}
918-
919-
rules, _ := GetCodeOwnersFromContent(ctx, data)
920-
changedFiles, err := repo.GetFilesChangedBetween(git.BranchPrefix+pr.BaseBranch, pr.GetGitRefName())
921-
if err != nil {
922-
return err
923-
}
924-
925-
uniqUsers := make(map[int64]*user_model.User)
926-
uniqTeams := make(map[string]*org_model.Team)
927-
for _, rule := range rules {
928-
for _, f := range changedFiles {
929-
if (rule.Rule.MatchString(f) && !rule.Negative) || (!rule.Rule.MatchString(f) && rule.Negative) {
930-
for _, u := range rule.Users {
931-
uniqUsers[u.ID] = u
932-
}
933-
for _, t := range rule.Teams {
934-
uniqTeams[fmt.Sprintf("%d/%d", t.OrgID, t.ID)] = t
935-
}
936-
}
937-
}
938-
}
939-
940-
for _, u := range uniqUsers {
941-
if u.ID != pull.Poster.ID {
942-
if _, err := AddReviewRequest(ctx, pull, u, pull.Poster); err != nil {
943-
log.Warn("Failed add assignee user: %s to PR review: %s#%d, error: %s", u.Name, pr.BaseRepo.Name, pr.ID, err)
944-
return err
945-
}
946-
}
947-
}
948-
for _, t := range uniqTeams {
949-
if _, err := AddTeamReviewRequest(ctx, pull, t, pull.Poster); err != nil {
950-
log.Warn("Failed add assignee team: %s to PR review: %s#%d, error: %s", t.Name, pr.BaseRepo.Name, pr.ID, err)
951-
return err
952-
}
953-
}
954-
955-
return nil
956-
}
957-
958886
// GetCodeOwnersFromContent returns the code owners configuration
959887
// Return empty slice if files missing
960888
// Return warning messages on parsing errors

modules/graceful/manager.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ func (g *Manager) setStateTransition(old, new state) bool {
233233
// At the moment the total number of servers (numberOfServersToCreate) are pre-defined as a const before global init,
234234
// so this function MUST be called if a server is not used.
235235
func (g *Manager) InformCleanup() {
236-
g.createServerWaitGroup.Done()
236+
g.createServerCond.L.Lock()
237+
defer g.createServerCond.L.Unlock()
238+
g.createdServer++
239+
g.createServerCond.Signal()
237240
}
238241

239242
// Done allows the manager to be viewed as a context.Context, it returns a channel that is closed when the server is finished terminating

modules/graceful/manager_common.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ type Manager struct {
4242
terminateCtxCancel context.CancelFunc
4343
managerCtxCancel context.CancelFunc
4444
runningServerWaitGroup sync.WaitGroup
45-
createServerWaitGroup sync.WaitGroup
4645
terminateWaitGroup sync.WaitGroup
46+
createServerCond sync.Cond
47+
createdServer int
4748
shutdownRequested chan struct{}
4849

4950
toRunAtShutdown []func()
@@ -52,7 +53,7 @@ type Manager struct {
5253

5354
func newGracefulManager(ctx context.Context) *Manager {
5455
manager := &Manager{ctx: ctx, shutdownRequested: make(chan struct{})}
55-
manager.createServerWaitGroup.Add(numberOfServersToCreate)
56+
manager.createServerCond.L = &sync.Mutex{}
5657
manager.prepare(ctx)
5758
manager.start()
5859
return manager

modules/graceful/manager_unix.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,35 @@ func (g *Manager) start() {
5757
// Handle clean up of unused provided listeners and delayed start-up
5858
startupDone := make(chan struct{})
5959
go func() {
60-
defer close(startupDone)
61-
// Wait till we're done getting all the listeners and then close the unused ones
62-
func() {
63-
// FIXME: there is a fundamental design problem of the "manager" and the "wait group".
64-
// If nothing has started, the "Wait" just panics: sync: WaitGroup is reused before previous Wait has returned
65-
// There is no clear solution besides a complete rewriting of the "manager"
66-
defer func() {
67-
_ = recover()
68-
}()
69-
g.createServerWaitGroup.Wait()
60+
defer func() {
61+
close(startupDone)
62+
// Close the unused listeners and ignore the error here there's not much we can do with it, they're logged in the CloseProvidedListeners function
63+
_ = CloseProvidedListeners()
7064
}()
71-
// Ignore the error here there's not much we can do with it, they're logged in the CloseProvidedListeners function
72-
_ = CloseProvidedListeners()
73-
g.notify(readyMsg)
65+
// Wait for all servers to be created
66+
g.createServerCond.L.Lock()
67+
for {
68+
if g.createdServer >= numberOfServersToCreate {
69+
g.createServerCond.L.Unlock()
70+
g.notify(readyMsg)
71+
return
72+
}
73+
select {
74+
case <-g.IsShutdown():
75+
g.createServerCond.L.Unlock()
76+
return
77+
default:
78+
}
79+
g.createServerCond.Wait()
80+
}
7481
}()
7582
if setting.StartupTimeout > 0 {
7683
go func() {
7784
select {
7885
case <-startupDone:
7986
return
8087
case <-g.IsShutdown():
81-
func() {
82-
// When WaitGroup counter goes negative it will panic - we don't care about this so we can just ignore it.
83-
defer func() {
84-
_ = recover()
85-
}()
86-
// Ensure that the createServerWaitGroup stops waiting
87-
for {
88-
g.createServerWaitGroup.Done()
89-
}
90-
}()
88+
g.createServerCond.Signal()
9189
return
9290
case <-time.After(setting.StartupTimeout):
9391
log.Error("Startup took too long! Shutting down")

modules/graceful/manager_windows.go

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,33 +149,35 @@ hammerLoop:
149149
func (g *Manager) awaitServer(limit time.Duration) bool {
150150
c := make(chan struct{})
151151
go func() {
152-
defer close(c)
153-
func() {
154-
// FIXME: there is a fundamental design problem of the "manager" and the "wait group".
155-
// If nothing has started, the "Wait" just panics: sync: WaitGroup is reused before previous Wait has returned
156-
// There is no clear solution besides a complete rewriting of the "manager"
157-
defer func() {
158-
_ = recover()
159-
}()
160-
g.createServerWaitGroup.Wait()
161-
}()
152+
g.createServerCond.L.Lock()
153+
for {
154+
if g.createdServer >= numberOfServersToCreate {
155+
g.createServerCond.L.Unlock()
156+
close(c)
157+
return
158+
}
159+
select {
160+
case <-g.IsShutdown():
161+
g.createServerCond.L.Unlock()
162+
return
163+
default:
164+
}
165+
g.createServerCond.Wait()
166+
}
162167
}()
168+
169+
var tc <-chan time.Time
163170
if limit > 0 {
164-
select {
165-
case <-c:
166-
return true // completed normally
167-
case <-time.After(limit):
168-
return false // timed out
169-
case <-g.IsShutdown():
170-
return false
171-
}
172-
} else {
173-
select {
174-
case <-c:
175-
return true // completed normally
176-
case <-g.IsShutdown():
177-
return false
178-
}
171+
tc = time.After(limit)
172+
}
173+
select {
174+
case <-c:
175+
return true // completed normally
176+
case <-tc:
177+
return false // timed out
178+
case <-g.IsShutdown():
179+
g.createServerCond.Signal()
180+
return false
179181
}
180182
}
181183

modules/indexer/code/bleve/bleve.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro
142142
return err
143143
}
144144
if size, err = strconv.ParseInt(strings.TrimSpace(stdout), 10, 64); err != nil {
145-
return fmt.Errorf("Misformatted git cat-file output: %w", err)
145+
return fmt.Errorf("misformatted git cat-file output: %w", err)
146146
}
147147
}
148148

@@ -233,26 +233,26 @@ func (b *Indexer) Delete(_ context.Context, repoID int64) error {
233233

234234
// Search searches for files in the specified repo.
235235
// Returns the matching file-paths
236-
func (b *Indexer) Search(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isFuzzy bool) (int64, []*internal.SearchResult, []*internal.SearchResultLanguages, error) {
236+
func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int64, []*internal.SearchResult, []*internal.SearchResultLanguages, error) {
237237
var (
238238
indexerQuery query.Query
239239
keywordQuery query.Query
240240
)
241241

242-
if isFuzzy {
243-
phraseQuery := bleve.NewMatchPhraseQuery(keyword)
242+
if opts.IsKeywordFuzzy {
243+
phraseQuery := bleve.NewMatchPhraseQuery(opts.Keyword)
244244
phraseQuery.FieldVal = "Content"
245245
phraseQuery.Analyzer = repoIndexerAnalyzer
246246
keywordQuery = phraseQuery
247247
} else {
248-
prefixQuery := bleve.NewPrefixQuery(keyword)
248+
prefixQuery := bleve.NewPrefixQuery(opts.Keyword)
249249
prefixQuery.FieldVal = "Content"
250250
keywordQuery = prefixQuery
251251
}
252252

253-
if len(repoIDs) > 0 {
254-
repoQueries := make([]query.Query, 0, len(repoIDs))
255-
for _, repoID := range repoIDs {
253+
if len(opts.RepoIDs) > 0 {
254+
repoQueries := make([]query.Query, 0, len(opts.RepoIDs))
255+
for _, repoID := range opts.RepoIDs {
256256
repoQueries = append(repoQueries, inner_bleve.NumericEqualityQuery(repoID, "RepoID"))
257257
}
258258

@@ -266,8 +266,8 @@ func (b *Indexer) Search(ctx context.Context, repoIDs []int64, language, keyword
266266

267267
// Save for reuse without language filter
268268
facetQuery := indexerQuery
269-
if len(language) > 0 {
270-
languageQuery := bleve.NewMatchQuery(language)
269+
if len(opts.Language) > 0 {
270+
languageQuery := bleve.NewMatchQuery(opts.Language)
271271
languageQuery.FieldVal = "Language"
272272
languageQuery.Analyzer = analyzer_keyword.Name
273273

@@ -277,12 +277,12 @@ func (b *Indexer) Search(ctx context.Context, repoIDs []int64, language, keyword
277277
)
278278
}
279279

280-
from := (page - 1) * pageSize
280+
from, pageSize := opts.GetSkipTake()
281281
searchRequest := bleve.NewSearchRequestOptions(indexerQuery, pageSize, from, false)
282282
searchRequest.Fields = []string{"Content", "RepoID", "Language", "CommitID", "UpdatedAt"}
283283
searchRequest.IncludeLocations = true
284284

285-
if len(language) == 0 {
285+
if len(opts.Language) == 0 {
286286
searchRequest.AddFacet("languages", bleve.NewFacetRequest("Language", 10))
287287
}
288288

@@ -326,7 +326,7 @@ func (b *Indexer) Search(ctx context.Context, repoIDs []int64, language, keyword
326326
}
327327

328328
searchResultLanguages := make([]*internal.SearchResultLanguages, 0, 10)
329-
if len(language) > 0 {
329+
if len(opts.Language) > 0 {
330330
// Use separate query to go get all language counts
331331
facetRequest := bleve.NewSearchRequestOptions(facetQuery, 1, 0, false)
332332
facetRequest.Fields = []string{"Content", "RepoID", "Language", "CommitID", "UpdatedAt"}

0 commit comments

Comments
 (0)