Skip to content

Commit 5050f7f

Browse files
authored
Merge branch 'main' into fix-pom-parent
2 parents 1cd5fa1 + 2a828e2 commit 5050f7f

File tree

318 files changed

+2297
-1729
lines changed

Some content is hidden

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

318 files changed

+2297
-1729
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build stage
2-
FROM docker.io/library/golang:1.23-alpine3.20 AS build-env
2+
FROM docker.io/library/golang:1.23-alpine3.21 AS build-env
33

44
ARG GOPROXY
55
ENV GOPROXY=${GOPROXY:-direct}
@@ -41,7 +41,7 @@ RUN chmod 755 /tmp/local/usr/bin/entrypoint \
4141
/go/src/code.gitea.io/gitea/environment-to-ini
4242
RUN chmod 644 /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete
4343

44-
FROM docker.io/library/alpine:3.20
44+
FROM docker.io/library/alpine:3.21
4545
LABEL maintainer="[email protected]"
4646

4747
EXPOSE 22 3000
@@ -78,7 +78,7 @@ ENV GITEA_CUSTOM=/data/gitea
7878
VOLUME ["/data"]
7979

8080
ENTRYPOINT ["/usr/bin/entrypoint"]
81-
CMD ["/bin/s6-svscan", "/etc/s6"]
81+
CMD ["/usr/bin/s6-svscan", "/etc/s6"]
8282

8383
COPY --from=build-env /tmp/local /
8484
COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea

Dockerfile.rootless

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build stage
2-
FROM docker.io/library/golang:1.23-alpine3.20 AS build-env
2+
FROM docker.io/library/golang:1.23-alpine3.21 AS build-env
33

44
ARG GOPROXY
55
ENV GOPROXY=${GOPROXY:-direct}
@@ -39,7 +39,7 @@ RUN chmod 755 /tmp/local/usr/local/bin/docker-entrypoint.sh \
3939
/go/src/code.gitea.io/gitea/environment-to-ini
4040
RUN chmod 644 /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete
4141

42-
FROM docker.io/library/alpine:3.20
42+
FROM docker.io/library/alpine:3.21
4343
LABEL maintainer="[email protected]"
4444

4545
EXPOSE 2222 3000

models/actions/runner_token.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"code.gitea.io/gitea/models/db"
1111
repo_model "code.gitea.io/gitea/models/repo"
1212
user_model "code.gitea.io/gitea/models/user"
13+
"code.gitea.io/gitea/modules/base"
1314
"code.gitea.io/gitea/modules/timeutil"
1415
"code.gitea.io/gitea/modules/util"
1516
)
@@ -51,7 +52,7 @@ func GetRunnerToken(ctx context.Context, token string) (*ActionRunnerToken, erro
5152
if err != nil {
5253
return nil, err
5354
} else if !has {
54-
return nil, fmt.Errorf("runner token %q: %w", token, util.ErrNotExist)
55+
return nil, fmt.Errorf(`runner token "%s...": %w`, base.TruncateString(token, 3), util.ErrNotExist)
5556
}
5657
return &runnerToken, nil
5758
}
@@ -68,19 +69,15 @@ func UpdateRunnerToken(ctx context.Context, r *ActionRunnerToken, cols ...string
6869
return err
6970
}
7071

71-
// NewRunnerToken creates a new active runner token and invalidate all old tokens
72+
// NewRunnerTokenWithValue creates a new active runner token and invalidate all old tokens
7273
// ownerID will be ignored and treated as 0 if repoID is non-zero.
73-
func NewRunnerToken(ctx context.Context, ownerID, repoID int64) (*ActionRunnerToken, error) {
74+
func NewRunnerTokenWithValue(ctx context.Context, ownerID, repoID int64, token string) (*ActionRunnerToken, error) {
7475
if ownerID != 0 && repoID != 0 {
7576
// It's trying to create a runner token that belongs to a repository, but OwnerID has been set accidentally.
7677
// Remove OwnerID to avoid confusion; it's not worth returning an error here.
7778
ownerID = 0
7879
}
7980

80-
token, err := util.CryptoRandomString(40)
81-
if err != nil {
82-
return nil, err
83-
}
8481
runnerToken := &ActionRunnerToken{
8582
OwnerID: ownerID,
8683
RepoID: repoID,
@@ -95,11 +92,19 @@ func NewRunnerToken(ctx context.Context, ownerID, repoID int64) (*ActionRunnerTo
9592
return err
9693
}
9794

98-
_, err = db.GetEngine(ctx).Insert(runnerToken)
95+
_, err := db.GetEngine(ctx).Insert(runnerToken)
9996
return err
10097
})
10198
}
10299

