Skip to content

Commit 2549ad6

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin Fix ephemeral runner deletion (go-gitea#34447) ui: add a default tab on repo header when migrating (go-gitea#34503) Use run-name and evaluate workflow variables (go-gitea#34301) feat(api): add date range filtering to commit retrieval endpoints (go-gitea#34497) Export repo's manual merge settings (go-gitea#34502)
2 parents 94d765d + 14bb8f7 commit 2549ad6

File tree

28 files changed

+631
-56
lines changed

28 files changed

+631
-56
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ replace github.com/hashicorp/go-version => github.com/6543/go-version v1.3.1
317317

318318
replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0
319319

320-
replace github.com/nektos/act => gitea.com/gitea/act v0.261.4
320+
replace github.com/nektos/act => gitea.com/gitea/act v0.261.6
321321

322322
// TODO: the only difference is in `PutObject`: the fork doesn't use `NewVerifyingReader(r, sha256.New(), oid, expectedSize)`, need to figure out why
323323
replace github.com/charmbracelet/git-lfs-transfer => gitea.com/gitea/git-lfs-transfer v0.2.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
1414
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
1515
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
1616
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
17-
gitea.com/gitea/act v0.261.4 h1:Tf9eLlvsYFtKcpuxlMvf9yT3g4Hshb2Beqw6C1STuH8=
18-
gitea.com/gitea/act v0.261.4/go.mod h1:Pg5C9kQY1CEA3QjthjhlrqOC/QOT5NyWNjOjRHw23Ok=
17+
gitea.com/gitea/act v0.261.6 h1:CjZwKOyejonNFDmsXOw3wGm5Vet573hHM6VMLsxtvPY=
18+
gitea.com/gitea/act v0.261.6/go.mod h1:Pg5C9kQY1CEA3QjthjhlrqOC/QOT5NyWNjOjRHw23Ok=
1919
gitea.com/gitea/git-lfs-transfer v0.2.0 h1:baHaNoBSRaeq/xKayEXwiDQtlIjps4Ac/Ll4KqLMB40=
2020
gitea.com/gitea/git-lfs-transfer v0.2.0/go.mod h1:UrXUCm3xLQkq15fu7qlXHUMlrhdlXHoi13KH2Dfiits=
2121
gitea.com/gitea/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:BAFmdZpRW7zMQZQDClaCWobRj9uL1MR3MzpCVJvc5s4=

models/actions/runner.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package actions
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"strings"
1011
"time"
@@ -298,6 +299,23 @@ func DeleteRunner(ctx context.Context, id int64) error {
298299
return err
299300
}
300301

302+
// DeleteEphemeralRunner deletes a ephemeral runner by given ID.
303+
func DeleteEphemeralRunner(ctx context.Context, id int64) error {
304+
runner, err := GetRunnerByID(ctx, id)
305+
if err != nil {
306+
if errors.Is(err, util.ErrNotExist) {
307+
return nil
308+
}
309+
return err
310+
}
311+
if !runner.Ephemeral {
312+
return nil
313+
}
314+
315+
_, err = db.DeleteByID[ActionRunner](ctx, id)
316+
return err
317+
}
318+
301319
// CreateRunner creates new runner.
302320
func CreateRunner(ctx context.Context, t *ActionRunner) error {
303321
if t.OwnerID != 0 && t.RepoID != 0 {

models/actions/task.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ func UpdateTask(ctx context.Context, task *ActionTask, cols ...string) error {
336336
sess.Cols(cols...)
337337
}
338338
_, err := sess.Update(task)
339+
340+
// Automatically delete the ephemeral runner if the task is done
341+
if err == nil && task.Status.IsDone() && util.SliceContainsString(cols, "status") {
342+
return DeleteEphemeralRunner(ctx, task.RunnerID)
343+
}
339344
return err
340345
}
341346

models/actions/utils.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,22 @@ func calculateDuration(started, stopped timeutil.TimeStamp, status Status) time.
8282
}
8383
return timeSince(s).Truncate(time.Second)
8484
}
85+
86+
// best effort function to convert an action schedule to action run, to be used in GenerateGiteaContext
87+
func (s *ActionSchedule) ToActionRun() *ActionRun {
88+
return &ActionRun{
89+
Title: s.Title,
90+
RepoID: s.RepoID,
91+
Repo: s.Repo,
92+
OwnerID: s.OwnerID,
93+
WorkflowID: s.WorkflowID,
94+
TriggerUserID: s.TriggerUserID,
95+
TriggerUser: s.TriggerUser,
96+
Ref: s.Ref,
97+
CommitSHA: s.CommitSHA,
98+
Event: s.Event,
99+
EventPayload: s.EventPayload,
100+
Created: s.Created,
101+
Updated: s.Updated,
102+
}
103+
}

