fix: address verified review findings (actions-runs-1)

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-18 17:43:11 +02:00
1 parent b69019fd74
commit d0cdfe7113
9 files changed
+267 -32

No files matched your search

+23 -6
View File
@@ -70,11 +70,10 @@ var artifactColumns = []terminal.Column{
func artifactRow(item services.Artifact) []terminal.Cell {
expires := terminal.Cell{}
expiresAt := ""
if item.ExpiresAt != nil {
expiresAt = *item.ExpiresAt
expires.Time = terminal.ParseTime(expiresAt)
expires.Time = terminal.ParseTime(*item.ExpiresAt)
}
piped := terminal.Cell{Time: expires.Time}
if item.Expired {
expires = terminal.Cell{Text: "expired", Color: "red"}
}
@@ -84,7 +83,7 @@ func artifactRow(item services.Artifact) []terminal.Cell {
{Text: terminal.Bytes(item.Size)},
{Text: strconv.FormatInt(item.Size, 10)},
expires,
{Text: expiresAt},
piped,
{Text: strconv.FormatBool(item.Expired)},
}
}
@@ -122,7 +121,7 @@ $ tea run download 34 --zip`,
if err != nil {
return err
}
selected, err := selectArtifacts(artifacts, names, run)
selected, err := selectArtifacts(latestArtifacts(artifacts), names, run)
if err != nil {
return err
}
@@ -153,6 +152,24 @@ $ tea run download 34 --zip`,
return cmd
}
// latestArtifacts keeps the newest artifact of each name: after a rerun, the run lists the artifacts
// of every attempt, which may share names.
func latestArtifacts(artifacts []services.Artifact) []services.Artifact {
index := map[string]int{}
latest := make([]services.Artifact, 0, len(artifacts))
for _, artifact := range artifacts {
if i, seen := index[artifact.Name]; seen {
if artifact.ID > latest[i].ID {
latest[i] = artifact
}
continue
}
index[artifact.Name] = len(latest)
latest = append(latest, artifact)
}
return latest
}
// selectArtifacts returns the artifacts of a run with the given names, or all of them.
func selectArtifacts(artifacts []services.Artifact, names []string, run int64) ([]services.Artifact, error) {
if len(artifacts) == 0 {
@@ -167,7 +184,7 @@ func selectArtifacts(artifacts []services.Artifact, names []string, run int64) (
if index < 0 {
available := make([]string, len(artifacts))
for i, artifact := range artifacts {
available[i] = artifact.Name
available[i] = terminal.SafeLine(artifact.Name)
}
return nil, fmt.Errorf("artifact %q not found in run %d (artifacts: %s)", name, run, strings.Join(available, ", "))
}