mirror of
https://github.com/go-gitea/gitea.git
synced 2025-06-20 13:40:29 +02:00
refactor: rename import alias
This commit is contained in:
parent
5f74b35377
commit
67c5c8868b
@ -4,7 +4,7 @@
|
|||||||
package actions
|
package actions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -13,7 +13,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// FullSteps returns steps with "Set up job" and "Complete job"
|
// FullSteps returns steps with "Set up job" and "Complete job"
|
||||||
func FullSteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
|
func FullSteps(task *actions_model.BotTask) []*actions_model.BotTaskStep {
|
||||||
if len(task.Steps) == 0 {
|
if len(task.Steps) == 0 {
|
||||||
return fullStepsOfEmptySteps(task)
|
return fullStepsOfEmptySteps(task)
|
||||||
}
|
}
|
||||||
@ -21,24 +21,24 @@ func FullSteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
|
|||||||
firstStep := task.Steps[0]
|
firstStep := task.Steps[0]
|
||||||
var logIndex int64
|
var logIndex int64
|
||||||
|
|
||||||
preStep := &bots_model.BotTaskStep{
|
preStep := &actions_model.BotTaskStep{
|
||||||
Name: preStepName,
|
Name: preStepName,
|
||||||
LogLength: task.LogLength,
|
LogLength: task.LogLength,
|
||||||
Started: task.Started,
|
Started: task.Started,
|
||||||
Status: bots_model.StatusRunning,
|
Status: actions_model.StatusRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
if firstStep.Status.HasRun() || firstStep.Status.IsRunning() {
|
if firstStep.Status.HasRun() || firstStep.Status.IsRunning() {
|
||||||
preStep.LogLength = firstStep.LogIndex
|
preStep.LogLength = firstStep.LogIndex
|
||||||
preStep.Stopped = firstStep.Started
|
preStep.Stopped = firstStep.Started
|
||||||
preStep.Status = bots_model.StatusSuccess
|
preStep.Status = actions_model.StatusSuccess
|
||||||
} else if task.Status.IsDone() {
|
} else if task.Status.IsDone() {
|
||||||
preStep.Stopped = task.Stopped
|
preStep.Stopped = task.Stopped
|
||||||
preStep.Status = bots_model.StatusFailure
|
preStep.Status = actions_model.StatusFailure
|
||||||
}
|
}
|
||||||
logIndex += preStep.LogLength
|
logIndex += preStep.LogLength
|
||||||
|
|
||||||
var lastHasRunStep *bots_model.BotTaskStep
|
var lastHasRunStep *actions_model.BotTaskStep
|
||||||
for _, step := range task.Steps {
|
for _, step := range task.Steps {
|
||||||
if step.Status.HasRun() {
|
if step.Status.HasRun() {
|
||||||
lastHasRunStep = step
|
lastHasRunStep = step
|
||||||
@ -49,9 +49,9 @@ func FullSteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
|
|||||||
lastHasRunStep = preStep
|
lastHasRunStep = preStep
|
||||||
}
|
}
|
||||||
|
|
||||||
postStep := &bots_model.BotTaskStep{
|
postStep := &actions_model.BotTaskStep{
|
||||||
Name: postStepName,
|
Name: postStepName,
|
||||||
Status: bots_model.StatusWaiting,
|
Status: actions_model.StatusWaiting,
|
||||||
}
|
}
|
||||||
if task.Status.IsDone() {
|
if task.Status.IsDone() {
|
||||||
postStep.LogIndex = logIndex
|
postStep.LogIndex = logIndex
|
||||||
@ -60,7 +60,7 @@ func FullSteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
|
|||||||
postStep.Started = lastHasRunStep.Stopped
|
postStep.Started = lastHasRunStep.Stopped
|
||||||
postStep.Stopped = task.Stopped
|
postStep.Stopped = task.Stopped
|
||||||
}
|
}
|
||||||
ret := make([]*bots_model.BotTaskStep, 0, len(task.Steps)+2)
|
ret := make([]*actions_model.BotTaskStep, 0, len(task.Steps)+2)
|
||||||
ret = append(ret, preStep)
|
ret = append(ret, preStep)
|
||||||
ret = append(ret, task.Steps...)
|
ret = append(ret, task.Steps...)
|
||||||
ret = append(ret, postStep)
|
ret = append(ret, postStep)
|
||||||
@ -68,33 +68,33 @@ func FullSteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func fullStepsOfEmptySteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
|
func fullStepsOfEmptySteps(task *actions_model.BotTask) []*actions_model.BotTaskStep {
|
||||||
preStep := &bots_model.BotTaskStep{
|
preStep := &actions_model.BotTaskStep{
|
||||||
Name: preStepName,
|
Name: preStepName,
|
||||||
LogLength: task.LogLength,
|
LogLength: task.LogLength,
|
||||||
Started: task.Started,
|
Started: task.Started,
|
||||||
Stopped: task.Stopped,
|
Stopped: task.Stopped,
|
||||||
Status: bots_model.StatusRunning,
|
Status: actions_model.StatusRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
postStep := &bots_model.BotTaskStep{
|
postStep := &actions_model.BotTaskStep{
|
||||||
Name: postStepName,
|
Name: postStepName,
|
||||||
LogIndex: task.LogLength,
|
LogIndex: task.LogLength,
|
||||||
Started: task.Stopped,
|
Started: task.Stopped,
|
||||||
Stopped: task.Stopped,
|
Stopped: task.Stopped,
|
||||||
Status: bots_model.StatusWaiting,
|
Status: actions_model.StatusWaiting,
|
||||||
}
|
}
|
||||||
|
|
||||||
if task.Status.IsDone() {
|
if task.Status.IsDone() {
|
||||||
preStep.Status = task.Status
|
preStep.Status = task.Status
|
||||||
if preStep.Status.IsSuccess() {
|
if preStep.Status.IsSuccess() {
|
||||||
postStep.Status = bots_model.StatusSuccess
|
postStep.Status = actions_model.StatusSuccess
|
||||||
} else {
|
} else {
|
||||||
postStep.Status = bots_model.StatusCancelled
|
postStep.Status = actions_model.StatusCancelled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return []*bots_model.BotTaskStep{
|
return []*actions_model.BotTaskStep{
|
||||||
preStep,
|
preStep,
|
||||||
postStep,
|
postStep,
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ package actions
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@ -14,93 +14,93 @@ import (
|
|||||||
func TestFullSteps(t *testing.T) {
|
func TestFullSteps(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
task *bots_model.BotTask
|
task *actions_model.BotTask
|
||||||
want []*bots_model.BotTaskStep
|
want []*actions_model.BotTaskStep
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "regular",
|
name: "regular",
|
||||||
task: &bots_model.BotTask{
|
task: &actions_model.BotTask{
|
||||||
Steps: []*bots_model.BotTaskStep{
|
Steps: []*actions_model.BotTaskStep{
|
||||||
{Status: bots_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
|
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
|
||||||
},
|
},
|
||||||
Status: bots_model.StatusSuccess,
|
Status: actions_model.StatusSuccess,
|
||||||
Started: 10000,
|
Started: 10000,
|
||||||
Stopped: 10100,
|
Stopped: 10100,
|
||||||
LogLength: 100,
|
LogLength: 100,
|
||||||
},
|
},
|
||||||
want: []*bots_model.BotTaskStep{
|
want: []*actions_model.BotTaskStep{
|
||||||
{Name: preStepName, Status: bots_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
|
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
|
||||||
{Status: bots_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
|
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
|
||||||
{Name: postStepName, Status: bots_model.StatusSuccess, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
|
{Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "failed step",
|
name: "failed step",
|
||||||
task: &bots_model.BotTask{
|
task: &actions_model.BotTask{
|
||||||
Steps: []*bots_model.BotTaskStep{
|
Steps: []*actions_model.BotTaskStep{
|
||||||
{Status: bots_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020},
|
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020},
|
||||||
{Status: bots_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090},
|
{Status: actions_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090},
|
||||||
{Status: bots_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
{Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
||||||
},
|
},
|
||||||
Status: bots_model.StatusFailure,
|
Status: actions_model.StatusFailure,
|
||||||
Started: 10000,
|
Started: 10000,
|
||||||
Stopped: 10100,
|
Stopped: 10100,
|
||||||
LogLength: 100,
|
LogLength: 100,
|
||||||
},
|
},
|
||||||
want: []*bots_model.BotTaskStep{
|
want: []*actions_model.BotTaskStep{
|
||||||
{Name: preStepName, Status: bots_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
|
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
|
||||||
{Status: bots_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020},
|
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020},
|
||||||
{Status: bots_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090},
|
{Status: actions_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090},
|
||||||
{Status: bots_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
{Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
||||||
{Name: postStepName, Status: bots_model.StatusFailure, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
|
{Name: postStepName, Status: actions_model.StatusFailure, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "first step is running",
|
name: "first step is running",
|
||||||
task: &bots_model.BotTask{
|
task: &actions_model.BotTask{
|
||||||
Steps: []*bots_model.BotTaskStep{
|
Steps: []*actions_model.BotTaskStep{
|
||||||
{Status: bots_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
|
{Status: actions_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
|
||||||
},
|
},
|
||||||
Status: bots_model.StatusRunning,
|
Status: actions_model.StatusRunning,
|
||||||
Started: 10000,
|
Started: 10000,
|
||||||
Stopped: 10100,
|
Stopped: 10100,
|
||||||
LogLength: 100,
|
LogLength: 100,
|
||||||
},
|
},
|
||||||
want: []*bots_model.BotTaskStep{
|
want: []*actions_model.BotTaskStep{
|
||||||
{Name: preStepName, Status: bots_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
|
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
|
||||||
{Status: bots_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
|
{Status: actions_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
|
||||||
{Name: postStepName, Status: bots_model.StatusWaiting, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
{Name: postStepName, Status: actions_model.StatusWaiting, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "first step has canceled",
|
name: "first step has canceled",
|
||||||
task: &bots_model.BotTask{
|
task: &actions_model.BotTask{
|
||||||
Steps: []*bots_model.BotTaskStep{
|
Steps: []*actions_model.BotTaskStep{
|
||||||
{Status: bots_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
{Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
||||||
},
|
},
|
||||||
Status: bots_model.StatusFailure,
|
Status: actions_model.StatusFailure,
|
||||||
Started: 10000,
|
Started: 10000,
|
||||||
Stopped: 10100,
|
Stopped: 10100,
|
||||||
LogLength: 100,
|
LogLength: 100,
|
||||||
},
|
},
|
||||||
want: []*bots_model.BotTaskStep{
|
want: []*actions_model.BotTaskStep{
|
||||||
{Name: preStepName, Status: bots_model.StatusFailure, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100},
|
{Name: preStepName, Status: actions_model.StatusFailure, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100},
|
||||||
{Status: bots_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
{Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
||||||
{Name: postStepName, Status: bots_model.StatusFailure, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
|
{Name: postStepName, Status: actions_model.StatusFailure, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty steps",
|
name: "empty steps",
|
||||||
task: &bots_model.BotTask{
|
task: &actions_model.BotTask{
|
||||||
Steps: []*bots_model.BotTaskStep{},
|
Steps: []*actions_model.BotTaskStep{},
|
||||||
Status: bots_model.StatusSuccess,
|
Status: actions_model.StatusSuccess,
|
||||||
Started: 10000,
|
Started: 10000,
|
||||||
Stopped: 10100,
|
Stopped: 10100,
|
||||||
LogLength: 100,
|
LogLength: 100,
|
||||||
},
|
},
|
||||||
want: []*bots_model.BotTaskStep{
|
want: []*actions_model.BotTaskStep{
|
||||||
{Name: preStepName, Status: bots_model.StatusSuccess, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100},
|
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100},
|
||||||
{Name: postStepName, Status: bots_model.StatusSuccess, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
|
{Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
packages_model "code.gitea.io/gitea/models/packages"
|
packages_model "code.gitea.io/gitea/models/packages"
|
||||||
@ -16,13 +16,13 @@ import (
|
|||||||
"code.gitea.io/gitea/models/unit"
|
"code.gitea.io/gitea/models/unit"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/models/webhook"
|
"code.gitea.io/gitea/models/webhook"
|
||||||
bots_module "code.gitea.io/gitea/modules/actions"
|
actions_module "code.gitea.io/gitea/modules/actions"
|
||||||
"code.gitea.io/gitea/modules/convert"
|
"code.gitea.io/gitea/modules/convert"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/json"
|
"code.gitea.io/gitea/modules/json"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
bots_service "code.gitea.io/gitea/services/actions"
|
actions_service "code.gitea.io/gitea/services/actions"
|
||||||
|
|
||||||
"github.com/nektos/act/pkg/jobparser"
|
"github.com/nektos/act/pkg/jobparser"
|
||||||
)
|
)
|
||||||
@ -117,7 +117,7 @@ func notify(ctx context.Context, input *notifyInput) error {
|
|||||||
return fmt.Errorf("gitRepo.GetCommit: %v", err)
|
return fmt.Errorf("gitRepo.GetCommit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
workflows, err := bots_module.DetectWorkflows(commit, input.Event)
|
workflows, err := actions_module.DetectWorkflows(commit, input.Event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("DetectWorkflows: %v", err)
|
return fmt.Errorf("DetectWorkflows: %v", err)
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ func notify(ctx context.Context, input *notifyInput) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for id, content := range workflows {
|
for id, content := range workflows {
|
||||||
run := bots_model.BotRun{
|
run := actions_model.BotRun{
|
||||||
Title: commit.Message(),
|
Title: commit.Message(),
|
||||||
RepoID: input.Repo.ID,
|
RepoID: input.Repo.ID,
|
||||||
OwnerID: input.Repo.OwnerID,
|
OwnerID: input.Repo.OwnerID,
|
||||||
@ -144,7 +144,7 @@ func notify(ctx context.Context, input *notifyInput) error {
|
|||||||
IsForkPullRequest: input.PullRequest != nil && input.PullRequest.IsFromFork(),
|
IsForkPullRequest: input.PullRequest != nil && input.PullRequest.IsFromFork(),
|
||||||
Event: input.Event,
|
Event: input.Event,
|
||||||
EventPayload: string(p),
|
EventPayload: string(p),
|
||||||
Status: bots_model.StatusWaiting,
|
Status: actions_model.StatusWaiting,
|
||||||
}
|
}
|
||||||
if len(run.Title) > 255 {
|
if len(run.Title) > 255 {
|
||||||
run.Title = run.Title[:255] // FIXME: we should use a better method to cut title
|
run.Title = run.Title[:255] // FIXME: we should use a better method to cut title
|
||||||
@ -154,15 +154,15 @@ func notify(ctx context.Context, input *notifyInput) error {
|
|||||||
log.Error("jobparser.Parse: %v", err)
|
log.Error("jobparser.Parse: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := bots_model.InsertRun(&run, jobs); err != nil {
|
if err := actions_model.InsertRun(&run, jobs); err != nil {
|
||||||
log.Error("InsertRun: %v", err)
|
log.Error("InsertRun: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if jobs, _, err := bots_model.FindRunJobs(ctx, bots_model.FindRunJobOptions{RunID: run.ID}); err != nil {
|
if jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{RunID: run.ID}); err != nil {
|
||||||
log.Error("FindRunJobs: %v", err)
|
log.Error("FindRunJobs: %v", err)
|
||||||
} else {
|
} else {
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
if err := bots_service.CreateCommitStatus(ctx, job); err != nil {
|
if err := actions_service.CreateCommitStatus(ctx, job); err != nil {
|
||||||
log.Error("CreateCommitStatus: %v", err)
|
log.Error("CreateCommitStatus: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/webhook"
|
"code.gitea.io/gitea/models/webhook"
|
||||||
"code.gitea.io/gitea/modules/actions"
|
"code.gitea.io/gitea/modules/actions"
|
||||||
"code.gitea.io/gitea/modules/json"
|
"code.gitea.io/gitea/modules/json"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
bot_service "code.gitea.io/gitea/services/actions"
|
actions_service "code.gitea.io/gitea/services/actions"
|
||||||
secret_service "code.gitea.io/gitea/services/secrets"
|
secret_service "code.gitea.io/gitea/services/secrets"
|
||||||
|
|
||||||
runnerv1 "code.gitea.io/bots-proto-go/runner/v1"
|
runnerv1 "code.gitea.io/bots-proto-go/runner/v1"
|
||||||
@ -42,7 +42,7 @@ func (s *Service) Register(
|
|||||||
return nil, errors.New("missing runner token, name")
|
return nil, errors.New("missing runner token, name")
|
||||||
}
|
}
|
||||||
|
|
||||||
runnerToken, err := bots_model.GetRunnerToken(req.Msg.Token)
|
runnerToken, err := actions_model.GetRunnerToken(req.Msg.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("runner token not found")
|
return nil, errors.New("runner token not found")
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ func (s *Service) Register(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create new runner
|
// create new runner
|
||||||
runner := &bots_model.BotRunner{
|
runner := &actions_model.BotRunner{
|
||||||
UUID: gouuid.New().String(),
|
UUID: gouuid.New().String(),
|
||||||
Name: req.Msg.Name,
|
Name: req.Msg.Name,
|
||||||
OwnerID: runnerToken.OwnerID,
|
OwnerID: runnerToken.OwnerID,
|
||||||
@ -65,13 +65,13 @@ func (s *Service) Register(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create new runner
|
// create new runner
|
||||||
if err := bots_model.NewRunner(ctx, runner); err != nil {
|
if err := actions_model.NewRunner(ctx, runner); err != nil {
|
||||||
return nil, errors.New("can't create new runner")
|
return nil, errors.New("can't create new runner")
|
||||||
}
|
}
|
||||||
|
|
||||||
// update token status
|
// update token status
|
||||||
runnerToken.IsActive = true
|
runnerToken.IsActive = true
|
||||||
if err := bots_model.UpdateRunnerToken(ctx, runnerToken, "is_active"); err != nil {
|
if err := actions_model.UpdateRunnerToken(ctx, runnerToken, "is_active"); err != nil {
|
||||||
return nil, errors.New("can't update runner token status")
|
return nil, errors.New("can't update runner token status")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ func (s *Service) UpdateTask(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get Task first
|
// Get Task first
|
||||||
task, err := bots_model.GetTaskByID(ctx, req.Msg.State.Id)
|
task, err := actions_model.GetTaskByID(ctx, req.Msg.State.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "can't find the task: %v", err)
|
return nil, status.Errorf(codes.Internal, "can't find the task: %v", err)
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ func (s *Service) UpdateTask(
|
|||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
task, err = bots_model.UpdateTaskByState(req.Msg.State)
|
task, err = actions_model.UpdateTaskByState(req.Msg.State)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "update task: %v", err)
|
return nil, status.Errorf(codes.Internal, "update task: %v", err)
|
||||||
}
|
}
|
||||||
@ -155,13 +155,13 @@ func (s *Service) UpdateTask(
|
|||||||
return nil, status.Errorf(codes.Internal, "load job: %v", err)
|
return nil, status.Errorf(codes.Internal, "load job: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := bot_service.CreateCommitStatus(ctx, task.Job); err != nil {
|
if err := actions_service.CreateCommitStatus(ctx, task.Job); err != nil {
|
||||||
log.Error("Update commit status failed: %v", err)
|
log.Error("Update commit status failed: %v", err)
|
||||||
// go on
|
// go on
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Msg.State.Result != runnerv1.Result_RESULT_UNSPECIFIED {
|
if req.Msg.State.Result != runnerv1.Result_RESULT_UNSPECIFIED {
|
||||||
if err := bot_service.EmitJobsIfReady(task.Job.RunID); err != nil {
|
if err := actions_service.EmitJobsIfReady(task.Job.RunID); err != nil {
|
||||||
log.Error("Emit ready jobs of run %d: %v", task.Job.RunID, err)
|
log.Error("Emit ready jobs of run %d: %v", task.Job.RunID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,7 +181,7 @@ func (s *Service) UpdateLog(
|
|||||||
) (*connect.Response[runnerv1.UpdateLogResponse], error) {
|
) (*connect.Response[runnerv1.UpdateLogResponse], error) {
|
||||||
res := connect.NewResponse(&runnerv1.UpdateLogResponse{})
|
res := connect.NewResponse(&runnerv1.UpdateLogResponse{})
|
||||||
|
|
||||||
task, err := bots_model.GetTaskByID(ctx, req.Msg.TaskId)
|
task, err := actions_model.GetTaskByID(ctx, req.Msg.TaskId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "get task: %v", err)
|
return nil, status.Errorf(codes.Internal, "get task: %v", err)
|
||||||
}
|
}
|
||||||
@ -203,7 +203,7 @@ func (s *Service) UpdateLog(
|
|||||||
}
|
}
|
||||||
task.LogLength += int64(len(rows))
|
task.LogLength += int64(len(rows))
|
||||||
if task.LogIndexes == nil {
|
if task.LogIndexes == nil {
|
||||||
task.LogIndexes = &bots_model.LogIndexes{}
|
task.LogIndexes = &actions_model.LogIndexes{}
|
||||||
}
|
}
|
||||||
for _, n := range ns {
|
for _, n := range ns {
|
||||||
*task.LogIndexes = append(*task.LogIndexes, task.LogSize)
|
*task.LogIndexes = append(*task.LogIndexes, task.LogSize)
|
||||||
@ -221,7 +221,7 @@ func (s *Service) UpdateLog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := bots_model.UpdateTask(ctx, task, "log_indexes", "log_length", "log_size", "log_in_storage"); err != nil {
|
if err := actions_model.UpdateTask(ctx, task, "log_indexes", "log_length", "log_size", "log_in_storage"); err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "update task: %v", err)
|
return nil, status.Errorf(codes.Internal, "update task: %v", err)
|
||||||
}
|
}
|
||||||
if remove != nil {
|
if remove != nil {
|
||||||
@ -231,8 +231,8 @@ func (s *Service) UpdateLog(
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func pickTask(ctx context.Context, runner *bots_model.BotRunner) (*runnerv1.Task, bool, error) {
|
func pickTask(ctx context.Context, runner *actions_model.BotRunner) (*runnerv1.Task, bool, error) {
|
||||||
t, ok, err := bots_model.CreateTaskForRunner(ctx, runner)
|
t, ok, err := actions_model.CreateTaskForRunner(ctx, runner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, fmt.Errorf("CreateTaskForRunner: %w", err)
|
return nil, false, fmt.Errorf("CreateTaskForRunner: %w", err)
|
||||||
}
|
}
|
||||||
@ -249,7 +249,7 @@ func pickTask(ctx context.Context, runner *bots_model.BotRunner) (*runnerv1.Task
|
|||||||
return task, true, nil
|
return task, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSecretsOfTask(ctx context.Context, task *bots_model.BotTask) map[string]string {
|
func getSecretsOfTask(ctx context.Context, task *actions_model.BotTask) map[string]string {
|
||||||
// Returning an error is worse than returning empty secrets.
|
// Returning an error is worse than returning empty secrets.
|
||||||
|
|
||||||
secrets := map[string]string{}
|
secrets := map[string]string{}
|
||||||
@ -289,7 +289,7 @@ func getSecretsOfTask(ctx context.Context, task *bots_model.BotTask) map[string]
|
|||||||
return secrets
|
return secrets
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateTaskContext(t *bots_model.BotTask) *structpb.Struct {
|
func generateTaskContext(t *actions_model.BotTask) *structpb.Struct {
|
||||||
event := map[string]interface{}{}
|
event := map[string]interface{}{}
|
||||||
_ = json.Unmarshal([]byte(t.Job.Run.EventPayload), &event)
|
_ = json.Unmarshal([]byte(t.Job.Run.EventPayload), &event)
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
@ -31,9 +31,9 @@ var WithRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar
|
|||||||
}
|
}
|
||||||
uuid := request.Header().Get(uuidHeaderKey)
|
uuid := request.Header().Get(uuidHeaderKey)
|
||||||
token := request.Header().Get(tokenHeaderKey)
|
token := request.Header().Get(tokenHeaderKey)
|
||||||
runner, err := bots_model.GetRunnerByUUID(uuid)
|
runner, err := actions_model.GetRunnerByUUID(uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(bots_model.ErrRunnerNotExist); ok {
|
if _, ok := err.(actions_model.ErrRunnerNotExist); ok {
|
||||||
return nil, status.Error(codes.Unauthenticated, "unregistered runner")
|
return nil, status.Error(codes.Unauthenticated, "unregistered runner")
|
||||||
}
|
}
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
@ -48,7 +48,7 @@ var WithRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar
|
|||||||
runner.LastActive = timeutil.TimeStampNow()
|
runner.LastActive = timeutil.TimeStampNow()
|
||||||
cols = append(cols, "last_active")
|
cols = append(cols, "last_active")
|
||||||
}
|
}
|
||||||
if err := bots_model.UpdateRunner(ctx, runner, cols...); err != nil {
|
if err := actions_model.UpdateRunner(ctx, runner, cols...); err != nil {
|
||||||
log.Error("can't update runner status: %v", err)
|
log.Error("can't update runner status: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,9 +67,9 @@ func getMethodName(req connect.AnyRequest) string {
|
|||||||
|
|
||||||
type runnerCtxKey struct{}
|
type runnerCtxKey struct{}
|
||||||
|
|
||||||
func GetRunner(ctx context.Context) *bots_model.BotRunner {
|
func GetRunner(ctx context.Context) *actions_model.BotRunner {
|
||||||
if v := ctx.Value(runnerCtxKey{}); v != nil {
|
if v := ctx.Value(runnerCtxKey{}); v != nil {
|
||||||
if r, ok := v.(*bots_model.BotRunner); ok {
|
if r, ok := v.(*actions_model.BotRunner); ok {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/organization"
|
"code.gitea.io/gitea/models/organization"
|
||||||
"code.gitea.io/gitea/models/perm"
|
"code.gitea.io/gitea/models/perm"
|
||||||
access_model "code.gitea.io/gitea/models/perm/access"
|
access_model "code.gitea.io/gitea/models/perm/access"
|
||||||
@ -187,9 +187,9 @@ func repoAssignment() func(ctx *context.APIContext) {
|
|||||||
|
|
||||||
if ctx.Doer != nil && ctx.Doer.ID == user_model.BotUserID {
|
if ctx.Doer != nil && ctx.Doer.ID == user_model.BotUserID {
|
||||||
botTaskID := ctx.Data["BotTaskID"].(int64)
|
botTaskID := ctx.Data["BotTaskID"].(int64)
|
||||||
task, err := bots_model.GetTaskByID(ctx, botTaskID)
|
task, err := actions_model.GetTaskByID(ctx, botTaskID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "bots_model.GetTaskByID", err)
|
ctx.Error(http.StatusInternalServerError, "actions_model.GetTaskByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if task.RepoID != repo.ID {
|
if task.RepoID != repo.ID {
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
@ -18,14 +18,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// RunnersList render common runners list page
|
// RunnersList render common runners list page
|
||||||
func RunnersList(ctx *context.Context, tplName base.TplName, opts bots_model.FindRunnerOptions) {
|
func RunnersList(ctx *context.Context, tplName base.TplName, opts actions_model.FindRunnerOptions) {
|
||||||
count, err := bots_model.CountRunners(opts)
|
count, err := actions_model.CountRunners(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("AdminRunners", err)
|
ctx.ServerError("AdminRunners", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
runners, err := bots_model.FindRunners(opts)
|
runners, err := actions_model.FindRunners(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("AdminRunners", err)
|
ctx.ServerError("AdminRunners", err)
|
||||||
return
|
return
|
||||||
@ -36,10 +36,10 @@ func RunnersList(ctx *context.Context, tplName base.TplName, opts bots_model.Fin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ownid=0,repo_id=0,means this token is used for global
|
// ownid=0,repo_id=0,means this token is used for global
|
||||||
var token *bots_model.BotRunnerToken
|
var token *actions_model.BotRunnerToken
|
||||||
token, err = bots_model.GetUnactivatedRunnerToken(opts.OwnerID, opts.RepoID)
|
token, err = actions_model.GetUnactivatedRunnerToken(opts.OwnerID, opts.RepoID)
|
||||||
if _, ok := err.(bots_model.ErrRunnerTokenNotExist); ok {
|
if _, ok := err.(actions_model.ErrRunnerTokenNotExist); ok {
|
||||||
token, err = bots_model.NewRunnerToken(opts.OwnerID, opts.RepoID)
|
token, err = actions_model.NewRunnerToken(opts.OwnerID, opts.RepoID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CreateRunnerToken", err)
|
ctx.ServerError("CreateRunnerToken", err)
|
||||||
return
|
return
|
||||||
@ -64,7 +64,7 @@ func RunnersList(ctx *context.Context, tplName base.TplName, opts bots_model.Fin
|
|||||||
|
|
||||||
// RunnerDetails render runner details page
|
// RunnerDetails render runner details page
|
||||||
func RunnerDetails(ctx *context.Context, tplName base.TplName, page int, runnerID, ownerID, repoID int64) {
|
func RunnerDetails(ctx *context.Context, tplName base.TplName, page int, runnerID, ownerID, repoID int64) {
|
||||||
runner, err := bots_model.GetRunnerByID(runnerID)
|
runner, err := actions_model.GetRunnerByID(runnerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetRunnerByID", err)
|
ctx.ServerError("GetRunnerByID", err)
|
||||||
return
|
return
|
||||||
@ -81,23 +81,23 @@ func RunnerDetails(ctx *context.Context, tplName base.TplName, page int, runnerI
|
|||||||
|
|
||||||
ctx.Data["Runner"] = runner
|
ctx.Data["Runner"] = runner
|
||||||
|
|
||||||
opts := bots_model.FindTaskOptions{
|
opts := actions_model.FindTaskOptions{
|
||||||
ListOptions: db.ListOptions{
|
ListOptions: db.ListOptions{
|
||||||
Page: page,
|
Page: page,
|
||||||
PageSize: 30,
|
PageSize: 30,
|
||||||
},
|
},
|
||||||
Status: bots_model.StatusUnknown, // Unknown means all
|
Status: actions_model.StatusUnknown, // Unknown means all
|
||||||
IDOrderDesc: true,
|
IDOrderDesc: true,
|
||||||
RunnerID: runner.ID,
|
RunnerID: runner.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := bots_model.CountTasks(ctx, opts)
|
count, err := actions_model.CountTasks(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CountTasks", err)
|
ctx.ServerError("CountTasks", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks, _, err := bots_model.FindTasks(ctx, opts)
|
tasks, _, err := actions_model.FindTasks(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("FindTasks", err)
|
ctx.ServerError("FindTasks", err)
|
||||||
return
|
return
|
||||||
@ -116,7 +116,7 @@ func RunnerDetails(ctx *context.Context, tplName base.TplName, page int, runnerI
|
|||||||
|
|
||||||
// RunnerDetailsEditPost response for edit runner details
|
// RunnerDetailsEditPost response for edit runner details
|
||||||
func RunnerDetailsEditPost(ctx *context.Context, runnerID, ownerID, repoID int64, redirectTo string) {
|
func RunnerDetailsEditPost(ctx *context.Context, runnerID, ownerID, repoID int64, redirectTo string) {
|
||||||
runner, err := bots_model.GetRunnerByID(runnerID)
|
runner, err := actions_model.GetRunnerByID(runnerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("RunnerDetailsEditPost.GetRunnerByID failed: %v, url: %s", err, ctx.Req.URL)
|
log.Warn("RunnerDetailsEditPost.GetRunnerByID failed: %v, url: %s", err, ctx.Req.URL)
|
||||||
ctx.ServerError("RunnerDetailsEditPost.GetRunnerByID", err)
|
ctx.ServerError("RunnerDetailsEditPost.GetRunnerByID", err)
|
||||||
@ -132,7 +132,7 @@ func RunnerDetailsEditPost(ctx *context.Context, runnerID, ownerID, repoID int64
|
|||||||
runner.Description = form.Description
|
runner.Description = form.Description
|
||||||
runner.CustomLabels = strings.Split(form.CustomLabels, ",")
|
runner.CustomLabels = strings.Split(form.CustomLabels, ",")
|
||||||
|
|
||||||
err = bots_model.UpdateRunner(ctx, runner, "description", "custom_labels")
|
err = actions_model.UpdateRunner(ctx, runner, "description", "custom_labels")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("RunnerDetailsEditPost.UpdateRunner failed: %v, url: %s", err, ctx.Req.URL)
|
log.Warn("RunnerDetailsEditPost.UpdateRunner failed: %v, url: %s", err, ctx.Req.URL)
|
||||||
ctx.Flash.Warning(ctx.Tr("admin.runners.update_runner_failed"))
|
ctx.Flash.Warning(ctx.Tr("admin.runners.update_runner_failed"))
|
||||||
@ -148,7 +148,7 @@ func RunnerDetailsEditPost(ctx *context.Context, runnerID, ownerID, repoID int64
|
|||||||
|
|
||||||
// RunnerResetRegistrationToken reset registration token
|
// RunnerResetRegistrationToken reset registration token
|
||||||
func RunnerResetRegistrationToken(ctx *context.Context, ownerID, repoID int64, redirectTo string) {
|
func RunnerResetRegistrationToken(ctx *context.Context, ownerID, repoID int64, redirectTo string) {
|
||||||
_, err := bots_model.NewRunnerToken(ownerID, repoID)
|
_, err := actions_model.NewRunnerToken(ownerID, repoID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("ResetRunnerRegistrationToken", err)
|
ctx.ServerError("ResetRunnerRegistrationToken", err)
|
||||||
return
|
return
|
||||||
@ -162,14 +162,14 @@ func RunnerResetRegistrationToken(ctx *context.Context, ownerID, repoID int64, r
|
|||||||
func RunnerDeletePost(ctx *context.Context, runnerID int64,
|
func RunnerDeletePost(ctx *context.Context, runnerID int64,
|
||||||
successRedirectTo, failedRedirectTo string,
|
successRedirectTo, failedRedirectTo string,
|
||||||
) {
|
) {
|
||||||
runner, err := bots_model.GetRunnerByID(runnerID)
|
runner, err := actions_model.GetRunnerByID(runnerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("DeleteRunnerPost.GetRunnerByID failed: %v, url: %s", err, ctx.Req.URL)
|
log.Warn("DeleteRunnerPost.GetRunnerByID failed: %v, url: %s", err, ctx.Req.URL)
|
||||||
ctx.ServerError("DeleteRunnerPost.GetRunnerByID", err)
|
ctx.ServerError("DeleteRunnerPost.GetRunnerByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bots_model.DeleteRunner(ctx, runner)
|
err = actions_model.DeleteRunner(ctx, runner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("DeleteRunnerPost.UpdateRunner failed: %v, url: %s", err, ctx.Req.URL)
|
log.Warn("DeleteRunnerPost.UpdateRunner failed: %v, url: %s", err, ctx.Req.URL)
|
||||||
ctx.Flash.Warning(ctx.Tr("runners.delete_runner_failed"))
|
ctx.Flash.Warning(ctx.Tr("runners.delete_runner_failed"))
|
||||||
|
@ -30,13 +30,13 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/translation"
|
"code.gitea.io/gitea/modules/translation"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
bots_router "code.gitea.io/gitea/routers/api/actions"
|
actions_router "code.gitea.io/gitea/routers/api/actions"
|
||||||
packages_router "code.gitea.io/gitea/routers/api/packages"
|
packages_router "code.gitea.io/gitea/routers/api/packages"
|
||||||
apiv1 "code.gitea.io/gitea/routers/api/v1"
|
apiv1 "code.gitea.io/gitea/routers/api/v1"
|
||||||
"code.gitea.io/gitea/routers/common"
|
"code.gitea.io/gitea/routers/common"
|
||||||
"code.gitea.io/gitea/routers/private"
|
"code.gitea.io/gitea/routers/private"
|
||||||
web_routers "code.gitea.io/gitea/routers/web"
|
web_routers "code.gitea.io/gitea/routers/web"
|
||||||
bot_service "code.gitea.io/gitea/services/actions"
|
actions_service "code.gitea.io/gitea/services/actions"
|
||||||
"code.gitea.io/gitea/services/auth"
|
"code.gitea.io/gitea/services/auth"
|
||||||
"code.gitea.io/gitea/services/auth/source/oauth2"
|
"code.gitea.io/gitea/services/auth/source/oauth2"
|
||||||
"code.gitea.io/gitea/services/automerge"
|
"code.gitea.io/gitea/services/automerge"
|
||||||
@ -174,7 +174,7 @@ func GlobalInitInstalled(ctx context.Context) {
|
|||||||
auth.Init()
|
auth.Init()
|
||||||
svg.Init()
|
svg.Init()
|
||||||
|
|
||||||
bot_service.Init()
|
actions_service.Init()
|
||||||
|
|
||||||
// Finally start up the cron
|
// Finally start up the cron
|
||||||
cron.NewContext(ctx)
|
cron.NewContext(ctx)
|
||||||
@ -204,7 +204,7 @@ func NormalRoutes(ctx context.Context) *web.Route {
|
|||||||
|
|
||||||
if setting.Bots.Enabled {
|
if setting.Bots.Enabled {
|
||||||
prefix := "/api/bots"
|
prefix := "/api/bots"
|
||||||
r.Mount(prefix, bots_router.Routes(ctx, prefix))
|
r.Mount(prefix, actions_router.Routes(ctx, prefix))
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
@ -7,7 +7,7 @@ package admin
|
|||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
@ -31,7 +31,7 @@ func Runners(ctx *context.Context) {
|
|||||||
page = 1
|
page = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := bots_model.FindRunnerOptions{
|
opts := actions_model.FindRunnerOptions{
|
||||||
ListOptions: db.ListOptions{
|
ListOptions: db.ListOptions{
|
||||||
Page: page,
|
Page: page,
|
||||||
PageSize: 100,
|
PageSize: 100,
|
||||||
|
@ -6,7 +6,7 @@ package org
|
|||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/routers/common"
|
"code.gitea.io/gitea/routers/common"
|
||||||
@ -23,7 +23,7 @@ func Runners(ctx *context.Context) {
|
|||||||
page = 1
|
page = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := bots_model.FindRunnerOptions{
|
opts := actions_model.FindRunnerOptions{
|
||||||
ListOptions: db.ListOptions{
|
ListOptions: db.ListOptions{
|
||||||
Page: page,
|
Page: page,
|
||||||
PageSize: 100,
|
PageSize: 100,
|
||||||
|
@ -6,7 +6,7 @@ package actions
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/unit"
|
"code.gitea.io/gitea/models/unit"
|
||||||
"code.gitea.io/gitea/modules/actions"
|
"code.gitea.io/gitea/modules/actions"
|
||||||
@ -74,7 +74,7 @@ func List(ctx *context.Context) {
|
|||||||
workflow := ctx.FormString("workflow")
|
workflow := ctx.FormString("workflow")
|
||||||
ctx.Data["CurWorkflow"] = workflow
|
ctx.Data["CurWorkflow"] = workflow
|
||||||
|
|
||||||
opts := bots_model.FindRunOptions{
|
opts := actions_model.FindRunOptions{
|
||||||
ListOptions: db.ListOptions{
|
ListOptions: db.ListOptions{
|
||||||
Page: page,
|
Page: page,
|
||||||
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
|
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
|
||||||
@ -85,7 +85,7 @@ func List(ctx *context.Context) {
|
|||||||
|
|
||||||
// open counts
|
// open counts
|
||||||
opts.IsClosed = util.OptionalBoolFalse
|
opts.IsClosed = util.OptionalBoolFalse
|
||||||
numOpenRuns, err := bots_model.CountRuns(ctx, opts)
|
numOpenRuns, err := actions_model.CountRuns(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
@ -94,7 +94,7 @@ func List(ctx *context.Context) {
|
|||||||
|
|
||||||
// closed counts
|
// closed counts
|
||||||
opts.IsClosed = util.OptionalBoolTrue
|
opts.IsClosed = util.OptionalBoolTrue
|
||||||
numClosedRuns, err := bots_model.CountRuns(ctx, opts)
|
numClosedRuns, err := actions_model.CountRuns(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
@ -108,7 +108,7 @@ func List(ctx *context.Context) {
|
|||||||
} else {
|
} else {
|
||||||
opts.IsClosed = util.OptionalBoolFalse
|
opts.IsClosed = util.OptionalBoolFalse
|
||||||
}
|
}
|
||||||
runs, total, err := bots_model.FindRuns(ctx, opts)
|
runs, total, err := actions_model.FindRuns(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
|
@ -9,13 +9,13 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/actions"
|
"code.gitea.io/gitea/modules/actions"
|
||||||
context_module "code.gitea.io/gitea/modules/context"
|
context_module "code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
bots_service "code.gitea.io/gitea/services/actions"
|
actions_service "code.gitea.io/gitea/services/actions"
|
||||||
|
|
||||||
runnerv1 "code.gitea.io/bots-proto-go/runner/v1"
|
runnerv1 "code.gitea.io/bots-proto-go/runner/v1"
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
@ -125,10 +125,10 @@ func ViewPost(ctx *context_module.Context) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var task *bots_model.BotTask
|
var task *actions_model.BotTask
|
||||||
if current.TaskID > 0 {
|
if current.TaskID > 0 {
|
||||||
var err error
|
var err error
|
||||||
task, err = bots_model.GetTaskByID(ctx, current.TaskID)
|
task, err = actions_model.GetTaskByID(ctx, current.TaskID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
@ -206,15 +206,15 @@ func Rerun(ctx *context_module.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
job.TaskID = 0
|
job.TaskID = 0
|
||||||
job.Status = bots_model.StatusWaiting
|
job.Status = actions_model.StatusWaiting
|
||||||
job.Started = 0
|
job.Started = 0
|
||||||
job.Stopped = 0
|
job.Stopped = 0
|
||||||
|
|
||||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
if _, err := bots_model.UpdateRunJob(ctx, job, builder.Eq{"status": status}, "task_id", "status", "started", "stopped"); err != nil {
|
if _, err := actions_model.UpdateRunJob(ctx, job, builder.Eq{"status": status}, "task_id", "status", "started", "stopped"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return bots_service.CreateCommitStatus(ctx, job)
|
return actions_service.CreateCommitStatus(ctx, job)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
@ -238,9 +238,9 @@ func Cancel(ctx *context_module.Context) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if job.TaskID == 0 {
|
if job.TaskID == 0 {
|
||||||
job.Status = bots_model.StatusCancelled
|
job.Status = actions_model.StatusCancelled
|
||||||
job.Stopped = timeutil.TimeStampNow()
|
job.Stopped = timeutil.TimeStampNow()
|
||||||
n, err := bots_model.UpdateRunJob(ctx, job, builder.Eq{"task_id": 0}, "status", "stopped")
|
n, err := actions_model.UpdateRunJob(ctx, job, builder.Eq{"task_id": 0}, "status", "stopped")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -249,10 +249,10 @@ func Cancel(ctx *context_module.Context) {
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := bots_model.StopTask(ctx, job.TaskID, bots_model.StatusCancelled); err != nil {
|
if err := actions_model.StopTask(ctx, job.TaskID, actions_model.StatusCancelled); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := bots_service.CreateCommitStatus(ctx, job); err != nil {
|
if err := actions_service.CreateCommitStatus(ctx, job); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -268,10 +268,10 @@ func Cancel(ctx *context_module.Context) {
|
|||||||
// getRunJobs gets the jobs of runIndex, and returns jobs[jobIndex], jobs.
|
// getRunJobs gets the jobs of runIndex, and returns jobs[jobIndex], jobs.
|
||||||
// Any error will be written to the ctx.
|
// Any error will be written to the ctx.
|
||||||
// It never returns a nil job of an empty jobs, if the jobIndex is out of range, it will be treated as 0.
|
// It never returns a nil job of an empty jobs, if the jobIndex is out of range, it will be treated as 0.
|
||||||
func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*bots_model.BotRunJob, []*bots_model.BotRunJob) {
|
func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*actions_model.BotRunJob, []*actions_model.BotRunJob) {
|
||||||
run, err := bots_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex)
|
run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(bots_model.ErrRunNotExist); ok {
|
if _, ok := err.(actions_model.ErrRunNotExist); ok {
|
||||||
ctx.Error(http.StatusNotFound, err.Error())
|
ctx.Error(http.StatusNotFound, err.Error())
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*bots_mo
|
|||||||
}
|
}
|
||||||
run.Repo = ctx.Repo.Repository
|
run.Repo = ctx.Repo.Repository
|
||||||
|
|
||||||
jobs, err := bots_model.GetRunJobsByRunID(ctx, run.ID)
|
jobs, err := actions_model.GetRunJobsByRunID(ctx, run.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/auth"
|
"code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/models/perm"
|
"code.gitea.io/gitea/models/perm"
|
||||||
access_model "code.gitea.io/gitea/models/perm/access"
|
access_model "code.gitea.io/gitea/models/perm/access"
|
||||||
@ -189,7 +189,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
|||||||
|
|
||||||
if ctx.Data["IsBotToken"] == true {
|
if ctx.Data["IsBotToken"] == true {
|
||||||
taskID := ctx.Data["BotTaskID"].(int64)
|
taskID := ctx.Data["BotTaskID"].(int64)
|
||||||
task, err := bots_model.GetTaskByID(ctx, taskID)
|
task, err := actions_model.GetTaskByID(ctx, taskID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetTaskByID", err)
|
ctx.ServerError("GetTaskByID", err)
|
||||||
return
|
return
|
||||||
|
@ -6,7 +6,7 @@ package repo
|
|||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/routers/common"
|
"code.gitea.io/gitea/routers/common"
|
||||||
@ -27,7 +27,7 @@ func Runners(ctx *context.Context) {
|
|||||||
page = 1
|
page = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := bots_model.FindRunnerOptions{
|
opts := actions_model.FindRunnerOptions{
|
||||||
ListOptions: db.ListOptions{
|
ListOptions: db.ListOptions{
|
||||||
Page: page,
|
Page: page,
|
||||||
PageSize: 100,
|
PageSize: 100,
|
||||||
|
@ -7,13 +7,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
git_model "code.gitea.io/gitea/models/git"
|
git_model "code.gitea.io/gitea/models/git"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/models/webhook"
|
"code.gitea.io/gitea/models/webhook"
|
||||||
bots_module "code.gitea.io/gitea/modules/actions"
|
actions_module "code.gitea.io/gitea/modules/actions"
|
||||||
"code.gitea.io/gitea/modules/graceful"
|
"code.gitea.io/gitea/modules/graceful"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/queue"
|
"code.gitea.io/gitea/modules/queue"
|
||||||
@ -26,26 +26,26 @@ func Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DeleteResourceOfRepository(ctx context.Context, repo *repo_model.Repository) error {
|
func DeleteResourceOfRepository(ctx context.Context, repo *repo_model.Repository) error {
|
||||||
tasks, _, err := bots_model.FindTasks(ctx, bots_model.FindTaskOptions{RepoID: repo.ID})
|
tasks, _, err := actions_model.FindTasks(ctx, actions_model.FindTaskOptions{RepoID: repo.ID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("find task of repo %v: %w", repo.ID, err)
|
return fmt.Errorf("find task of repo %v: %w", repo.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
e := db.GetEngine(ctx)
|
e := db.GetEngine(ctx)
|
||||||
if _, err := e.Delete(&bots_model.BotTaskStep{RepoID: repo.ID}); err != nil {
|
if _, err := e.Delete(&actions_model.BotTaskStep{RepoID: repo.ID}); err != nil {
|
||||||
return fmt.Errorf("delete bots task steps of repo %d: %w", repo.ID, err)
|
return fmt.Errorf("delete bots task steps of repo %d: %w", repo.ID, err)
|
||||||
}
|
}
|
||||||
if _, err := e.Delete(&bots_model.BotTask{RepoID: repo.ID}); err != nil {
|
if _, err := e.Delete(&actions_model.BotTask{RepoID: repo.ID}); err != nil {
|
||||||
return fmt.Errorf("delete bots tasks of repo %d: %w", repo.ID, err)
|
return fmt.Errorf("delete bots tasks of repo %d: %w", repo.ID, err)
|
||||||
}
|
}
|
||||||
if _, err := e.Delete(&bots_model.BotRunJob{RepoID: repo.ID}); err != nil {
|
if _, err := e.Delete(&actions_model.BotRunJob{RepoID: repo.ID}); err != nil {
|
||||||
return fmt.Errorf("delete bots run jobs of repo %d: %w", repo.ID, err)
|
return fmt.Errorf("delete bots run jobs of repo %d: %w", repo.ID, err)
|
||||||
}
|
}
|
||||||
if _, err := e.Delete(&bots_model.BotRun{RepoID: repo.ID}); err != nil {
|
if _, err := e.Delete(&actions_model.BotRun{RepoID: repo.ID}); err != nil {
|
||||||
return fmt.Errorf("delete bots runs of repo %d: %w", repo.ID, err)
|
return fmt.Errorf("delete bots runs of repo %d: %w", repo.ID, err)
|
||||||
}
|
}
|
||||||
if _, err := e.Delete(&bots_model.BotRunner{RepoID: repo.ID}); err != nil {
|
if _, err := e.Delete(&actions_model.BotRunner{RepoID: repo.ID}); err != nil {
|
||||||
return fmt.Errorf("delete bots runner of repo %d: %w", repo.ID, err)
|
return fmt.Errorf("delete bots runner of repo %d: %w", repo.ID, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -55,7 +55,7 @@ func DeleteResourceOfRepository(ctx context.Context, repo *repo_model.Repository
|
|||||||
|
|
||||||
// remove logs file after tasks have been deleted, to avoid new log files
|
// remove logs file after tasks have been deleted, to avoid new log files
|
||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
err := bots_module.RemoveLogs(ctx, task.LogInStorage, task.LogFilename)
|
err := actions_module.RemoveLogs(ctx, task.LogInStorage, task.LogFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("remove log file %q: %v", task.LogFilename, err)
|
log.Error("remove log file %q: %v", task.LogFilename, err)
|
||||||
// go on
|
// go on
|
||||||
@ -65,7 +65,7 @@ func DeleteResourceOfRepository(ctx context.Context, repo *repo_model.Repository
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateCommitStatus(ctx context.Context, job *bots_model.BotRunJob) error {
|
func CreateCommitStatus(ctx context.Context, job *actions_model.BotRunJob) error {
|
||||||
if err := job.LoadAttributes(ctx); err != nil {
|
if err := job.LoadAttributes(ctx); err != nil {
|
||||||
return fmt.Errorf("load run: %w", err)
|
return fmt.Errorf("load run: %w", err)
|
||||||
}
|
}
|
||||||
@ -122,15 +122,15 @@ func CreateCommitStatus(ctx context.Context, job *bots_model.BotRunJob) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func toCommitStatus(status bots_model.Status) api.CommitStatusState {
|
func toCommitStatus(status actions_model.Status) api.CommitStatusState {
|
||||||
switch status {
|
switch status {
|
||||||
case bots_model.StatusSuccess:
|
case actions_model.StatusSuccess:
|
||||||
return api.CommitStatusSuccess
|
return api.CommitStatusSuccess
|
||||||
case bots_model.StatusFailure, bots_model.StatusCancelled, bots_model.StatusSkipped:
|
case actions_model.StatusFailure, actions_model.StatusCancelled, actions_model.StatusSkipped:
|
||||||
return api.CommitStatusFailure
|
return api.CommitStatusFailure
|
||||||
case bots_model.StatusWaiting, bots_model.StatusBlocked:
|
case actions_model.StatusWaiting, actions_model.StatusBlocked:
|
||||||
return api.CommitStatusPending
|
return api.CommitStatusPending
|
||||||
case bots_model.StatusRunning:
|
case actions_model.StatusRunning:
|
||||||
return api.CommitStatusRunning
|
return api.CommitStatusRunning
|
||||||
default:
|
default:
|
||||||
return api.CommitStatusError
|
return api.CommitStatusError
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
@ -21,8 +21,8 @@ const (
|
|||||||
|
|
||||||
// StopZombieTasks stops the task which have running status, but haven't been updated for a long time
|
// StopZombieTasks stops the task which have running status, but haven't been updated for a long time
|
||||||
func StopZombieTasks(ctx context.Context) error {
|
func StopZombieTasks(ctx context.Context) error {
|
||||||
tasks, _, err := bots_model.FindTasks(ctx, bots_model.FindTaskOptions{
|
tasks, _, err := actions_model.FindTasks(ctx, actions_model.FindTaskOptions{
|
||||||
Status: bots_model.StatusRunning,
|
Status: actions_model.StatusRunning,
|
||||||
UpdatedBefore: timeutil.TimeStamp(time.Now().Add(-zombieTaskTimeout).Unix()),
|
UpdatedBefore: timeutil.TimeStamp(time.Now().Add(-zombieTaskTimeout).Unix()),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -32,7 +32,7 @@ func StopZombieTasks(ctx context.Context) error {
|
|||||||
|
|
||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
if err := bots_model.StopTask(ctx, task.ID, bots_model.StatusFailure); err != nil {
|
if err := actions_model.StopTask(ctx, task.ID, actions_model.StatusFailure); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := task.LoadJob(ctx); err != nil {
|
if err := task.LoadJob(ctx); err != nil {
|
||||||
@ -49,8 +49,8 @@ func StopZombieTasks(ctx context.Context) error {
|
|||||||
|
|
||||||
// StopEndlessTasks stops the tasks which have running status and continuous updates, but don't end for a long time
|
// StopEndlessTasks stops the tasks which have running status and continuous updates, but don't end for a long time
|
||||||
func StopEndlessTasks(ctx context.Context) error {
|
func StopEndlessTasks(ctx context.Context) error {
|
||||||
tasks, _, err := bots_model.FindTasks(ctx, bots_model.FindTaskOptions{
|
tasks, _, err := actions_model.FindTasks(ctx, actions_model.FindTaskOptions{
|
||||||
Status: bots_model.StatusRunning,
|
Status: actions_model.StatusRunning,
|
||||||
StartedBefore: timeutil.TimeStamp(time.Now().Add(-endlessTaskTimeout).Unix()),
|
StartedBefore: timeutil.TimeStamp(time.Now().Add(-endlessTaskTimeout).Unix()),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -60,7 +60,7 @@ func StopEndlessTasks(ctx context.Context) error {
|
|||||||
|
|
||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
if err := bots_model.StopTask(ctx, task.ID, bots_model.StatusFailure); err != nil {
|
if err := actions_model.StopTask(ctx, task.ID, actions_model.StatusFailure); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := task.LoadJob(ctx); err != nil {
|
if err := task.LoadJob(ctx); err != nil {
|
||||||
@ -77,8 +77,8 @@ func StopEndlessTasks(ctx context.Context) error {
|
|||||||
|
|
||||||
// CancelAbandonedJobs cancels the jobs which have waiting status, but haven't been picked by a runner for a long time
|
// CancelAbandonedJobs cancels the jobs which have waiting status, but haven't been picked by a runner for a long time
|
||||||
func CancelAbandonedJobs(ctx context.Context) error {
|
func CancelAbandonedJobs(ctx context.Context) error {
|
||||||
jobs, _, err := bots_model.FindRunJobs(ctx, bots_model.FindRunJobOptions{
|
jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{
|
||||||
Statuses: []bots_model.Status{bots_model.StatusWaiting, bots_model.StatusBlocked},
|
Statuses: []actions_model.Status{actions_model.StatusWaiting, actions_model.StatusBlocked},
|
||||||
UpdatedBefore: timeutil.TimeStamp(time.Now().Add(-abandonedJobTimeout).Unix()),
|
UpdatedBefore: timeutil.TimeStamp(time.Now().Add(-abandonedJobTimeout).Unix()),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -88,10 +88,10 @@ func CancelAbandonedJobs(ctx context.Context) error {
|
|||||||
|
|
||||||
now := timeutil.TimeStampNow()
|
now := timeutil.TimeStampNow()
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
job.Status = bots_model.StatusCancelled
|
job.Status = actions_model.StatusCancelled
|
||||||
job.Stopped = now
|
job.Stopped = now
|
||||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
if _, err := bots_model.UpdateRunJob(ctx, job, nil, "status", "stopped"); err != nil {
|
if _, err := actions_model.UpdateRunJob(ctx, job, nil, "status", "stopped"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return CreateCommitStatus(ctx, job)
|
return CreateCommitStatus(ctx, job)
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/graceful"
|
"code.gitea.io/gitea/modules/graceful"
|
||||||
"code.gitea.io/gitea/modules/queue"
|
"code.gitea.io/gitea/modules/queue"
|
||||||
@ -46,11 +46,11 @@ func jobEmitterQueueHandle(data ...queue.Data) []queue.Data {
|
|||||||
|
|
||||||
func checkJobsOfRun(ctx context.Context, runID int64) error {
|
func checkJobsOfRun(ctx context.Context, runID int64) error {
|
||||||
return db.WithTx(ctx, func(ctx context.Context) error {
|
return db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
jobs, _, err := bots_model.FindRunJobs(ctx, bots_model.FindRunJobOptions{RunID: runID})
|
jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{RunID: runID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
idToJobs := make(map[string][]*bots_model.BotRunJob, len(jobs))
|
idToJobs := make(map[string][]*actions_model.BotRunJob, len(jobs))
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
idToJobs[job.JobID] = append(idToJobs[job.JobID], job)
|
idToJobs[job.JobID] = append(idToJobs[job.JobID], job)
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ func checkJobsOfRun(ctx context.Context, runID int64) error {
|
|||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
if status, ok := updates[job.ID]; ok {
|
if status, ok := updates[job.ID]; ok {
|
||||||
job.Status = status
|
job.Status = status
|
||||||
if n, err := bots_model.UpdateRunJob(ctx, job, builder.Eq{"status": bots_model.StatusBlocked}, "status"); err != nil {
|
if n, err := actions_model.UpdateRunJob(ctx, job, builder.Eq{"status": actions_model.StatusBlocked}, "status"); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if n != 1 {
|
} else if n != 1 {
|
||||||
return fmt.Errorf("no affected for updating blocked job %v", job.ID)
|
return fmt.Errorf("no affected for updating blocked job %v", job.ID)
|
||||||
@ -71,17 +71,17 @@ func checkJobsOfRun(ctx context.Context, runID int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type jobStatusResolver struct {
|
type jobStatusResolver struct {
|
||||||
statuses map[int64]bots_model.Status
|
statuses map[int64]actions_model.Status
|
||||||
needs map[int64][]int64
|
needs map[int64][]int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func newJobStatusResolver(jobs bots_model.RunJobList) *jobStatusResolver {
|
func newJobStatusResolver(jobs actions_model.RunJobList) *jobStatusResolver {
|
||||||
idToJobs := make(map[string][]*bots_model.BotRunJob, len(jobs))
|
idToJobs := make(map[string][]*actions_model.BotRunJob, len(jobs))
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
idToJobs[job.JobID] = append(idToJobs[job.JobID], job)
|
idToJobs[job.JobID] = append(idToJobs[job.JobID], job)
|
||||||
}
|
}
|
||||||
|
|
||||||
statuses := make(map[int64]bots_model.Status, len(jobs))
|
statuses := make(map[int64]actions_model.Status, len(jobs))
|
||||||
needs := make(map[int64][]int64, len(jobs))
|
needs := make(map[int64][]int64, len(jobs))
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
statuses[job.ID] = job.Status
|
statuses[job.ID] = job.Status
|
||||||
@ -97,8 +97,8 @@ func newJobStatusResolver(jobs bots_model.RunJobList) *jobStatusResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *jobStatusResolver) Resolve() map[int64]bots_model.Status {
|
func (r *jobStatusResolver) Resolve() map[int64]actions_model.Status {
|
||||||
ret := map[int64]bots_model.Status{}
|
ret := map[int64]actions_model.Status{}
|
||||||
for i := 0; i < len(r.statuses); i++ {
|
for i := 0; i < len(r.statuses); i++ {
|
||||||
updated := r.resolve()
|
updated := r.resolve()
|
||||||
if len(updated) == 0 {
|
if len(updated) == 0 {
|
||||||
@ -112,10 +112,10 @@ func (r *jobStatusResolver) Resolve() map[int64]bots_model.Status {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *jobStatusResolver) resolve() map[int64]bots_model.Status {
|
func (r *jobStatusResolver) resolve() map[int64]actions_model.Status {
|
||||||
ret := map[int64]bots_model.Status{}
|
ret := map[int64]actions_model.Status{}
|
||||||
for id, status := range r.statuses {
|
for id, status := range r.statuses {
|
||||||
if status != bots_model.StatusBlocked {
|
if status != actions_model.StatusBlocked {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
allDone, allSucceed := true, true
|
allDone, allSucceed := true, true
|
||||||
@ -124,15 +124,15 @@ func (r *jobStatusResolver) resolve() map[int64]bots_model.Status {
|
|||||||
if !needStatus.IsDone() {
|
if !needStatus.IsDone() {
|
||||||
allDone = false
|
allDone = false
|
||||||
}
|
}
|
||||||
if needStatus.In(bots_model.StatusFailure, bots_model.StatusCancelled, bots_model.StatusSkipped) {
|
if needStatus.In(actions_model.StatusFailure, actions_model.StatusCancelled, actions_model.StatusSkipped) {
|
||||||
allSucceed = false
|
allSucceed = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if allDone {
|
if allDone {
|
||||||
if allSucceed {
|
if allSucceed {
|
||||||
ret[id] = bots_model.StatusWaiting
|
ret[id] = actions_model.StatusWaiting
|
||||||
} else {
|
} else {
|
||||||
ret[id] = bots_model.StatusSkipped
|
ret[id] = actions_model.StatusSkipped
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ package actions
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@ -14,61 +14,61 @@ import (
|
|||||||
func Test_jobStatusResolver_Resolve(t *testing.T) {
|
func Test_jobStatusResolver_Resolve(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
jobs bots_model.RunJobList
|
jobs actions_model.RunJobList
|
||||||
want map[int64]bots_model.Status
|
want map[int64]actions_model.Status
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "no blocked",
|
name: "no blocked",
|
||||||
jobs: bots_model.RunJobList{
|
jobs: actions_model.RunJobList{
|
||||||
{ID: 1, JobID: "1", Status: bots_model.StatusWaiting, Needs: []string{}},
|
{ID: 1, JobID: "1", Status: actions_model.StatusWaiting, Needs: []string{}},
|
||||||
{ID: 2, JobID: "2", Status: bots_model.StatusWaiting, Needs: []string{}},
|
{ID: 2, JobID: "2", Status: actions_model.StatusWaiting, Needs: []string{}},
|
||||||
{ID: 3, JobID: "3", Status: bots_model.StatusWaiting, Needs: []string{}},
|
{ID: 3, JobID: "3", Status: actions_model.StatusWaiting, Needs: []string{}},
|
||||||
},
|
},
|
||||||
want: map[int64]bots_model.Status{},
|
want: map[int64]actions_model.Status{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "single blocked",
|
name: "single blocked",
|
||||||
jobs: bots_model.RunJobList{
|
jobs: actions_model.RunJobList{
|
||||||
{ID: 1, JobID: "1", Status: bots_model.StatusSuccess, Needs: []string{}},
|
{ID: 1, JobID: "1", Status: actions_model.StatusSuccess, Needs: []string{}},
|
||||||
{ID: 2, JobID: "2", Status: bots_model.StatusBlocked, Needs: []string{"1"}},
|
{ID: 2, JobID: "2", Status: actions_model.StatusBlocked, Needs: []string{"1"}},
|
||||||
{ID: 3, JobID: "3", Status: bots_model.StatusWaiting, Needs: []string{}},
|
{ID: 3, JobID: "3", Status: actions_model.StatusWaiting, Needs: []string{}},
|
||||||
},
|
},
|
||||||
want: map[int64]bots_model.Status{
|
want: map[int64]actions_model.Status{
|
||||||
2: bots_model.StatusWaiting,
|
2: actions_model.StatusWaiting,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multiple blocked",
|
name: "multiple blocked",
|
||||||
jobs: bots_model.RunJobList{
|
jobs: actions_model.RunJobList{
|
||||||
{ID: 1, JobID: "1", Status: bots_model.StatusSuccess, Needs: []string{}},
|
{ID: 1, JobID: "1", Status: actions_model.StatusSuccess, Needs: []string{}},
|
||||||
{ID: 2, JobID: "2", Status: bots_model.StatusBlocked, Needs: []string{"1"}},
|
{ID: 2, JobID: "2", Status: actions_model.StatusBlocked, Needs: []string{"1"}},
|
||||||
{ID: 3, JobID: "3", Status: bots_model.StatusBlocked, Needs: []string{"1"}},
|
{ID: 3, JobID: "3", Status: actions_model.StatusBlocked, Needs: []string{"1"}},
|
||||||
},
|
},
|
||||||
want: map[int64]bots_model.Status{
|
want: map[int64]actions_model.Status{
|
||||||
2: bots_model.StatusWaiting,
|
2: actions_model.StatusWaiting,
|
||||||
3: bots_model.StatusWaiting,
|
3: actions_model.StatusWaiting,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "chain blocked",
|
name: "chain blocked",
|
||||||
jobs: bots_model.RunJobList{
|
jobs: actions_model.RunJobList{
|
||||||
{ID: 1, JobID: "1", Status: bots_model.StatusFailure, Needs: []string{}},
|
{ID: 1, JobID: "1", Status: actions_model.StatusFailure, Needs: []string{}},
|
||||||
{ID: 2, JobID: "2", Status: bots_model.StatusBlocked, Needs: []string{"1"}},
|
{ID: 2, JobID: "2", Status: actions_model.StatusBlocked, Needs: []string{"1"}},
|
||||||
{ID: 3, JobID: "3", Status: bots_model.StatusBlocked, Needs: []string{"2"}},
|
{ID: 3, JobID: "3", Status: actions_model.StatusBlocked, Needs: []string{"2"}},
|
||||||
},
|
},
|
||||||
want: map[int64]bots_model.Status{
|
want: map[int64]actions_model.Status{
|
||||||
2: bots_model.StatusSkipped,
|
2: actions_model.StatusSkipped,
|
||||||
3: bots_model.StatusSkipped,
|
3: actions_model.StatusSkipped,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "loop need",
|
name: "loop need",
|
||||||
jobs: bots_model.RunJobList{
|
jobs: actions_model.RunJobList{
|
||||||
{ID: 1, JobID: "1", Status: bots_model.StatusBlocked, Needs: []string{"3"}},
|
{ID: 1, JobID: "1", Status: actions_model.StatusBlocked, Needs: []string{"3"}},
|
||||||
{ID: 2, JobID: "2", Status: bots_model.StatusBlocked, Needs: []string{"1"}},
|
{ID: 2, JobID: "2", Status: actions_model.StatusBlocked, Needs: []string{"1"}},
|
||||||
{ID: 3, JobID: "3", Status: bots_model.StatusBlocked, Needs: []string{"2"}},
|
{ID: 3, JobID: "3", Status: actions_model.StatusBlocked, Needs: []string{"2"}},
|
||||||
},
|
},
|
||||||
want: map[int64]bots_model.Status{},
|
want: map[int64]actions_model.Status{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
@ -109,7 +109,7 @@ func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check task token
|
// check task token
|
||||||
task, err := bots_model.GetRunningTaskByToken(db.DefaultContext, authToken)
|
task, err := actions_model.GetRunningTaskByToken(db.DefaultContext, authToken)
|
||||||
if err == nil && task != nil {
|
if err == nil && task != nil {
|
||||||
log.Trace("Basic Authorization: Valid AccessToken for task[%d]", task.ID)
|
log.Trace("Basic Authorization: Valid AccessToken for task[%d]", task.ID)
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
bots_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
@ -94,7 +94,7 @@ func (o *OAuth2) userIDFromToken(req *http.Request, store DataStore) int64 {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if auth_model.IsErrAccessTokenNotExist(err) {
|
if auth_model.IsErrAccessTokenNotExist(err) {
|
||||||
// check task token
|
// check task token
|
||||||
task, err := bots_model.GetRunningTaskByToken(db.DefaultContext, tokenSHA)
|
task, err := actions_model.GetRunningTaskByToken(db.DefaultContext, tokenSHA)
|
||||||
if err == nil && task != nil {
|
if err == nil && task != nil {
|
||||||
log.Trace("Basic Authorization: Valid AccessToken for task[%d]", task.ID)
|
log.Trace("Basic Authorization: Valid AccessToken for task[%d]", task.ID)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
bots_service "code.gitea.io/gitea/services/actions"
|
actions_service "code.gitea.io/gitea/services/actions"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initBotsTasks() {
|
func initBotsTasks() {
|
||||||
@ -22,7 +22,7 @@ func registerStopZombieTasks() {
|
|||||||
RunAtStart: true,
|
RunAtStart: true,
|
||||||
Schedule: "@every 5m",
|
Schedule: "@every 5m",
|
||||||
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
|
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
|
||||||
return bots_service.StopZombieTasks(ctx)
|
return actions_service.StopZombieTasks(ctx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ func registerStopEndlessTasks() {
|
|||||||
RunAtStart: true,
|
RunAtStart: true,
|
||||||
Schedule: "@every 30m",
|
Schedule: "@every 30m",
|
||||||
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
|
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
|
||||||
return bots_service.StopEndlessTasks(ctx)
|
return actions_service.StopEndlessTasks(ctx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,6 +42,6 @@ func registerCancelAbandonedJobs() {
|
|||||||
RunAtStart: true,
|
RunAtStart: true,
|
||||||
Schedule: "@every 6h",
|
Schedule: "@every 6h",
|
||||||
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
|
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
|
||||||
return bots_service.CancelAbandonedJobs(ctx)
|
return actions_service.CancelAbandonedJobs(ctx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification"
|
||||||
repo_module "code.gitea.io/gitea/modules/repository"
|
repo_module "code.gitea.io/gitea/modules/repository"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
bots_service "code.gitea.io/gitea/services/actions"
|
actions_service "code.gitea.io/gitea/services/actions"
|
||||||
pull_service "code.gitea.io/gitea/services/pull"
|
pull_service "code.gitea.io/gitea/services/pull"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// deletes bots resource after the repo has been deleted, to avoid new bots tasks
|
// deletes bots resource after the repo has been deleted, to avoid new bots tasks
|
||||||
if err := bots_service.DeleteResourceOfRepository(ctx, repo); err != nil {
|
if err := actions_service.DeleteResourceOfRepository(ctx, repo); err != nil {
|
||||||
log.Error("delete bots resource failed: %v", err)
|
log.Error("delete bots resource failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user