Skip to content

Commit c10a5b9

Browse files
wxiaoguangGiteaBot
andauthored
Remove unneeded doctor sub-commands (#37156)
Co-authored-by: Giteabot <teabot@gitea.io>
1 parent 980a899 commit c10a5b9

15 files changed

Lines changed: 1 addition & 1268 deletions

File tree

models/actions/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestUpdateRepoRunsNumbers(t *testing.T) {
3232
err = UpdateRepoRunsNumbers(t.Context(), repo)
3333
assert.NoError(t, err)
3434
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
35-
assert.Equal(t, 5, repo.NumActionRuns)
35+
assert.Equal(t, 4, repo.NumActionRuns)
3636
assert.Equal(t, 3, repo.NumClosedActionRuns)
3737
}
3838

models/fixtures/action_run.yml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,4 @@
140140
need_approval: 0
141141
approved_by: 0
142142

143-
-
144-
id: 805
145-
title: "update actions"
146-
repo_id: 4
147-
owner_id: 1
148-
workflow_id: "artifact.yaml"
149-
index: 191
150-
trigger_user_id: 1
151-
ref: "refs/heads/master"
152-
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
153-
event: "push"
154-
trigger_event: "push"
155-
is_fork_pull_request: 0
156-
status: 5
157-
started: 1683636528
158-
stopped: 1683636626
159-
created: 1683636108
160-
updated: 1683636626
161-
need_approval: 0
162-
approved_by: 0
163-
164143
# DO NOT add more test data in the fixtures, test case should prepare their own test data separately and clearly

models/fixtures/action_run_job.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,4 @@
130130
started: 1683636528
131131
stopped: 1683636626
132132

133-
-
134-
id: 206
135-
run_id: 805
136-
repo_id: 4
137-
owner_id: 1
138-
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
139-
is_fork_pull_request: 0
140-
name: job_2
141-
attempt: 1
142-
job_id: job_2
143-
task_id: 56
144-
status: 3
145-
started: 1683636528
146-
stopped: 1683636626
147-
148133
# DO NOT add more test data in the fixtures, test case should prepare their own test data separately and clearly

models/fixtures/action_task.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,24 +178,4 @@
178178
log_size: 0
179179
log_expired: 0
180180

181-
-
182-
id: 56
183-
attempt: 1
184-
runner_id: 1
185-
status: 3 # 3 is the status code for "cancelled"
186-
started: 1683636528
187-
stopped: 1683636626
188-
repo_id: 4
189-
owner_id: 1
190-
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
191-
is_fork_pull_request: 0
192-
token_hash: 6d8ef48297195edcc8e22c70b3020eaa06c52976db67d39b4240c64a69a2cc1508825121b7b8394e48e00b1bf3718b2aaaab
193-
token_salt: eeeeeeee
194-
token_last_eight: eeeeeeee
195-
log_filename: artifact-test2/2f/47.log
196-
log_in_storage: 1
197-
log_length: 707
198-
log_size: 90179
199-
log_expired: 0
200-
201181
# DO NOT add more test data in the fixtures, test case should prepare their own test data separately and clearly

models/user/user.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,16 +1462,6 @@ func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool {
14621462
return false
14631463
}
14641464

1465-
// CountWrongUserType count OrgUser who have wrong type
1466-
func CountWrongUserType(ctx context.Context) (int64, error) {
1467-
return db.GetEngine(ctx).Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Count(new(User))
1468-
}
1469-
1470-
// FixWrongUserType fix OrgUser who have wrong type
1471-
func FixWrongUserType(ctx context.Context) (int64, error) {
1472-
return db.GetEngine(ctx).Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Cols("type").NoAutoTime().Update(&User{Type: 1})
1473-
}
1474-
14751465
func GetOrderByName() string {
14761466
if setting.UI.DefaultShowFullName {
14771467
return "full_name, name"

services/doctor/actions.go

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ import (
77
"context"
88
"fmt"
99

10-
actions_model "code.gitea.io/gitea/models/actions"
1110
"code.gitea.io/gitea/models/db"
1211
repo_model "code.gitea.io/gitea/models/repo"
1312
unit_model "code.gitea.io/gitea/models/unit"
1413
"code.gitea.io/gitea/modules/log"
1514
"code.gitea.io/gitea/modules/optional"
16-
"code.gitea.io/gitea/modules/setting"
17-
"code.gitea.io/gitea/modules/timeutil"
1815
repo_service "code.gitea.io/gitea/services/repository"
19-
20-
"xorm.io/builder"
2116
)
2217

2318
func disableMirrorActionsUnit(ctx context.Context, logger log.Logger, autofix bool) error {
@@ -64,95 +59,6 @@ func disableMirrorActionsUnit(ctx context.Context, logger log.Logger, autofix bo
6459
return nil
6560
}
6661

67-
func fixUnfinishedRunStatus(ctx context.Context, logger log.Logger, autofix bool) error {
68-
total := 0
69-
inconsistent := 0
70-
fixed := 0
71-
72-
cond := builder.In("status", []actions_model.Status{
73-
actions_model.StatusWaiting,
74-
actions_model.StatusRunning,
75-
actions_model.StatusBlocked,
76-
}).And(builder.Lt{"updated": timeutil.TimeStampNow().AddDuration(-setting.Actions.ZombieTaskTimeout)})
77-
78-
err := db.Iterate(
79-
ctx,
80-
cond,
81-
func(ctx context.Context, run *actions_model.ActionRun) error {
82-
total++
83-
84-
jobs, err := actions_model.GetRunJobsByRunID(ctx, run.ID)
85-
if err != nil {
86-
return fmt.Errorf("GetRunJobsByRunID: %w", err)
87-
}
88-
expected := actions_model.AggregateJobStatus(jobs)
89-
if expected == run.Status {
90-
return nil
91-
}
92-
93-
inconsistent++
94-
logger.Warn("Run %d (repo_id=%d, index=%d) has status %s, expected %s", run.ID, run.RepoID, run.Index, run.Status, expected)
95-
96-
if !autofix {
97-
return nil
98-
}
99-
100-
run.Started, run.Stopped = getRunTimestampsFromJobs(run, expected, jobs)
101-
run.Status = expected
102-
103-
if err := actions_model.UpdateRun(ctx, run, "status", "started", "stopped"); err != nil {
104-
return fmt.Errorf("UpdateRun: %w", err)
105-
}
106-
fixed++
107-
108-
return nil
109-
},
110-
)
111-
if err != nil {
112-
logger.Critical("Unable to iterate unfinished runs: %v", err)
113-
return err
114-
}
115-
116-
if inconsistent == 0 {
117-
logger.Info("Checked %d unfinished runs; all statuses are consistent.", total)
118-
return nil
119-
}
120-
121-
if autofix {
122-
logger.Info("Checked %d unfinished runs; fixed %d of %d runs.", total, fixed, inconsistent)
123-
} else {
124-
logger.Warn("Checked %d unfinished runs; found %d runs need to be fixed", total, inconsistent)
125-
}
126-
127-
return nil
128-
}
129-
130-
func getRunTimestampsFromJobs(run *actions_model.ActionRun, newStatus actions_model.Status, jobs actions_model.ActionJobList) (started, stopped timeutil.TimeStamp) {
131-
started = run.Started
132-
if (newStatus.IsRunning() || newStatus.IsDone()) && started.IsZero() {
133-
var earliest timeutil.TimeStamp
134-
for _, job := range jobs {
135-
if job.Started > 0 && (earliest.IsZero() || job.Started < earliest) {
136-
earliest = job.Started
137-
}
138-
}
139-
started = earliest
140-
}
141-
142-
stopped = run.Stopped
143-
if newStatus.IsDone() && stopped.IsZero() {
144-
var latest timeutil.TimeStamp
145-
for _, job := range jobs {
146-
if job.Stopped > latest {
147-
latest = job.Stopped
148-
}
149-
}
150-
stopped = latest
151-
}
152-
153-
return started, stopped
154-
}
155-
15662
func init() {
15763
Register(&Check{
15864
Title: "Disable the actions unit for all mirrors",
@@ -161,11 +67,4 @@ func init() {
16167
Run: disableMirrorActionsUnit,
16268
Priority: 9,
16369
})
164-
Register(&Check{
165-
Title: "Fix inconsistent status for unfinished actions runs",
166-
Name: "fix-actions-unfinished-run-status",
167-
IsDefault: false,
168-
Run: fixUnfinishedRunStatus,
169-
Priority: 9,
170-
})
17170
}

services/doctor/actions_test.go

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

services/doctor/breaking.go

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

services/doctor/dbversion.go

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

0 commit comments

Comments
 (0)