Skip to content

Commit e95db5a

Browse files
Merge branch 'main' into runners-rest-api
2 parents f581e49 + 65e2411 commit e95db5a

File tree

24 files changed

+309
-49
lines changed

24 files changed

+309
-49
lines changed

models/actions/runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type ActionRunner struct {
5757

5858
// Store labels defined in state file (default: .runner file) of `act_runner`
5959
AgentLabels []string `xorm:"TEXT"`
60+
// Store if this is a runner that only ever get one single job assigned
61+
Ephemeral bool `xorm:"ephemeral NOT NULL DEFAULT false"`
6062

6163
Created timeutil.TimeStamp `xorm:"created"`
6264
Updated timeutil.TimeStamp `xorm:"updated"`

models/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ func prepareMigrationTasks() []*migration {
375375
newMigration(312, "Add DeleteBranchAfterMerge to AutoMerge", v1_24.AddDeleteBranchAfterMergeForAutoMerge),
376376
newMigration(313, "Move PinOrder from issue table to a new table issue_pin", v1_24.MovePinOrderToTableIssuePin),
377377
newMigration(314, "Update OwnerID as zero for repository level action tables", v1_24.UpdateOwnerIDOfRepoLevelActionsTables),
378+
newMigration(315, "Add Ephemeral to ActionRunner", v1_24.AddEphemeralToActionRunner),
378379
}
379380
return preparedMigrations
380381
}

models/migrations/v1_24/v315.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_24 //nolint
5+
6+
import (
7+
"xorm.io/xorm"
8+
)
9+
10+
func AddEphemeralToActionRunner(x *xorm.Engine) error {
11+
type ActionRunner struct {
12+
Ephemeral bool `xorm:"ephemeral NOT NULL DEFAULT false"`
13+
}
14+
15+
return x.Sync(new(ActionRunner))
16+
}

modules/gitrepo/gitrepo.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package gitrepo
55

