Conversation
…icate flattening logic Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
pelikhan
March 16, 2026 04:53
View session
5 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors artifact-flattening in the logs download flow by extracting the shared walk/move/cleanup logic into a single helper, reducing duplication and adding direct unit tests for the helper.
Changes:
- Added
flattenArtifactTree(...)helper to centralize traversal, file moves, and cleanup for artifact directories. - Updated unified/activation/agent_outputs flatteners to delegate to the shared helper (while preserving unified old/new structure detection).
- Added focused unit tests for
flattenArtifactTreecovering common flatten scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/cli/logs_download.go | Extracts shared flatten logic into flattenArtifactTree and updates callers to use it. |
| pkg/cli/logs_flatten_test.go | Adds direct unit tests for flattenArtifactTree and introduces testify assertions for the new cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
|
||
| if err != nil { | ||
| return fmt.Errorf("failed to flatten unified artifact: %w", err) | ||
| return fmt.Errorf("failed to flatten %s: %w", label, err) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three functions in
pkg/cli/logs_download.go(flattenUnifiedArtifact,flattenActivationArtifact,flattenAgentOutputsArtifact) contained ~150 lines of near-identical walk → move → cleanup code, making any behavioral fix a triple-apply problem.Changes
flattenArtifactTree(sourceDir, artifactDir, outputDir, label string, verbose bool) error— encapsulates thefilepath.Walktraversal,os.MkdirAll/os.Renameper entry, and warn-onlyos.RemoveAllcleanup;labeldrives all log and user-facing messagesflattenUnifiedArtifact— retains old/new structure detection (tmp/gh-awprefix check), then delegates withsourceDir != artifactDirwhen the old layout is presentflattenActivationArtifact/flattenAgentOutputsArtifact— reduced to path resolution + single delegate callflattenArtifactTreeinlogs_flatten_test.gocovering: basic move, nested dirs, detachedsourceDir/artifactDir(old-structure case), empty source, multiple files, verbose mode