mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-08 17:05:45 +02:00
build UI
This commit is contained in:
parent
482832da76
commit
f75a4abc5d
@ -23,7 +23,7 @@ import (
|
||||
// Run represents a run of a workflow file
|
||||
type Run struct {
|
||||
ID int64
|
||||
Name string
|
||||
Title string
|
||||
RepoID int64 `xorm:"index unique(repo_workflow_index)"`
|
||||
Repo *repo_model.Repository `xorm:"-"`
|
||||
WorkflowID string `xorm:"index unique(repo_workflow_index)"` // the name of workflow file
|
||||
@ -52,6 +52,10 @@ func (Run) TableName() string {
|
||||
return "bots_run"
|
||||
}
|
||||
|
||||
func (run *Run) HTMLURL() string {
|
||||
return fmt.Sprintf("%s/builds/run/%d", run.Repo.HTMLURL(), run.Index)
|
||||
}
|
||||
|
||||
// LoadAttributes load Repo TriggerUser if not loaded
|
||||
func (r *Run) LoadAttributes(ctx context.Context) error {
|
||||
if r == nil {
|
||||
|
@ -16,10 +16,10 @@ import (
|
||||
type RunList []*Run
|
||||
|
||||
// GetUserIDs returns a slice of user's id
|
||||
func (builds RunList) GetUserIDs() []int64 {
|
||||
func (runs RunList) GetUserIDs() []int64 {
|
||||
userIDsMap := make(map[int64]struct{})
|
||||
for _, build := range builds {
|
||||
userIDsMap[build.TriggerUserID] = struct{}{}
|
||||
for _, run := range runs {
|
||||
userIDsMap[run.TriggerUserID] = struct{}{}
|
||||
}
|
||||
userIDs := make([]int64, 0, len(userIDsMap))
|
||||
for userID := range userIDsMap {
|
||||
@ -28,14 +28,14 @@ func (builds RunList) GetUserIDs() []int64 {
|
||||
return userIDs
|
||||
}
|
||||
|
||||
func (builds RunList) LoadTriggerUser() error {
|
||||
userIDs := builds.GetUserIDs()
|
||||
func (runs RunList) LoadTriggerUser() error {
|
||||
userIDs := runs.GetUserIDs()
|
||||
users := make(map[int64]*user_model.User, len(userIDs))
|
||||
if err := db.GetEngine(db.DefaultContext).In("id", userIDs).Find(&users); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, task := range builds {
|
||||
task.TriggerUser = users[task.TriggerUserID]
|
||||
for _, run := range runs {
|
||||
run.TriggerUser = users[run.TriggerUserID]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -52,16 +52,14 @@ func (opts FindRunOptions) toConds() builder.Cond {
|
||||
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
|
||||
}
|
||||
if opts.IsClosed.IsFalse() {
|
||||
|
||||
} else if opts.IsClosed.IsTrue() {
|
||||
|
||||
}
|
||||
return cond
|
||||
}
|
||||
|
||||
func FindRuns(ctx context.Context, opts FindRunOptions) (RunList, int64, error) {
|
||||
e := db.GetEngine(ctx).Where(opts.toConds())
|
||||
if opts.PageSize>0&&opts.Page >=1 {
|
||||
if opts.PageSize > 0 && opts.Page >= 1 {
|
||||
e.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
|
||||
}
|
||||
var runs RunList
|
||||
|
@ -50,7 +50,7 @@ func addBotTables(x *xorm.Engine) error {
|
||||
|
||||
type BotsRun struct {
|
||||
ID int64
|
||||
Name string
|
||||
Title string
|
||||
RepoID int64 `xorm:"index unique(repo_workflow_index)"`
|
||||
WorkflowID string `xorm:"index unique(repo_workflow_index)"` // the name of workflow file
|
||||
Index int64 `xorm:"index unique(repo_workflow_index)"` // a unique number for each run of a particular workflow in a repository
|
||||
|
@ -86,7 +86,7 @@ func notify(repo *repo_model.Repository, doer *user_model.User, payload, ref str
|
||||
|
||||
for id, content := range workflows {
|
||||
run := bots_model.Run{
|
||||
Name: commit.Message(),
|
||||
Title: commit.Message(),
|
||||
RepoID: repo.ID,
|
||||
WorkflowID: id,
|
||||
TriggerUserID: doer.ID,
|
||||
@ -96,6 +96,9 @@ func notify(repo *repo_model.Repository, doer *user_model.User, payload, ref str
|
||||
EventPayload: payload,
|
||||
Status: core.StatusPending,
|
||||
}
|
||||
if len(run.Title) > 255 {
|
||||
run.Title = run.Title[:255]
|
||||
}
|
||||
jobs, err := jobparser.Parse(content) // TODO: parse with options
|
||||
if err != nil {
|
||||
log.Error("jobparser.Parse: %v", err)
|
||||
|
@ -106,7 +106,7 @@ func BuildViewPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
resp := &BuildViewResponse{}
|
||||
resp.StateData.BuildInfo.Title = run.Name
|
||||
resp.StateData.BuildInfo.Title = run.Title
|
||||
|
||||
respJobs := make([]*BuildViewJob, len(jobs))
|
||||
for i, v := range jobs {
|
||||
|
@ -57,18 +57,22 @@ func List(ctx *context.Context) {
|
||||
} else {
|
||||
opts.IsClosed = util.OptionalBoolFalse
|
||||
}
|
||||
builds, total, err := bots_model.FindRuns(ctx, opts)
|
||||
runs, total, err := bots_model.FindRuns(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err := builds.LoadTriggerUser(); err != nil {
|
||||
for _, run := range runs {
|
||||
run.Repo = ctx.Repo.Repository
|
||||
}
|
||||
|
||||
if err := runs.LoadTriggerUser(); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Builds"] = builds
|
||||
ctx.Data["Builds"] = runs
|
||||
|
||||
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5)
|
||||
pager.SetDefaultParams(ctx)
|
||||
|
Loading…
x
Reference in New Issue
Block a user