Skip to content

Commit cdfdbd0

Browse files
authored
Merge branch 'main' into strictNullChecks2
2 parents 07e9577 + a0f492d commit cdfdbd0

File tree

36 files changed

+524
-142
lines changed

36 files changed

+524
-142
lines changed

.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ linters:
1414
- govet
1515
- ineffassign
1616
- mirror
17+
- modernize
1718
- nakedret
1819
- nolintlint
1920
- perfsprint
@@ -55,6 +56,7 @@ linters:
5556
disabled-checks:
5657
- ifElseChain
5758
- singleCaseSwitch # Every time this occurred in the code, there was no other way.
59+
- deprecatedComment # conflicts with go-swagger comments
5860
revive:
5961
severity: error
6062
rules:
@@ -107,6 +109,11 @@ linters:
107109
- require-error
108110
usetesting:
109111
os-temp-dir: true
112+
modernize:
113+
disable:
114+
- stringsbuilder
115+
perfsprint:
116+
concat-loop: false
110117
exclusions:
111118
generated: lax
112119
presets:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ XGO_VERSION := go-1.25.x
3232
AIR_PACKAGE ?= github.com/air-verse/air@v1
3333
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3
3434
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.9.2
35-
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0
35+
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.0
3636
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.15
3737
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.7.0
3838
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.33.1

flake.lock

