mirror of https://github.com/go-gitea/gitea.git
actions view: move loading of task attributes etc... into own func (#31494)
just a smal refactor to make the function length smaler ... and code more reusable in the futurepull/33472/head^2
parent
9cd88ef8c7
commit
fcfe1fb0fc
|
@ -281,17 +281,33 @@ func ViewPost(ctx *context_module.Context) {
|
||||||
resp.State.CurrentJob.Steps = make([]*ViewJobStep, 0) // marshal to '[]' instead fo 'null' in json
|
resp.State.CurrentJob.Steps = make([]*ViewJobStep, 0) // marshal to '[]' instead fo 'null' in json
|
||||||
resp.Logs.StepsLog = make([]*ViewStepLog, 0) // marshal to '[]' instead fo 'null' in json
|
resp.Logs.StepsLog = make([]*ViewStepLog, 0) // marshal to '[]' instead fo 'null' in json
|
||||||
if task != nil {
|
if task != nil {
|
||||||
|
steps, logs, err := convertToViewModel(ctx, req.LogCursors, task)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp.State.CurrentJob.Steps = append(resp.State.CurrentJob.Steps, steps...)
|
||||||
|
resp.Logs.StepsLog = append(resp.Logs.StepsLog, logs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.JSON(http.StatusOK, resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertToViewModel(ctx *context_module.Context, cursors []LogCursor, task *actions_model.ActionTask) ([]*ViewJobStep, []*ViewStepLog, error) {
|
||||||
|
var viewJobs []*ViewJobStep
|
||||||
|
var logs []*ViewStepLog
|
||||||
|
|
||||||
steps := actions.FullSteps(task)
|
steps := actions.FullSteps(task)
|
||||||
|
|
||||||
for _, v := range steps {
|
for _, v := range steps {
|
||||||
resp.State.CurrentJob.Steps = append(resp.State.CurrentJob.Steps, &ViewJobStep{
|
viewJobs = append(viewJobs, &ViewJobStep{
|
||||||
Summary: v.Name,
|
Summary: v.Name,
|
||||||
Duration: v.Duration().String(),
|
Duration: v.Duration().String(),
|
||||||
Status: v.Status.String(),
|
Status: v.Status.String(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cursor := range req.LogCursors {
|
for _, cursor := range cursors {
|
||||||
if !cursor.Expanded {
|
if !cursor.Expanded {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -301,7 +317,7 @@ func ViewPost(ctx *context_module.Context) {
|
||||||
// if task log is expired, return a consistent log line
|
// if task log is expired, return a consistent log line
|
||||||
if task.LogExpired {
|
if task.LogExpired {
|
||||||
if cursor.Cursor == 0 {
|
if cursor.Cursor == 0 {
|
||||||
resp.Logs.StepsLog = append(resp.Logs.StepsLog, &ViewStepLog{
|
logs = append(logs, &ViewStepLog{
|
||||||
Step: cursor.Step,
|
Step: cursor.Step,
|
||||||
Cursor: 1,
|
Cursor: 1,
|
||||||
Lines: []*ViewStepLogLine{
|
Lines: []*ViewStepLogLine{
|
||||||
|
@ -336,8 +352,7 @@ func ViewPost(ctx *context_module.Context) {
|
||||||
offset := task.LogIndexes[index]
|
offset := task.LogIndexes[index]
|
||||||
logRows, err := actions.ReadLogs(ctx, task.LogInStorage, task.LogFilename, offset, length)
|
logRows, err := actions.ReadLogs(ctx, task.LogInStorage, task.LogFilename, offset, length)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("actions.ReadLogs", err)
|
return nil, nil, fmt.Errorf("actions.ReadLogs: %w", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, row := range logRows {
|
for i, row := range logRows {
|
||||||
|
@ -349,16 +364,15 @@ func ViewPost(ctx *context_module.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Logs.StepsLog = append(resp.Logs.StepsLog, &ViewStepLog{
|
logs = append(logs, &ViewStepLog{
|
||||||
Step: cursor.Step,
|
Step: cursor.Step,
|
||||||
Cursor: cursor.Cursor + int64(len(logLines)),
|
Cursor: cursor.Cursor + int64(len(logLines)),
|
||||||
Lines: logLines,
|
Lines: logLines,
|
||||||
Started: int64(step.Started),
|
Started: int64(step.Started),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, resp)
|
return viewJobs, logs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rerun will rerun jobs in the given run
|
// Rerun will rerun jobs in the given run
|
||||||
|
|
Loading…
Reference in New Issue