Split logs_download.go into focused files (flatten, zip, artifacts) - #50052
Conversation
|
Thanks for getting this refactoring underway, This PR tackles the file-diet issue head-on — breaking up the 1151-line A few notes as this moves forward:
The refactoring plan is thorough and the split boundaries are clean. Looking forward to seeing the implementation!
|
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
PR Triage: #50052
Draft, large pure code-organization refactor splitting logs_download.go (702+/632-). No behavior change expected; batch with other refactor PRs.
|
There was a problem hiding this comment.
Pull request overview
Splits artifact download logic into focused modules while preserving existing APIs and behavior.
Changes:
- Separates ZIP extraction, artifact flattening, and artifact discovery/download logic.
- Extracts post-download flattening and verbose-summary helpers.
- Retains top-level orchestration in
logs_download.go.
Show a summary per file
| File | Description |
|---|---|
pkg/cli/logs_download.go |
Retains download orchestration and delegates extracted operations. |
pkg/cli/logs_download_zip.go |
Contains protected ZIP extraction logic. |
pkg/cli/logs_download_flatten.go |
Normalizes downloaded artifact directory structures. |
pkg/cli/logs_download_artifacts.go |
Handles artifact discovery, filtering, retries, and summaries. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Balanced
|
|
||
| // Copy the content with size limit enforcement | ||
| // Use LimitReader to prevent reading more than declared size | ||
| limitedReader := io.LimitReader(srcFile, int64(maxFileSize)) |
|
/matt |
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅ |
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /codebase-design — pure code-move refactor, no logic changes. Two issues worth addressing; nothing blocking.
📋 Key Themes & Highlights
Issues Found
- Dead post-condition check in
extractZipFile(zip.go:109):uint64(written) > maxFileSizeis unreachable becauseio.LimitReaderalready prevents reading beyond the limit. It gives false assurance without providing real protection. See inline comment. - Duplicated
repoFlagconstruction (artifacts.go): the 6-line hostname/owner/repo assembly is copy-pasted betweendownloadArtifactsByNameandretryCriticalArtifacts. Should be a shared helper. See inline comment.
Positive Highlights
- ✅ Clean file split with well-named concerns — flatten, zip, artifacts, orchestration.
- ✅ Good existing security annotations (
#nosecwith explanation, decompression-bomb guard). - ✅
extractErrnamed-return pattern for safe close-error propagation is correct and well-commented. - ✅ All extractions are pure moves; no behaviour changes.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 47.9 AIC · ⌖ 10.9 AIC · ⊞ 7.1K
Comment /matt to run again
|
@copilot This PR still needs another pass before maintainers can investigate quickly.
|
- logs_download_zip.go: use LimitReader(maxFileSize+1) so the written>maxFileSize check is now reachable and correctly rejects oversized content; also remove the inaccurate 'case-collision' claim from the file comment. - logs_download_artifacts.go: extract duplicated owner/repo/hostname → repoFlag assembly into buildRepoFlag helper and replace both call sites. Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Both issues addressed in commit
|
|
🎉 This pull request is included in a new release. Release: |
pkg/cli/logs_download.gohad grown to 1151 lines mixing four distinct concerns (zip extraction, directory flattening, artifact listing/filtering, and download orchestration), making it hard to navigate and test in isolation.File splits
logs_download_flatten.go(321 lines): post-download directory normalization —flattenSingleFileArtifacts,findArtifactDir,flattenArtifactTree,flattenUnifiedArtifact,flattenActivationArtifact,flattenAgentOutputsArtifact,flattenSafeOutputsItemsArtifact,flattenDownloadedArtifactslogs_download_zip.go(115 lines): zip archive extraction with path-traversal/decompression-bomb protections —unzipFile,extractZipFilelogs_download_artifacts.go(263 lines): artifact discovery, filtering, and per-name download/retry —listArtifacts,isNonZipArtifactError,isCaseCollisionArtifactError,isDockerBuildArtifact,listRunArtifactNames,downloadArtifactsByName,retryCriticalArtifacts,logVerboseDownloadSummarylogs_download.go(522 lines, retained): top-level orchestration —isUsageOnlyArtifactFilter,shouldDownloadWorkflowRunLogs,downloadWorkflowRunLogs,downloadRunArtifacts,ensureUsageAwInfoFallbackReducing
downloadRunArtifactscomplexityThis function alone was ~390 lines, mixing cache-checks, bulk/individual download strategies, and post-processing. Its post-download tail was extracted into two named helpers so the core download logic is easier to follow:
downloadRunArtifactsis now ~322 lines.All extractions are code moves — no logic changes, no public API changes.
Branch refresh requested by PR Sous Chef.
Run: https://github.com/github/gh-aw/actions/runs/30851084299