Lines changed: 0 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 80 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,94 @@
11
{
22
inputs = {
33
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
4-
flake-utils.url = "github:numtide/flake-utils";
54
};
65
outputs =
7-
{ nixpkgs, flake-utils, ... }:
8-
flake-utils.lib.eachDefaultSystem (
9-
system:
10-
let
11-
pkgs = nixpkgs.legacyPackages.${system};
12-
in
13-
{
14-
devShells.default =
15-
with pkgs;
16-
let
17-
# only bump toolchain versions here
18-
go = go_1_25;
19-
nodejs = nodejs_24;
20-
python3 = python312;
21-
pnpm = pnpm_10;
22-
23-
# Platform-specific dependencies
24-
linuxOnlyInputs = lib.optionals pkgs.stdenv.isLinux [
25-
glibc.static
26-
];
6+
{ nixpkgs, ... }:
7+
let
8+
supportedSystems = [
9+
"aarch64-darwin"
10+
"aarch64-linux"
11+
"x86_64-darwin"
12+
"x86_64-linux"
13+
];
2714

28-
linuxOnlyEnv = lib.optionalAttrs pkgs.stdenv.isLinux {
29-
CFLAGS = "-I${glibc.static.dev}/include";
30-
LDFLAGS = "-L ${glibc.static}/lib";
15+
forEachSupportedSystem =
16+
f:
17+
nixpkgs.lib.genAttrs supportedSystems (
18+
system:
19+
let
20+
pkgs = import nixpkgs {
21+
inherit system;
3122
};
3223
in
33-
pkgs.mkShell (
34-
{
35-
buildInputs = [
36-
# generic
37-
git
38-
git-lfs
39-
gnumake
40-
gnused
41-
gnutar
42-
gzip
43-
zip
24+
f { inherit pkgs; }
25+
);
26+
in
27+
{
28+
devShells = forEachSupportedSystem (
29+
{ pkgs, ... }:
30+
{
31+
default =
32+
let
33+
inherit (pkgs) lib;
34+
35+
# only bump toolchain versions here
36+
go = pkgs.go_1_25;
37+
nodejs = pkgs.nodejs_24;
38+
python3 = pkgs.python312;
39+
pnpm = pkgs.pnpm_10;
4440

45-
# frontend
46-
nodejs
47-
pnpm
48-
cairo
49-
pixman
50-
pkg-config
41+
# Platform-specific dependencies
42+
linuxOnlyInputs = lib.optionals pkgs.stdenv.isLinux [
43+
pkgs.glibc.static
44+
];
5145

52-
# linting
53-
python3
54-
uv
46+
linuxOnlyEnv = lib.optionalAttrs pkgs.stdenv.isLinux {
47+
CFLAGS = "-I${pkgs.glibc.static.dev}/include";
48+
LDFLAGS = "-L ${pkgs.glibc.static}/lib";
49+
};
50+
in
51+
pkgs.mkShell {
52+
packages =
53+
with pkgs;
54+
[
55+
# generic
56+
git
57+
git-lfs
58+
gnumake
59+
gnused
60+
gnutar
61+
gzip
62+
zip
5563

56-
# backend
57-
go
58-
gofumpt
59-
sqlite
60-
]
61-
++ linuxOnlyInputs;
64+
# frontend
65+
nodejs
66+
pnpm
67+
cairo
68+
pixman
69+
pkg-config
6270

63-
GO = "${go}/bin/go";
64-
GOROOT = "${go}/share/go";
71+
# linting
72+
python3
73+
uv
6574

66-
TAGS = "sqlite sqlite_unlock_notify";
67-
STATIC = "true";
68-
}
69-
// linuxOnlyEnv
70-
);
71-
}
72-
);
75+
# backend
76+
go
77+
gofumpt
78+
sqlite
79+
]
80+
++ linuxOnlyInputs;
81+
82+
env = {
83+
GO = "${go}/bin/go";
84+
GOROOT = "${go}/share/go";
85+
86+
TAGS = "sqlite sqlite_unlock_notify";
87+
STATIC = "true";
88+
}
89+
// linuxOnlyEnv;
90+
};
91+
}
92+
);
93+
};
7394
}

models/actions/main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ func TestMain(m *testing.M) {
1313
unittest.MainTest(m, &unittest.TestOptions{
1414
FixtureFiles: []string{
1515
"action_runner_token.yml",
16+
"action_run.yml",
17+
"repository.yml",
1618
},
1719
})
1820
}

models/actions/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,11 @@ func (run *ActionRun) IsSchedule() bool {
193193
return run.ScheduleID > 0
194194
}
195195

196+
// UpdateRepoRunsNumbers updates the number of runs and closed runs of a repository.
196197
func UpdateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) error {
197198
_, err := db.GetEngine(ctx).ID(repo.ID).
198199
NoAutoTime().
200+
Cols("num_action_runs", "num_closed_action_runs").
199201
SetExpr("num_action_runs",
200202
builder.Select("count(*)").From("action_run").
201203
Where(builder.Eq{"repo_id": repo.ID}),

models/actions/run_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package actions
5+
6+
import (
7+
"testing"
8+
9+
"code.gitea.io/gitea/models/db"
10+
repo_model "code.gitea.io/gitea/models/repo"
11+
"code.gitea.io/gitea/models/unittest"
12+
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func TestUpdateRepoRunsNumbers(t *testing.T) {
17+
assert.NoError(t, unittest.PrepareTestDatabase())
18+
19+
// update the number to a wrong one, the original is 3
20+
_, err := db.GetEngine(t.Context()).ID(4).Cols("num_closed_action_runs").Update(&repo_model.Repository{
21+
NumClosedActionRuns: 2,
22+
})
23+
assert.NoError(t, err)
24+
25+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
26+
assert.Equal(t, 4, repo.NumActionRuns)
27+
assert.Equal(t, 2, repo.NumClosedActionRuns)
28+
29+
// now update will correct them, only num_actionr_runs and num_closed_action_runs should be updated
30+
err = UpdateRepoRunsNumbers(t.Context(), repo)
31+
assert.NoError(t, err)
32+
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
33+
assert.Equal(t, 5, repo.NumActionRuns)
34+
assert.Equal(t, 3, repo.NumClosedActionRuns)
35+
}

models/activities/notification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func SetNotificationStatus(ctx context.Context, notificationID int64, user *user
386386

387387
notification.Status = status
388388

389-
_, err = db.GetEngine(ctx).ID(notificationID).Update(notification)
389+
_, err = db.GetEngine(ctx).ID(notificationID).Cols("status").Update(notification)
390390
return notification, err
391391
}
392392

models/asymkey/gpg_key_verify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func VerifyGPGKey(ctx context.Context, ownerID int64, keyID, token, signature st
7878
}
7979

8080
key.Verified = true
81-
if _, err := db.GetEngine(ctx).ID(key.ID).SetExpr("verified", true).Update(new(GPGKey)); err != nil {
81+
if _, err := db.GetEngine(ctx).ID(key.ID).Cols("verified").Update(key); err != nil {
8282
return "", err
8383
}
8484

models/fixtures/action_run.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,23 @@
159159
updated: 1683636626
160160
need_approval: 0
161161
approved_by: 0
162+
-
163+
id: 805
164+
title: "update actions"
165+
repo_id: 4
166+
owner_id: 1
167+
workflow_id: "artifact.yaml"
168+
index: 191
169+
trigger_user_id: 1
170+
ref: "refs/heads/master"
171+
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
172+
event: "push"
173+
trigger_event: "push"
174+
is_fork_pull_request: 0
175+
status: 5
176+
started: 1683636528
177+
stopped: 1683636626
178+
created: 1683636108
179+
updated: 1683636626
180+
need_approval: 0
181+
approved_by: 0

0 commit comments

Comments
 (0)