Skip to content

Commit 7f44370

Browse files
authored
Merge branch 'main' into support-issue-list
2 parents 8803a97 + 02c64e4 commit 7f44370

38 files changed

+210
-22
lines changed

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 {

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+
}

options/locale/locale_cs-CZ.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,6 +3742,7 @@ variables.creation.success=Proměnná „%s“ byla přidána.
37423742
variables.update.failed=Úprava proměnné se nezdařila.
37433743
variables.update.success=Proměnná byla upravena.
37443744
3745+
37453746
[projects]
37463747
deleted.display_name=Odstraněný projekt
37473748
type-1.display_name=Samostatný projekt

options/locale/locale_de-DE.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,6 +3556,7 @@ variables.creation.success=Die Variable „%s“ wurde hinzugefügt.
35563556
variables.update.failed=Fehler beim Bearbeiten der Variable.
35573557
variables.update.success=Die Variable wurde bearbeitet.
35583558

3559+
35593560
[projects]
35603561
type-1.display_name=Individuelles Projekt
35613562
type-2.display_name=Repository-Projekt

options/locale/locale_el-GR.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,6 +3439,7 @@ variables.creation.success=Η μεταβλητή "%s" έχει προστεθε
34393439
variables.update.failed=Αποτυχία επεξεργασίας μεταβλητής.
34403440
variables.update.success=Η μεταβλητή έχει τροποποιηθεί.
34413441

3442+
34423443
[projects]
34433444
type-1.display_name=Ατομικό Έργο
34443445
type-2.display_name=Έργο Αποθετηρίου

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,6 +3722,7 @@ runners.status.active = Active
37223722
runners.status.offline = Offline
37233723
runners.version = Version
37243724
runners.reset_registration_token = Reset registration token
3725+
runners.reset_registration_token_confirm = Would you like to invalidate the current token and generate a new one?
37253726
runners.reset_registration_token_success = Runner registration token reset successfully
37263727
37273728
runs.all_workflows = All Workflows

options/locale/locale_es-ES.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,6 +3415,7 @@ variables.creation.success=La variable "%s" ha sido añadida.
34153415
variables.update.failed=Error al editar la variable.
34163416
variables.update.success=La variable ha sido editada.
34173417
3418+
34183419
[projects]
34193420
type-1.display_name=Proyecto individual
34203421
type-2.display_name=Proyecto repositorio

options/locale/locale_fa-IR.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,6 +2529,7 @@ runs.commit=کامیت
25292529

25302530

25312531

2532+
25322533
[projects]
25332534

25342535
[git.filemode]

options/locale/locale_fi-FI.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,7 @@ runs.commit=Commit
17071707

17081708

17091709

1710+
17101711
[projects]
17111712

17121713
[git.filemode]

0 commit comments

Comments
 (0)