66
import (
77
"context"
8+
"fmt"
89
"io"
910
"path/filepath"
1011
"strings"
@@ -20,8 +21,12 @@ type Repository interface {
2021
GetOwnerName() string
2122
}
2223

24+
func absPath(owner, name string) string {
25+
return filepath.Join(setting.RepoRootPath, strings.ToLower(owner), strings.ToLower(name)+".git")
26+
}
27+
2328
func repoPath(repo Repository) string {
24-
return filepath.Join(setting.RepoRootPath, strings.ToLower(repo.GetOwnerName()), strings.ToLower(repo.GetName())+".git")
29+
return absPath(repo.GetOwnerName(), repo.GetName())
2530
}
2631

2732
func wikiPath(repo Repository) string {
@@ -74,3 +79,17 @@ func RepositoryFromRequestContextOrOpen(ctx reqctx.RequestContext, repo Reposito
7479
func IsRepositoryExist(ctx context.Context, repo Repository) (bool, error) {
7580
return util.IsExist(repoPath(repo))
7681
}
82+
83+
// DeleteRepository deletes the repository directory from the disk
84+
func DeleteRepository(ctx context.Context, repo Repository) error {
85+
return util.RemoveAll(repoPath(repo))
86+
}
87+
88+
// RenameRepository renames a repository's name on disk
89+
func RenameRepository(ctx context.Context, repo Repository, newName string) error {
90+
newRepoPath := absPath(repo.GetOwnerName(), newName)
91+
if err := util.Rename(repoPath(repo), newRepoPath); err != nil {
92+
return fmt.Errorf("rename repository directory: %w", err)
93+
}
94+
return nil
95+
}

modules/indexer/code/bleve/bleve.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"code.gitea.io/gitea/modules/setting"
2626
"code.gitea.io/gitea/modules/timeutil"
2727
"code.gitea.io/gitea/modules/typesniffer"
28+
"code.gitea.io/gitea/modules/util"
2829

2930
"github.com/blevesearch/bleve/v2"
3031
analyzer_custom "github.com/blevesearch/bleve/v2/analysis/analyzer/custom"
@@ -272,14 +273,18 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
272273
pathQuery.FieldVal = "Filename"
273274
pathQuery.SetBoost(10)
274275

275-
if opts.SearchMode == indexer.SearchModeExact {
276+
searchMode := util.IfZero(opts.SearchMode, b.SupportedSearchModes()[0].ModeValue)
277+
if searchMode == indexer.SearchModeExact {
278+
// 1.21 used NewPrefixQuery, but it seems not working well, and later releases changed to NewMatchPhraseQuery
276279
q := bleve.NewMatchPhraseQuery(opts.Keyword)
280+
q.Analyzer = repoIndexerAnalyzer
277281
q.FieldVal = "Content"
278282
contentQuery = q
279283
} else /* words */ {
280284
q := bleve.NewMatchQuery(opts.Keyword)
281285
q.FieldVal = "Content"
282-
if opts.SearchMode == indexer.SearchModeFuzzy {
286+
q.Analyzer = repoIndexerAnalyzer
287+
if searchMode == indexer.SearchModeFuzzy {
283288
// this logic doesn't seem right, it is only used to pass the test-case `Keyword: "dESCRIPTION"`, which doesn't seem to be a real-life use-case.
284289
q.Fuzziness = inner_bleve.GuessFuzzinessByKeyword(opts.Keyword)
285290
} else {

modules/indexer/code/elasticsearch/elasticsearch.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"code.gitea.io/gitea/modules/setting"
2626
"code.gitea.io/gitea/modules/timeutil"
2727
"code.gitea.io/gitea/modules/typesniffer"
28+
"code.gitea.io/gitea/modules/util"
2829

2930
"github.com/go-enry/go-enry/v2"
3031
"github.com/olivere/elastic/v7"
@@ -365,7 +366,9 @@ func extractAggs(searchResult *elastic.SearchResult) []*internal.SearchResultLan
365366
// Search searches for codes and language stats by given conditions.
366367
func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int64, []*internal.SearchResult, []*internal.SearchResultLanguages, error) {
367368
var contentQuery elastic.Query
368-
if opts.SearchMode == indexer.SearchModeExact {
369+
searchMode := util.IfZero(opts.SearchMode, b.SupportedSearchModes()[0].ModeValue)
370+
if searchMode == indexer.SearchModeExact {
371+
// 1.21 used NewMultiMatchQuery().Type(esMultiMatchTypePhrasePrefix), but later releases changed to NewMatchPhraseQuery
369372
contentQuery = elastic.NewMatchPhraseQuery("content", opts.Keyword)
370373
} else /* words */ {
371374
contentQuery = elastic.NewMultiMatchQuery("content", opts.Keyword).Type(esMultiMatchTypeBestFields).Operator("and")

modules/indexer/code/indexer_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"code.gitea.io/gitea/modules/indexer/code/internal"
1818
"code.gitea.io/gitea/modules/setting"
1919
"code.gitea.io/gitea/modules/test"
20+
"code.gitea.io/gitea/modules/util"
2021

2122
_ "code.gitea.io/gitea/models"
2223
_ "code.gitea.io/gitea/models/actions"
@@ -240,7 +241,7 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
240241
total, res, langs, err := indexer.Search(t.Context(), &internal.SearchOptions{
241242
RepoIDs: kw.RepoIDs,
242243
Keyword: kw.Keyword,
243-
SearchMode: kw.SearchMode,
244+
SearchMode: util.IfZero(kw.SearchMode, indexer_module.SearchModeWords),
244245
Paginator: &db.ListOptions{
245246
Page: 1,
246247
PageSize: 10,

modules/indexer/issues/bleve/bleve.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
1111
inner_bleve "code.gitea.io/gitea/modules/indexer/internal/bleve"
1212
"code.gitea.io/gitea/modules/indexer/issues/internal"
13+
"code.gitea.io/gitea/modules/util"
1314

1415
"github.com/blevesearch/bleve/v2"
1516
"github.com/blevesearch/bleve/v2/analysis/analyzer/custom"
@@ -162,9 +163,10 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
162163
var queries []query.Query
163164

164165
if options.Keyword != "" {
165-
if options.SearchMode == indexer.SearchModeWords || options.SearchMode == indexer.SearchModeFuzzy {
166+
searchMode := util.IfZero(options.SearchMode, b.SupportedSearchModes()[0].ModeValue)
167+
if searchMode == indexer.SearchModeWords || searchMode == indexer.SearchModeFuzzy {
166168
fuzziness := 0
167-
if options.SearchMode == indexer.SearchModeFuzzy {
169+
if searchMode == indexer.SearchModeFuzzy {
168170
fuzziness = inner_bleve.GuessFuzzinessByKeyword(options.Keyword)
169171
}
170172
queries = append(queries, bleve.NewDisjunctionQuery([]query.Query{

modules/indexer/issues/db/db.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
1414
inner_db "code.gitea.io/gitea/modules/indexer/internal/db"
1515
"code.gitea.io/gitea/modules/indexer/issues/internal"
16+
"code.gitea.io/gitea/modules/util"
1617

1718
"xorm.io/builder"
1819
)
@@ -46,7 +47,7 @@ func (i *Indexer) Delete(_ context.Context, _ ...int64) error {
4647

4748
func buildMatchQuery(mode indexer.SearchModeType, colName, keyword string) builder.Cond {
4849
if mode == indexer.SearchModeExact {
49-
return db.BuildCaseInsensitiveLike("issue.name", keyword)
50+
return db.BuildCaseInsensitiveLike(colName, keyword)
5051
}
5152

5253
// match words
@@ -84,16 +85,16 @@ func (i *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
8485
repoCond = builder.Eq{"repo_id": options.RepoIDs[0]}
8586
}
8687
subQuery := builder.Select("id").From("issue").Where(repoCond)
87-
88+
searchMode := util.IfZero(options.SearchMode, i.SupportedSearchModes()[0].ModeValue)
8889
cond = builder.Or(
89-
buildMatchQuery(options.SearchMode, "issue.name", options.Keyword),
90-
buildMatchQuery(options.SearchMode, "issue.content", options.Keyword),
90+
buildMatchQuery(searchMode, "issue.name", options.Keyword),
91+
buildMatchQuery(searchMode, "issue.content", options.Keyword),
9192
builder.In("issue.id", builder.Select("issue_id").
9293
From("comment").
9394
Where(builder.And(
9495
builder.Eq{"type": issue_model.CommentTypeComment},
9596
builder.In("issue_id", subQuery),
96-
buildMatchQuery(options.SearchMode, "content", options.Keyword),
97+
buildMatchQuery(searchMode, "content", options.Keyword),
9798
)),
9899
),
99100
)

modules/indexer/issues/elasticsearch/elasticsearch.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
1515
inner_elasticsearch "code.gitea.io/gitea/modules/indexer/internal/elasticsearch"
1616
"code.gitea.io/gitea/modules/indexer/issues/internal"
17+
"code.gitea.io/gitea/modules/util"
1718

1819
"github.com/olivere/elastic/v7"
1920
)
@@ -152,7 +153,8 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
152153
query := elastic.NewBoolQuery()
153154

154155
if options.Keyword != "" {
155-
if options.SearchMode == indexer.SearchModeExact {
156+
searchMode := util.IfZero(options.SearchMode, b.SupportedSearchModes()[0].ModeValue)
157+
if searchMode == indexer.SearchModeExact {
156158
query.Must(elastic.NewMultiMatchQuery(options.Keyword, "title", "content", "comments").Type(esMultiMatchTypePhrasePrefix))
157159
} else /* words */ {
158160
query.Must(elastic.NewMultiMatchQuery(options.Keyword, "title", "content", "comments").Type(esMultiMatchTypeBestFields).Operator("and"))

0 commit comments

Comments
 (0)