mirror of
https://github.com/go-gitea/gitea.git
synced 2024-09-01 14:56:30 +00:00
chore: add extra fields to Run and RunJob
This commit is contained in:
parent
cab3fc072a
commit
5e7adf2004
@ -16,10 +16,10 @@ import (
|
|||||||
"code.gitea.io/gitea/models/webhook"
|
"code.gitea.io/gitea/models/webhook"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
"xorm.io/builder"
|
|
||||||
|
|
||||||
"github.com/nektos/act/pkg/jobparser"
|
"github.com/nektos/act/pkg/jobparser"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Run represents a run of a workflow file
|
// Run represents a run of a workflow file
|
||||||
@ -28,6 +28,7 @@ type Run struct {
|
|||||||
Title string
|
Title string
|
||||||
RepoID int64 `xorm:"index unique(repo_index)"`
|
RepoID int64 `xorm:"index unique(repo_index)"`
|
||||||
Repo *repo_model.Repository `xorm:"-"`
|
Repo *repo_model.Repository `xorm:"-"`
|
||||||
|
OwnerID int64 `xorm:"index"`
|
||||||
WorkflowID string `xorm:"index"` // the name of workflow file
|
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
|
Index int64 `xorm:"index unique(repo_index)"` // a unique number for each run of a repository
|
||||||
TriggerUserID int64
|
TriggerUserID int64
|
||||||
@ -175,6 +176,9 @@ func InsertRun(run *Run, jobs []*jobparser.SingleWorkflow) error {
|
|||||||
}
|
}
|
||||||
runJobs = append(runJobs, &RunJob{
|
runJobs = append(runJobs, &RunJob{
|
||||||
RunID: run.ID,
|
RunID: run.ID,
|
||||||
|
RepoID: run.RepoID,
|
||||||
|
OwnerID: run.OwnerID,
|
||||||
|
CommitSHA: run.CommitSHA,
|
||||||
Name: job.Name,
|
Name: job.Name,
|
||||||
WorkflowPayload: payload,
|
WorkflowPayload: payload,
|
||||||
JobID: id,
|
JobID: id,
|
||||||
|
@ -11,9 +11,9 @@ import (
|
|||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
"xorm.io/builder"
|
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunJob represents a job of a run
|
// RunJob represents a job of a run
|
||||||
@ -21,6 +21,9 @@ type RunJob struct {
|
|||||||
ID int64
|
ID int64
|
||||||
RunID int64 `xorm:"index"`
|
RunID int64 `xorm:"index"`
|
||||||
Run *Run `xorm:"-"`
|
Run *Run `xorm:"-"`
|
||||||
|
RepoID int64 `xorm:"index"`
|
||||||
|
OwnerID int64 `xorm:"index"`
|
||||||
|
CommitSHA string `xorm:"index"`
|
||||||
Name string
|
Name string
|
||||||
Attempt int64
|
Attempt int64
|
||||||
WorkflowPayload []byte
|
WorkflowPayload []byte
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -60,6 +61,9 @@ func (jobs RunJobList) LoadAttributes(ctx context.Context, withRepo bool) error
|
|||||||
type FindRunJobOptions struct {
|
type FindRunJobOptions struct {
|
||||||
db.ListOptions
|
db.ListOptions
|
||||||
RunID int64
|
RunID int64
|
||||||
|
RepoID int64
|
||||||
|
OwnerID int64
|
||||||
|
CommitSHA string
|
||||||
Statuses []Status
|
Statuses []Status
|
||||||
UpdatedBefore timeutil.TimeStamp
|
UpdatedBefore timeutil.TimeStamp
|
||||||
}
|
}
|
||||||
@ -69,6 +73,15 @@ func (opts FindRunJobOptions) toConds() builder.Cond {
|
|||||||
if opts.RunID > 0 {
|
if opts.RunID > 0 {
|
||||||
cond = cond.And(builder.Eq{"run_id": opts.RunID})
|
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 {
|
if len(opts.Statuses) > 0 {
|
||||||
cond = cond.And(builder.In("status", opts.Statuses))
|
cond = cond.And(builder.In("status", opts.Statuses))
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
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/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -68,6 +69,7 @@ func (runs RunList) LoadRepos() error {
|
|||||||
type FindRunOptions struct {
|
type FindRunOptions struct {
|
||||||
db.ListOptions
|
db.ListOptions
|
||||||
RepoID int64
|
RepoID int64
|
||||||
|
OwnerID int64
|
||||||
IsClosed util.OptionalBool
|
IsClosed util.OptionalBool
|
||||||
WorkflowFileName string
|
WorkflowFileName string
|
||||||
}
|
}
|
||||||
@ -77,6 +79,9 @@ func (opts FindRunOptions) toConds() builder.Cond {
|
|||||||
if opts.RepoID > 0 {
|
if opts.RepoID > 0 {
|
||||||
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
|
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() {
|
if opts.IsClosed.IsFalse() {
|
||||||
cond = cond.And(builder.Eq{"status": StatusWaiting}.Or(
|
cond = cond.And(builder.Eq{"status": StatusWaiting}.Or(
|
||||||
builder.Eq{"status": StatusRunning}))
|
builder.Eq{"status": StatusRunning}))
|
||||||
|
@ -7,6 +7,7 @@ package migrations
|
|||||||
import (
|
import (
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
|
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ func addBotTables(x *xorm.Engine) error {
|
|||||||
ID int64
|
ID int64
|
||||||
Title string
|
Title string
|
||||||
RepoID int64 `xorm:"index unique(repo_index)"`
|
RepoID int64 `xorm:"index unique(repo_index)"`
|
||||||
|
OwnerID int64 `xorm:"index"`
|
||||||
WorkflowID string `xorm:"index"` // the name of workflow file
|
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
|
Index int64 `xorm:"index unique(repo_index)"` // a unique number for each run of a repository
|
||||||
TriggerUserID int64
|
TriggerUserID int64
|
||||||
@ -70,6 +72,9 @@ func addBotTables(x *xorm.Engine) error {
|
|||||||
type BotsRunJob struct {
|
type BotsRunJob struct {
|
||||||
ID int64
|
ID int64
|
||||||
RunID int64 `xorm:"index"`
|
RunID int64 `xorm:"index"`
|
||||||
|
RepoID int64 `xorm:"index"`
|
||||||
|
OwnerID int64 `xorm:"index"`
|
||||||
|
CommitSHA string `xorm:"index"`
|
||||||
Name string
|
Name string
|
||||||
Attempt int64
|
Attempt int64
|
||||||
WorkflowPayload []byte
|
WorkflowPayload []byte
|
||||||
|
@ -75,6 +75,7 @@ func notify(repo *repo_model.Repository, doer *user_model.User, ref string, evt
|
|||||||
run := bots_model.Run{
|
run := bots_model.Run{
|
||||||
Title: commit.Message(),
|
Title: commit.Message(),
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
|
OwnerID: repo.OwnerID,
|
||||||
WorkflowID: id,
|
WorkflowID: id,
|
||||||
TriggerUserID: doer.ID,
|
TriggerUserID: doer.ID,
|
||||||
Ref: ref,
|
Ref: ref,
|
||||||
|
Loading…
Reference in New Issue
Block a user