mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix(run): show logs past jobs that have not started
run logs stopped at the first job without logs with a misleading not-found error. Report such a job as "build (job 35): not started yet" (or that it never started when it was canceled or skipped first) and continue with the next job. Jobs report started_at and completed_at, null until they happen. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
3 files changed
+94
-16
No files matched your search
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -86,11 +87,22 @@ func (a *application) runLogsCommand() *cobra.Command {
|
||||
})
|
||||
}
|
||||
for _, job := range jobs {
|
||||
if _, err := fmt.Fprintf(cmd.ErrOrStderr(), "Job %d: %s\n", job.ID, terminal.SafeLine(job.Name)); err != nil {
|
||||
label := fmt.Sprintf("%s (job %d)", terminal.SafeLine(job.Name), job.ID)
|
||||
var logs io.ReadCloser
|
||||
if job.Started() {
|
||||
logs, err = service.JobLogs(cmd.Context(), job.ID)
|
||||
}
|
||||
if !job.Started() || errors.Is(err, services.ErrJobNotStarted) {
|
||||
if _, err := fmt.Fprintf(cmd.ErrOrStderr(), "%s: %s\n", label, unstarted(job)); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logs, err := service.JobLogs(cmd.Context(), job.ID)
|
||||
if err != nil {
|
||||
if _, err := fmt.Fprintln(cmd.ErrOrStderr(), label); err != nil {
|
||||
_ = logs.Close()
|
||||
return err
|
||||
}
|
||||
_, copyErr := io.Copy(out, logs)
|
||||
@@ -111,3 +123,12 @@ func (a *application) runLogsCommand() *cobra.Command {
|
||||
cmd.Flags().DurationVar(&timeout, "timeout", time.Hour, "Maximum follow duration")
|
||||
return cmd
|
||||
}
|
||||
|
||||
// unstarted explains why a job has no logs: it is waiting for a runner, or it completed, such
|
||||
// as by cancellation, before one started it.
|
||||
func unstarted(job services.Job) string {
|
||||
if job.CompletedAt == nil {
|
||||
return "not started yet"
|
||||
}
|
||||
return "never started (" + cmp.Or(job.Conclusion, job.Status) + ")"
|
||||
}
|
||||
Reference in new issue
Block a user