fix(run): filter runs by creation time and report unstarted times as null

run list --since/--until compared the start time, which queued runs report
as the Unix epoch, so every queued run was dropped. Filter on created_at,
stop scanning at the first older run, and report a run's missing start or
completion time as null instead of 1970-01-01.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-11 23:46:26 +02:00
1 parent f21c05ead4
commit 68da491b9e
3 files changed
+68 -31

No files matched your search

+34 -22
View File
@@ -28,22 +28,23 @@ func workflowFrom(workflow *gitea.ActionsWorkflow) Workflow {
return Workflow{ID: workflow.ID, Name: workflow.Name, Path: workflow.Path, State: workflow.State}
}
// Run is the stable command representation of an Actions run.
// Run is the stable command representation of an Actions run. StartedAt and CompletedAt are nil
// until the run starts and completes.
type Run struct {
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
StartedAt string `json:"started_at"`
CompletedAt string `json:"completed_at"`
ID int64 `json:"id"`
Title string `json:"title"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
URL string `json:"url"`
Branch string `json:"branch"`
Event string `json:"event,omitempty"`
Actor string `json:"actor,omitempty"`
Commit string `json:"commit,omitempty"`
Attempt int64 `json:"attempt,omitempty"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
StartedAt *string `json:"started_at"`
CompletedAt *string `json:"completed_at"`
ID int64 `json:"id"`
Title string `json:"title"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
URL string `json:"url"`
Branch string `json:"branch"`
Event string `json:"event,omitempty"`
Actor string `json:"actor,omitempty"`
Commit string `json:"commit,omitempty"`
Attempt int64 `json:"attempt,omitempty"`
}
type runResponse struct {
CreatedAt string `json:"created_at"`
@@ -67,11 +68,21 @@ type runResponse struct {
func (r runResponse) result() Run {
return Run{
ID: r.ID, Title: r.DisplayTitle, Status: r.Status, Conclusion: r.Conclusion, URL: r.HTMLURL, Branch: r.HeadBranch,
CreatedAt: r.CreatedAt, UpdatedAt: r.UpdatedAt, StartedAt: r.StartedAt, CompletedAt: r.CompletedAt,
CreatedAt: r.CreatedAt, UpdatedAt: r.UpdatedAt, StartedAt: runTime(r.StartedAt), CompletedAt: runTime(r.CompletedAt),
Event: r.Event, Actor: r.Actor.Login, Commit: r.HeadSHA, Attempt: r.RunAttempt,
}
}
// runTime returns an Actions timestamp, or nil for the zero or Unix epoch time Gitea reports
// for a run or job that has not started or completed.
func runTime(raw string) *string {
t, err := time.Parse(time.RFC3339Nano, raw)
if raw == "" || (err == nil && t.Unix() <= 0) {
return nil
}
return &raw
}
// DispatchResult identifies a workflow run created by dispatch when the server returns details.
type DispatchResult struct {
ID int64 `json:"id"`
@@ -171,14 +182,15 @@ func (s Actions) Runs(ctx context.Context, opts RunListOptions) ([]Run, error) {
return result, nil
}
for _, item := range items {
if item.StartedAt == "" {
continue
}
started, err := time.Parse(time.RFC3339Nano, item.StartedAt)
created, err := time.Parse(time.RFC3339Nano, item.CreatedAt)
if err != nil {
return nil, errors.New("server returned an invalid run start timestamp")
return nil, errors.New("server returned an invalid run creation timestamp")
}
if opts.Since != nil && started.Before(*opts.Since) || opts.Until != nil && started.After(*opts.Until) {
// Runs are listed newest first, so the rest were created earlier still.
if opts.Since != nil && created.Before(*opts.Since) {
return result, nil
}
if opts.Until != nil && created.After(*opts.Until) {
continue
}
if matched >= first {