Skip to content

Commit 1f845db

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin Upgrade golang net from 0.35.0 -> 0.36.0 (go-gitea#33795) Remove context from git struct (go-gitea#33793) Small refactor to reduce unnecessary database queries and remove duplicated functions (go-gitea#33779) Refactor repo-issue.ts (go-gitea#33784) Refactor repo-settings.ts (go-gitea#33785) Refactor admin/common.ts (go-gitea#33788)
2 parents 7657e9d + b9913d9 commit 1f845db

File tree

134 files changed

+864
-883
lines changed

Some content is hidden

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

134 files changed

+864
-883
lines changed

.github/workflows/pull-db-tests.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,10 @@ jobs:
202202
test-mssql:
203203
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true'
204204
needs: files-changed
205-
# specifying the version of ubuntu in use as mssql fails on newer kernels
206-
# pending resolution from vendor
207-
runs-on: ubuntu-20.04
205+
runs-on: ubuntu-latest
208206
services:
209207
mssql:
210-
image: mcr.microsoft.com/mssql/server:2017-latest
208+
image: mcr.microsoft.com/mssql/server:2019-latest
211209
env:
212210
ACCEPT_EULA: Y
213211
MSSQL_PID: Standard

cmd/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func runHookPostReceive(c *cli.Context) error {
316316
setup(ctx, c.Bool("debug"))
317317

318318
// First of all run update-server-info no matter what
319-
if _, _, err := git.NewCommand(ctx, "update-server-info").RunStdString(nil); err != nil {
319+
if _, _, err := git.NewCommand("update-server-info").RunStdString(ctx, nil); err != nil {
320320
return fmt.Errorf("Failed to call 'git update-server-info': %w", err)
321321
}
322322

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ require (
119119
gitlab.com/gitlab-org/api/client-go v0.123.0
120120
golang.org/x/crypto v0.35.0
121121
golang.org/x/image v0.24.0
122-
golang.org/x/net v0.35.0
122+
golang.org/x/net v0.36.0
123123
golang.org/x/oauth2 v0.27.0
124124
golang.org/x/sync v0.11.0
125125
golang.org/x/sys v0.30.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,8 @@ golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
867867
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
868868
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
869869
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
870-
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
871-
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
870+
golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA=
871+
golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I=
872872
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
873873
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
874874
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

models/actions/schedule.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@ func init() {
4343
// GetSchedulesMapByIDs returns the schedules by given id slice.
4444
func GetSchedulesMapByIDs(ctx context.Context, ids []int64) (map[int64]*ActionSchedule, error) {
4545
schedules := make(map[int64]*ActionSchedule, len(ids))
46+
if len(ids) == 0 {
47+
return schedules, nil
48+
}
4649
return schedules, db.GetEngine(ctx).In("id", ids).Find(&schedules)
4750
}
4851

49-
// GetReposMapByIDs returns the repos by given id slice.
50-
func GetReposMapByIDs(ctx context.Context, ids []int64) (map[int64]*repo_model.Repository, error) {
51-
repos := make(map[int64]*repo_model.Repository, len(ids))
52-
return repos, db.GetEngine(ctx).In("id", ids).Find(&repos)
53-
}
54-
5552
// CreateScheduleTask creates new schedule task.
5653
func CreateScheduleTask(ctx context.Context, rows []*ActionSchedule) error {
5754
// Return early if there are no rows to insert

models/actions/schedule_spec_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (specs SpecList) LoadSchedules(ctx context.Context) error {
3232
}
3333

3434
repoIDs := specs.GetRepoIDs()
35-
repos, err := GetReposMapByIDs(ctx, repoIDs)
35+
repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs)
3636
if err != nil {
3737
return err
3838
}

models/db/context.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ func FindIDs(ctx context.Context, tableName, idCol string, cond builder.Cond) ([
289289
// DecrByIDs decreases the given column for entities of the "bean" type with one of the given ids by one
290290
// Timestamps of the entities won't be updated
291291
func DecrByIDs(ctx context.Context, ids []int64, decrCol string, bean any) error {
292+
if len(ids) == 0 {
293+
return nil
294+
}
292295
_, err := GetEngine(ctx).Decr(decrCol).In("id", ids).NoAutoCondition().NoAutoTime().Update(bean)
293296
return err
294297
}

models/issues/issue.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ func GetIssueByID(ctx context.Context, id int64) (*Issue, error) {
595595
// If keepOrder is true, the order of the returned issues will be the same as the given IDs.
596596
func GetIssuesByIDs(ctx context.Context, issueIDs []int64, keepOrder ...bool) (IssueList, error) {
597597
issues := make([]*Issue, 0, len(issueIDs))
598+
if len(issueIDs) == 0 {
599+
return issues, nil
600+
}
598601

599602
if err := db.GetEngine(ctx).In("id", issueIDs).Find(&issues); err != nil {
600603
return nil, err

models/issues/label.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ func GetLabelByID(ctx context.Context, labelID int64) (*Label, error) {
299299
// GetLabelsByIDs returns a list of labels by IDs
300300
func GetLabelsByIDs(ctx context.Context, labelIDs []int64, cols ...string) ([]*Label, error) {
301301
labels := make([]*Label, 0, len(labelIDs))
302+
if len(labelIDs) == 0 {
303+
return labels, nil
304+
}
302305
return labels, db.GetEngine(ctx).Table("label").
303306
In("id", labelIDs).
304307
Asc("name").
@@ -375,6 +378,9 @@ func BuildLabelNamesIssueIDsCondition(labelNames []string) *builder.Builder {
375378
// it silently ignores label IDs that do not belong to the repository.
376379
func GetLabelsInRepoByIDs(ctx context.Context, repoID int64, labelIDs []int64) ([]*Label, error) {
377380
labels := make([]*Label, 0, len(labelIDs))
381+
if len(labelIDs) == 0 {
382+
return labels, nil
383+
}
378384
return labels, db.GetEngine(ctx).
379385
Where("repo_id = ?", repoID).
380386
In("id", labelIDs).
@@ -447,6 +453,9 @@ func GetLabelInOrgByID(ctx context.Context, orgID, labelID int64) (*Label, error
447453
// it silently ignores label IDs that do not belong to the organization.
448454
func GetLabelsInOrgByIDs(ctx context.Context, orgID int64, labelIDs []int64) ([]*Label, error) {
449455
labels := make([]*Label, 0, len(labelIDs))
456+
if len(labelIDs) == 0 {
457+
return labels, nil
458+
}
450459
return labels, db.GetEngine(ctx).
451460
Where("org_id = ?", orgID).
452461
In("id", labelIDs).

models/migrations/v1_12/v128.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ func FixMergeBase(x *xorm.Engine) error {
8282

8383
if !pr.HasMerged {
8484
var err error
85-
pr.MergeBase, _, err = git.NewCommand(git.DefaultContext, "merge-base").AddDashesAndList(pr.BaseBranch, gitRefName).RunStdString(&git.RunOpts{Dir: repoPath})
85+
pr.MergeBase, _, err = git.NewCommand("merge-base").AddDashesAndList(pr.BaseBranch, gitRefName).RunStdString(git.DefaultContext, &git.RunOpts{Dir: repoPath})
8686
if err != nil {
8787
var err2 error
88-
pr.MergeBase, _, err2 = git.NewCommand(git.DefaultContext, "rev-parse").AddDynamicArguments(git.BranchPrefix + pr.BaseBranch).RunStdString(&git.RunOpts{Dir: repoPath})
88+
pr.MergeBase, _, err2 = git.NewCommand("rev-parse").AddDynamicArguments(git.BranchPrefix+pr.BaseBranch).RunStdString(git.DefaultContext, &git.RunOpts{Dir: repoPath})
8989
if err2 != nil {
9090
log.Error("Unable to get merge base for PR ID %d, Index %d in %s/%s. Error: %v & %v", pr.ID, pr.Index, baseRepo.OwnerName, baseRepo.Name, err, err2)
9191
continue
9292
}
9393
}
9494
} else {
95-
parentsString, _, err := git.NewCommand(git.DefaultContext, "rev-list", "--parents", "-n", "1").AddDynamicArguments(pr.MergedCommitID).RunStdString(&git.RunOpts{Dir: repoPath})
95+
parentsString, _, err := git.NewCommand("rev-list", "--parents", "-n", "1").AddDynamicArguments(pr.MergedCommitID).RunStdString(git.DefaultContext, &git.RunOpts{Dir: repoPath})
9696
if err != nil {
9797
log.Error("Unable to get parents for merged PR ID %d, Index %d in %s/%s. Error: %v", pr.ID, pr.Index, baseRepo.OwnerName, baseRepo.Name, err)
9898
continue
@@ -104,9 +104,9 @@ func FixMergeBase(x *xorm.Engine) error {
104104

105105
refs := append([]string{}, parents[1:]...)
106106
refs = append(refs, gitRefName)
107-
cmd := git.NewCommand(git.DefaultContext, "merge-base").AddDashesAndList(refs...)
107+
cmd := git.NewCommand("merge-base").AddDashesAndList(refs...)
108108

109-
pr.MergeBase, _, err = cmd.RunStdString(&git.RunOpts{Dir: repoPath})
109+
pr.MergeBase, _, err = cmd.RunStdString(git.DefaultContext, &git.RunOpts{Dir: repoPath})
110110
if err != nil {
111111
log.Error("Unable to get merge base for merged PR ID %d, Index %d in %s/%s. Error: %v", pr.ID, pr.Index, baseRepo.OwnerName, baseRepo.Name, err)
112112
continue

0 commit comments

Comments
 (0)