chore: add extra fields to Run and RunJob

This commit is contained in:
Jason Song 2022-11-10 18:02:08 +08:00
parent cab3fc072a
commit 5e7adf2004
6 changed files with 36 additions and 5 deletions

View File

@ -16,10 +16,10 @@ import (
"code.gitea.io/gitea/models/webhook"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
"xorm.io/builder"
"github.com/nektos/act/pkg/jobparser"
"golang.org/x/exp/slices"
"xorm.io/builder"
)
// Run represents a run of a workflow file
@ -28,6 +28,7 @@ type Run struct {
Title string
RepoID int64 `xorm:"index unique(repo_index)"`
Repo *repo_model.Repository `xorm:"-"`
OwnerID int64 `xorm:"index"`
WorkflowID string `xorm:"index"` // the name of workflow file
Index int64 `xorm:"index unique(repo_index)"` // a unique number for each run of a repository
TriggerUserID int64
@ -175,6 +176,9 @@ func InsertRun(run *Run, jobs []*jobparser.SingleWorkflow) error {
}
runJobs = append(runJobs, &RunJob{
RunID: run.ID,
RepoID: run.RepoID,
OwnerID: run.OwnerID,
CommitSHA: run.CommitSHA,
Name: job.Name,
WorkflowPayload: payload,
JobID: id,

View File

@ -11,9 +11,9 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/timeutil"
"xorm.io/builder"
"golang.org/x/exp/slices"
"xorm.io/builder"
)
// RunJob represents a job of a run
@ -21,6 +21,9 @@ type RunJob struct {
ID int64
RunID int64 `xorm:"index"`
Run *Run `xorm:"-"`
RepoID int64 `xorm:"index"`
OwnerID int64 `xorm:"index"`
CommitSHA string `xorm:"index"`
Name string
Attempt int64
WorkflowPayload []byte

View File

@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/timeutil"
"xorm.io/builder"
)
@ -60,6 +61,9 @@ func (jobs RunJobList) LoadAttributes(ctx context.Context, withRepo bool) error
type FindRunJobOptions struct {
db.ListOptions
RunID int64
RepoID int64
OwnerID int64
CommitSHA string
Statuses []Status
UpdatedBefore timeutil.TimeStamp
}
@ -69,6 +73,15 @@ func (opts FindRunJobOptions) toConds() builder.Cond {
if opts.RunID > 0 {
cond = cond.And(builder.Eq{"run_id": opts.RunID})
}
if opts.RepoID > 0 {
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
}
if opts.OwnerID > 0 {
cond = cond.And(builder.Eq{"owner_id": opts.OwnerID})
}
if opts.CommitSHA != "" {
cond = cond.And(builder.Eq{"commit_sha": opts.CommitSHA})
}
if len(opts.Statuses) > 0 {
cond = cond.And(builder.In("status", opts.Statuses))
}

View File

@ -11,6 +11,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/util"
"xorm.io/builder"
)
@ -68,6 +69,7 @@ func (runs RunList) LoadRepos() error {
type FindRunOptions struct {
db.ListOptions
RepoID int64
OwnerID int64
IsClosed util.OptionalBool
WorkflowFileName string
}
@ -77,6 +79,9 @@ func (opts FindRunOptions) toConds() builder.Cond {
if opts.RepoID > 0 {
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
}
if opts.OwnerID > 0 {
cond = cond.And(builder.Eq{"owner_id": opts.OwnerID})
}
if opts.IsClosed.IsFalse() {
cond = cond.And(builder.Eq{"status": StatusWaiting}.Or(
builder.Eq{"status": StatusRunning}))

View File

@ -7,6 +7,7 @@ package migrations
import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/timeutil"
"xorm.io/xorm"
)
@ -51,6 +52,7 @@ func addBotTables(x *xorm.Engine) error {
ID int64
Title string
RepoID int64 `xorm:"index unique(repo_index)"`
OwnerID int64 `xorm:"index"`
WorkflowID string `xorm:"index"` // the name of workflow file
Index int64 `xorm:"index unique(repo_index)"` // a unique number for each run of a repository
TriggerUserID int64
@ -70,6 +72,9 @@ func addBotTables(x *xorm.Engine) error {
type BotsRunJob struct {
ID int64
RunID int64 `xorm:"index"`
RepoID int64 `xorm:"index"`
OwnerID int64 `xorm:"index"`
CommitSHA string `xorm:"index"`
Name string
Attempt int64
WorkflowPayload []byte

View File

@ -75,6 +75,7 @@ func notify(repo *repo_model.Repository, doer *user_model.User, ref string, evt
run := bots_model.Run{
Title: commit.Message(),
RepoID: repo.ID,
OwnerID: repo.OwnerID,
WorkflowID: id,
TriggerUserID: doer.ID,
Ref: ref,