Repository: cli/cli
File: pkg/cmd/run/view/view.go (Go)

Code before:
//	├── jobname1/
//	│   ├── 1_stepname.txt
//	│   ├── 2_anotherstepname.txt
//	│   ├── 3_stepstepname.txt
//	│   └── 4_laststepname.txt
//	├── jobname2/
//	|   ├── 1_stepname.txt
//	|   └── 2_somestepname.txt
//	├── 0_jobname1.txt
//	├── 1_jobname2.txt
//	└── -9999999999_jobname3.txt
//
// It iterates through the list of jobs and tries to find the matching
// log in the zip file. If the matching log is found it is attached
// to the job.
//
// The top-level .txt files include the logs for an entire job run. Note that
// the prefixed number is either:
//   - An ordinal and cannot be mapped to the corresponding job's ID.
//   - A negative integer which is the ID of the job in the old Actions service.
//     The service right now tries to get logs and use an ordinal in a loop.
//     However, if it doesn't get the logs, it falls back to an old service
//     where the ID can apparently be negative.
func attachRunLog(rlz *zip.Reader, jobs []shared.Job) {
	for i, job := range jobs {
		// the normal job run log file is preferred over the legacy one. So, we
		// try to find the normal log file, and if we couldn't find it then we
		// look for the legacy one, if any.
		jobLog := matchFileInZIPArchive(rlz, jobLogFilenameRegexp(job))
		if jobLog == nil {
			jobLog = matchFileInZIPArchive(rlz, legacyJobLogFilenameRegexp(job))
		}
		jobs[i].Log = jobLog

		for j, step := range job.Steps {
			jobs[i].Steps[j].Log = matchFileInZIPArchive(rlz, stepLogFilenameRegexp(job, step))
		}
	}
}

func matchFileInZIPArchive(zr *zip.Reader, re *regexp.Regexp) *zip.File {
	for _, file := range zr.File {
		if re.MatchString(file.Name) {
			return file
		}
	}
	return nil
}

func displayRunLog(w io.Writer, jobs []shared.Job, failed bool) error {
	for _, job := range jobs {

Review comment (suggestion):
Given https://github.com/cli/cli/pull/10769#issuecomment-2796956212

I'd suggest updating this comment to the effect of:

```go
// As a highest priority, we try to use the step logs first. We have seen zips that surprisingly contain
// step logs, normal job logs and legacy job logs. In this case, both job logs would be ignored. We have
// never seen a zip containing both job logs and no step logs, however, it may be possible. In that case
// let's prioritise the normal log over the legacy one.
```

Code after:
//	├── jobname1/
//	│   ├── 1_stepname.txt
//	│   ├── 2_anotherstepname.txt
//	│   ├── 3_stepstepname.txt
//	│   └── 4_laststepname.txt
//	├── jobname2/
//	|   ├── 1_stepname.txt
//	|   └── 2_somestepname.txt
//	├── 0_jobname1.txt
//	├── 1_jobname2.txt
//	└── -9999999999_jobname3.txt
//
// It iterates through the list of jobs and tries to find the matching
// log in the zip file. If the matching log is found it is attached
// to the job.
//
// The top-level .txt files include the logs for an entire job run. Note that
// the prefixed number is either:
//   - An ordinal and cannot be mapped to the corresponding job's ID.
//   - A negative integer which is the ID of the job in the old Actions service.
//     The service right now tries to get logs and use an ordinal in a loop.
//     However, if it doesn't get the logs, it falls back to an old service
//     where the ID can apparently be negative.
func attachRunLog(rlz *zip.Reader, jobs []shared.Job) {
	for i, job := range jobs {
		// As a highest priority, we try to use the step logs first. We have seen zips that surprisingly contain
		// step logs, normal job logs and legacy job logs. In this case, both job logs would be ignored. We have
		// never seen a zip containing both job logs and no step logs, however, it may be possible. In that case
		// let's prioritise the normal log over the legacy one.
		jobLog := matchFileInZIPArchive(rlz, jobLogFilenameRegexp(job))
		if jobLog == nil {
			jobLog = matchFileInZIPArchive(rlz, legacyJobLogFilenameRegexp(job))
		}
		jobs[i].Log = jobLog

		for j, step := range job.Steps {
			jobs[i].Steps[j].Log = matchFileInZIPArchive(rlz, stepLogFilenameRegexp(job, step))
		}
	}
}

func matchFileInZIPArchive(zr *zip.Reader, re *regexp.Regexp) *zip.File {
	for _, file := range zr.File {
		if re.MatchString(file.Name) {
			return file
		}
	}
	return nil
}

func displayRunLog(w io.Writer, jobs []shared.Job, failed bool) error {