Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions routers/web/repo/actions/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Logs.StepsLog = make([]*ViewStepLog, 0) // marshal to '[]' instead fo 'null' in json
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)

for _, v := range steps {
resp.State.CurrentJob.Steps = append(resp.State.CurrentJob.Steps, &ViewJobStep{
viewJobs = append(viewJobs, &ViewJobStep{
Summary: v.Name,
Duration: v.Duration().String(),
Status: v.Status.String(),
})
}

for _, cursor := range req.LogCursors {
for _, cursor := range cursors {
if !cursor.Expanded {
continue
}
Expand All @@ -301,7 +317,7 @@ func ViewPost(ctx *context_module.Context) {
// if task log is expired, return a consistent log line
if task.LogExpired {
if cursor.Cursor == 0 {
resp.Logs.StepsLog = append(resp.Logs.StepsLog, &ViewStepLog{
logs = append(logs, &ViewStepLog{
Step: cursor.Step,
Cursor: 1,
Lines: []*ViewStepLogLine{
Expand Down Expand Up @@ -336,8 +352,7 @@ func ViewPost(ctx *context_module.Context) {
offset := task.LogIndexes[index]
logRows, err := actions.ReadLogs(ctx, task.LogInStorage, task.LogFilename, offset, length)
if err != nil {
ctx.ServerError("actions.ReadLogs", err)
return
return nil, nil, fmt.Errorf("actions.ReadLogs: %w", err)
}

for i, row := range logRows {
Expand All @@ -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,
Cursor: cursor.Cursor + int64(len(logLines)),
Lines: logLines,
Started: int64(step.Started),
})
}
}

ctx.JSON(http.StatusOK, resp)
return viewJobs, logs, nil
}

// Rerun will rerun jobs in the given run
Expand Down