models/fixtures/action_runner.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@
3838
repo_id: 0
3939
description: "This runner is going to be deleted"
4040
agent_labels: '["runner_to_be_deleted","linux"]'
41+
-
42+
id: 34350
43+
name: runner_to_be_deleted-org-ephemeral
44+
uuid: 3FF231BD-FBB7-4E4B-9602-E6F28363EF20
45+
token_hash: 3FF231BD-FBB7-4E4B-9602-E6F28363EF20
46+
ephemeral: true
47+
version: "1.0.0"
48+
owner_id: 3
49+
repo_id: 0
50+
description: "This runner is going to be deleted"
51+
agent_labels: '["runner_to_be_deleted","linux"]'

models/fixtures/action_task.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@
117117
log_length: 707
118118
log_size: 90179
119119
log_expired: 0
120+
-
121+
id: 52
122+
job_id: 196
123+
attempt: 1
124+
runner_id: 34350
125+
status: 6 # running
126+
started: 1683636528
127+
stopped: 1683636626
128+
repo_id: 4
129+
owner_id: 1
130+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
131+
is_fork_pull_request: 0
132+
token_hash: f8d3962425466b6709b9ac51446f93260c54afe8e7b6d3686e34f991fb8a8953822b0deed86fe41a103f34bc48dbc4784222
133+
token_salt: ffffffffff
134+
token_last_eight: ffffffff
135+
log_filename: artifact-test2/2f/47.log
136+
log_in_storage: 1
137+
log_length: 707
138+
log_size: 90179
139+
log_expired: 0
120140
-
121141
id: 53
122142
job_id: 198

modules/git/commit.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ type CommitsCountOptions struct {
166166
Not string
167167
Revision []string
168168
RelPath []string
169+
Since string
170+
Until string
169171
}
170172

171173
// CommitsCount returns number of total commits of until given revision.
@@ -199,8 +201,8 @@ func (c *Commit) CommitsCount() (int64, error) {
199201
}
200202

201203
// CommitsByRange returns the specific page commits before current revision, every page's number default by CommitsRangeSize
202-
func (c *Commit) CommitsByRange(page, pageSize int, not string) ([]*Commit, error) {
203-
return c.repo.commitsByRange(c.ID, page, pageSize, not)
204+
func (c *Commit) CommitsByRange(page, pageSize int, not, since, until string) ([]*Commit, error) {
205+
return c.repo.commitsByRangeWithTime(c.ID, page, pageSize, not, since, until)
204206
}
205207

206208
// CommitsBefore returns all the commits before current revision

modules/git/repo_commit.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
8989
return commits[0], nil
9090
}
9191