100+
func NewRunnerToken(ctx context.Context, ownerID, repoID int64) (*ActionRunnerToken, error) {
101+
token, err := util.CryptoRandomString(40)
102+
if err != nil {
103+
return nil, err
104+
}
105+
return NewRunnerTokenWithValue(ctx, ownerID, repoID, token)
106+
}
107+
103108
// GetLatestRunnerToken returns the latest runner token
104109
func GetLatestRunnerToken(ctx context.Context, ownerID, repoID int64) (*ActionRunnerToken, error) {
105110
if ownerID != 0 && repoID != 0 {

models/migrations/base/tests.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"testing"
1414

1515
"code.gitea.io/gitea/models/unittest"
16-
"code.gitea.io/gitea/modules/base"
1716
"code.gitea.io/gitea/modules/git"
1817
"code.gitea.io/gitea/modules/setting"
18+
"code.gitea.io/gitea/modules/test"
1919
"code.gitea.io/gitea/modules/testlogger"
2020

2121
"github.com/stretchr/testify/require"
@@ -92,10 +92,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
9292
func MainTest(m *testing.M) {
9393
testlogger.Init()
9494

95-
giteaRoot := base.SetupGiteaRoot()
96-
if giteaRoot == "" {
97-
testlogger.Fatalf("Environment variable $GITEA_ROOT not set\n")
98-
}
95+
giteaRoot := test.SetupGiteaRoot()
9996
giteaBinary := "gitea"
10097
if runtime.GOOS == "windows" {
10198
giteaBinary += ".exe"

models/unittest/testdb.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import (
1414
"code.gitea.io/gitea/models/db"
1515
"code.gitea.io/gitea/models/system"
1616
"code.gitea.io/gitea/modules/auth/password/hash"
17-
"code.gitea.io/gitea/modules/base"
1817
"code.gitea.io/gitea/modules/cache"
1918
"code.gitea.io/gitea/modules/git"
2019
"code.gitea.io/gitea/modules/log"
2120
"code.gitea.io/gitea/modules/setting"
2221
"code.gitea.io/gitea/modules/setting/config"
2322
"code.gitea.io/gitea/modules/storage"
23+
"code.gitea.io/gitea/modules/test"
2424
"code.gitea.io/gitea/modules/util"
2525

2626
"github.com/stretchr/testify/assert"
@@ -206,7 +206,7 @@ func CreateTestEngine(opts FixturesOptions) error {
206206
x, err := xorm.NewEngine("sqlite3", "file::memory:?cache=shared&_txlock=immediate")
207207
if err != nil {
208208
if strings.Contains(err.Error(), "unknown driver") {
209-
return fmt.Errorf(`sqlite3 requires: import _ "github.com/mattn/go-sqlite3" or -tags sqlite,sqlite_unlock_notify%s%w`, "\n", err)
209+
return fmt.Errorf(`sqlite3 requires: -tags sqlite,sqlite_unlock_notify%s%w`, "\n", err)
210210
}
211211
return err
212212
}
@@ -235,5 +235,5 @@ func PrepareTestEnv(t testing.TB) {
235235
assert.NoError(t, PrepareTestDatabase())
236236
metaPath := filepath.Join(giteaRoot, "tests", "gitea-repositories-meta")
237237
assert.NoError(t, SyncDirs(metaPath, setting.RepoRootPath))
238-
base.SetupGiteaRoot() // Makes sure GITEA_ROOT is set
238+
test.SetupGiteaRoot() // Makes sure GITEA_ROOT is set
239239
}

modules/base/base.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

modules/base/tool.go

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ import (
1313
"errors"
1414
"fmt"
1515
"hash"
16-
"os"
17-
"path/filepath"
18-
"runtime"
1916
"strconv"
2017
"strings"
2118
"time"
@@ -189,49 +186,3 @@ func EntryIcon(entry *git.TreeEntry) string {
189186

190187
return "file"
191188
}
192-
193-
// SetupGiteaRoot Sets GITEA_ROOT if it is not already set and returns the value
194-
func SetupGiteaRoot() string {
195-
giteaRoot := os.Getenv("GITEA_ROOT")
196-
if giteaRoot == "" {
197-
_, filename, _, _ := runtime.Caller(0)
198-
giteaRoot = strings.TrimSuffix(filename, "modules/base/tool.go")
199-
wd, err := os.Getwd()
200-
if err != nil {
201-
rel, err := filepath.Rel(giteaRoot, wd)
202-
if err != nil && strings.HasPrefix(filepath.ToSlash(rel), "../") {
203-
giteaRoot = wd
204-
}
205-
}
206-
if _, err := os.Stat(filepath.Join(giteaRoot, "gitea")); os.IsNotExist(err) {
207-
giteaRoot = ""
208-
} else if err := os.Setenv("GITEA_ROOT", giteaRoot); err != nil {
209-
giteaRoot = ""
210-
}
211-
}
212-
return giteaRoot
213-
}
214-
215-
// FormatNumberSI format a number
216-
func FormatNumberSI(data any) string {
217-
var num int64
218-
if num1, ok := data.(int64); ok {
219-
num = num1
220-
} else if num1, ok := data.(int); ok {
221-
num = int64(num1)
222-
} else {
223-
return ""
224-
}
225-
226-
if num < 1000 {
227-
return fmt.Sprintf("%d", num)
228-
} else if num < 1000000 {
229-
num2 := float32(num) / float32(1000.0)
230-
return fmt.Sprintf("%.1fk", num2)
231-
} else if num < 1000000000 {
232-
num2 := float32(num) / float32(1000000.0)
233-
return fmt.Sprintf("%.1fM", num2)
234-
}
235-
num2 := float32(num) / float32(1000000000.0)
236-
return fmt.Sprintf("%.1fG", num2)
237-
}

modules/base/tool_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,3 @@ func TestInt64sToStrings(t *testing.T) {
169169
}
170170

171171
// TODO: Test EntryIcon
172-
173-
func TestSetupGiteaRoot(t *testing.T) {
174-
t.Setenv("GITEA_ROOT", "test")
175-
assert.Equal(t, "test", SetupGiteaRoot())
176-
t.Setenv("GITEA_ROOT", "")
177-
assert.NotEqual(t, "test", SetupGiteaRoot())
178-
}
179-
180-
func TestFormatNumberSI(t *testing.T) {
181-
assert.Equal(t, "125", FormatNumberSI(int(125)))
182-
assert.Equal(t, "1.3k", FormatNumberSI(int64(1317)))
183-
assert.Equal(t, "21.3M", FormatNumberSI(21317675))
184-
assert.Equal(t, "45.7G", FormatNumberSI(45721317675))
185-
assert.Equal(t, "", FormatNumberSI("test"))
186-
}

modules/git/repo_commit.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ type CommitsByFileAndRangeOptions struct {
216216

217217
// CommitsByFileAndRange return the commits according revision file and the page
218218
func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions) ([]*Commit, error) {
219-
skip := (opts.Page - 1) * setting.Git.CommitsRangeSize
220-
221219
stdoutReader, stdoutWriter := io.Pipe()
222220
defer func() {
223221
_ = stdoutReader.Close()
@@ -226,8 +224,8 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
226224
go func() {
227225
stderr := strings.Builder{}
228226
gitCmd := NewCommand(repo.Ctx, "rev-list").
229-
AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize*opts.Page).
230-
AddOptionFormat("--skip=%d", skip)
227+
AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize).
228+
AddOptionFormat("--skip=%d", (opts.Page-1)*setting.Git.CommitsRangeSize)
231229
gitCmd.AddDynamicArguments(opts.Revision)
232230

233231
if opts.Not != "" {

modules/git/repo_commit_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import (
88
"path/filepath"
99
"testing"
1010

11+
"code.gitea.io/gitea/modules/setting"
12+
"code.gitea.io/gitea/modules/test"
13+
1114
"github.com/stretchr/testify/assert"
15+
"github.com/stretchr/testify/require"
1216
)
1317

1418
func TestRepository_GetCommitBranches(t *testing.T) {
@@ -126,3 +130,21 @@ func TestGetRefCommitID(t *testing.T) {
126130
}
127131
}
128132
}
133+
134+
func TestCommitsByFileAndRange(t *testing.T) {
135+
defer test.MockVariableValue(&setting.Git.CommitsRangeSize, 2)()
136+
137+
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
138+
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
139+
require.NoError(t, err)
140+
defer bareRepo1.Close()
141+
142+
// "foo" has 3 commits in "master" branch
143+
commits, err := bareRepo1.CommitsByFileAndRange(CommitsByFileAndRangeOptions{Revision: "master", File: "foo", Page: 1})
144+
require.NoError(t, err)
145+
assert.Len(t, commits, 2)
146+
147+
commits, err = bareRepo1.CommitsByFileAndRange(CommitsByFileAndRangeOptions{Revision: "master", File: "foo", Page: 2})
148+
require.NoError(t, err)
149+
assert.Len(t, commits, 1)
150+
}

0 commit comments

Comments
 (0)