92-
func (repo *Repository) commitsByRange(id ObjectID, page, pageSize int, not string) ([]*Commit, error) {
92+
// commitsByRangeWithTime returns the specific page commits before current revision, with not, since, until support
93+
func (repo *Repository) commitsByRangeWithTime(id ObjectID, page, pageSize int, not, since, until string) ([]*Commit, error) {
9394
cmd := NewCommand("log").
9495
AddOptionFormat("--skip=%d", (page-1)*pageSize).
9596
AddOptionFormat("--max-count=%d", pageSize).
@@ -99,6 +100,12 @@ func (repo *Repository) commitsByRange(id ObjectID, page, pageSize int, not stri
99100
if not != "" {
100101
cmd.AddOptionValues("--not", not)
101102
}
103+
if since != "" {
104+
cmd.AddOptionFormat("--since=%s", since)
105+
}
106+
if until != "" {
107+
cmd.AddOptionFormat("--until=%s", until)
108+
}
102109

103110
stdout, _, err := cmd.RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})
104111
if err != nil {
@@ -212,6 +219,8 @@ type CommitsByFileAndRangeOptions struct {
212219
File string
213220
Not string
214221
Page int
222+
Since string
223+
Until string
215224
}
216225

217226
// CommitsByFileAndRange return the commits according revision file and the page
@@ -231,6 +240,12 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
231240
if opts.Not != "" {
232241
gitCmd.AddOptionValues("--not", opts.Not)
233242
}
243+
if opts.Since != "" {
244+
gitCmd.AddOptionFormat("--since=%s", opts.Since)
245+
}
246+
if opts.Until != "" {
247+
gitCmd.AddOptionFormat("--until=%s", opts.Until)
248+
}
234249

235250
gitCmd.AddDashesAndList(opts.File)
236251
err := gitCmd.Run(repo.Ctx, &RunOpts{

modules/git/repo_stats.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
4040

4141
since := fromTime.Format(time.RFC3339)
4242

43-
stdout, _, runErr := NewCommand("rev-list", "--count", "--no-merges", "--branches=*", "--date=iso").AddOptionFormat("--since='%s'", since).RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
43+
stdout, _, runErr := NewCommand("rev-list", "--count", "--no-merges", "--branches=*", "--date=iso").
44+
AddOptionFormat("--since=%s", since).
45+
RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
4446
if runErr != nil {
4547
return nil, runErr
4648
}
@@ -60,7 +62,8 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
6062
_ = stdoutWriter.Close()
6163
}()
6264

63-
gitCmd := NewCommand("log", "--numstat", "--no-merges", "--pretty=format:---%n%h%n%aN%n%aE%n", "--date=iso").AddOptionFormat("--since='%s'", since)
65+
gitCmd := NewCommand("log", "--numstat", "--no-merges", "--pretty=format:---%n%h%n%aN%n%aE%n", "--date=iso").
66+
AddOptionFormat("--since=%s", since)
6467
if len(branch) == 0 {
6568
gitCmd.AddArguments("--branches=*")
6669
} else {

modules/repository/commits_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,3 @@ func TestListToPushCommits(t *testing.T) {
200200
assert.Equal(t, now, pushCommits.Commits[1].Timestamp)
201201
}
202202
}
203-
204-
// TODO TestPushUpdate

modules/structs/repo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ type Repository struct {
101101
AllowSquash bool `json:"allow_squash_merge"`
102102
AllowFastForwardOnly bool `json:"allow_fast_forward_only_merge"`
103103
AllowRebaseUpdate bool `json:"allow_rebase_update"`
104+
AllowManualMerge bool `json:"allow_manual_merge"`
105+
AutodetectManualMerge bool `json:"autodetect_manual_merge"`
104106
DefaultDeleteBranchAfterMerge bool `json:"default_delete_branch_after_merge"`
105107
DefaultMergeStyle string `json:"default_merge_style"`
106108
DefaultAllowMaintainerEdit bool `json:"default_allow_maintainer_edit"`

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,7 @@ migrate.migrating_issues = Migrating Issues
12281228
migrate.migrating_pulls = Migrating Pull Requests
12291229
migrate.cancel_migrating_title = Cancel Migration
12301230
migrate.cancel_migrating_confirm = Do you want to cancel this migration?
1231+
migrating_status = Migrating status
12311232
12321233
mirror_from = mirror of
12331234
forked_from = forked from

0 commit comments

Comments
 (0)