Refactor logs.go: split 1,354-line file into 5 focused modules #6824
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.
The
pkg/cli/logs.gofile had grown to 1,354 lines (69% over the 800-line threshold), making it difficult to navigate and maintain. This refactoring splits it into focused modules with clear boundaries.File Structure
Original:
logs.go(1,354 lines) - monolithic implementationRefactored:
logs_command.go(229 lines) - CLI command definition and flag parsinglogs_orchestrator.go(683 lines) - download coordination, pagination, filteringlogs_github_api.go(269 lines) - GitHub API interactionslogs_display.go(180 lines) - table rendering and metrics formattinglogs_utils.go(91 lines) - helper functionsKey Changes
fetchJobStatuses(),fetchJobDetails(),listWorkflowRunsWithPagination()DownloadWorkflowLogs(),downloadRunArtifactsConcurrent()displayLogsOverview()with metrics formattingEach module has a dedicated logger instance following the
cli:logs_*naming convention. Public API remains unchanged -NewLogsCommand()andDownloadWorkflowLogs()maintain their signatures.Result
83% reduction in main command file size (1,354 → 229 lines), with all modules under 700 lines. Clear separation of concerns: command interface, orchestration, API calls, display, and utilities.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/user/usr/bin/gh gh api user --jq .login ithub/workflows 6436160/b112/vet.cfg(http block)/usr/bin/gh gh api user --jq .login 91/push_to_pull_request_branch.js GOPROXY /usr/bin/gh te GOWORK 75227ef3bc569b41--git-dir gh repo�� pload-artifact/git/ref/tags/v5 --json e/git --jq .owner.login + "-1 64/bin/go e/git(http block)/usr/bin/gh gh api user --jq .login ithub/workflows log e/git-remote-https -n1 --format=format:-1 8d2c81aea4ddbf42xterm-color e/git-remote-https om/a�� 2536-38582/test-3046845998/.github/workflows -pack 0/x64/bin/node -json GO111MODULE 64/bin/go git(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[file-diet] Refactor Large Go File: pkg/cli/logs.go</issue_title>
<issue_description>## Overview
The file
pkg/cli/logs.gohas grown to 1,354 lines, significantly exceeding the healthy 800-line threshold. This makes it difficult to navigate, maintain, and test effectively. The file contains the coregh aw logscommand implementation with multiple distinct functional areas that should be split into focused modules.Current State
pkg/cli/logs.goFunctional Analysis
The file contains these distinct functional areas:
DownloadWorkflowLogsfunction with pagination logicRefactoring Strategy
Proposed File Splits
1.
logs_command.go(CLI Command Definition)Responsibility: Cobra command setup, flag definitions, and command entry point
Functions to move:
NewLogsCommand()(lines 121-282)Estimated LOC: ~200 lines
Rationale: Separates the CLI interface layer from business logic
2.
logs_orchestrator.go(Download Orchestration)Responsibility: Main download workflow coordination, pagination, iteration logic
Functions to move:
DownloadWorkflowLogs()(lines 283-689)Estimated LOC: ~450 lines
Rationale: Core orchestration logic is complex enough to warrant its own file
3.
logs_download.go(Concurrent Download Operations)Responsibility: Artifact downloading, concurrent processing, cache management
Functions to move:
downloadRunArtifactsConcurrent()(lines 690-948)Estimated LOC: ~300 lines
Rationale: Isolates concurrent operations and artifact handling logic
4.
logs_github_api.go(GitHub API Integration)Responsibility: GitHub API calls for workflow runs, jobs, and statuses
Functions to move:
listWorkflowRunsWithPagination()(lines 949-1089)fetchJobStatuses()(lines 26-71)fetchJobDetails()(lines 74-119)Estimated LOC: ~250 lines
Rationale: Encapsulates all GitHub API interactions in one place
5.
logs_display.go(Output & Rendering)Responsibility: Table formatting, metrics display, console output
Functions to move:
displayLogsOverview()(lines 1090-1272)Estimated LOC: ~200 lines
Rationale: Separates presentation logic from data operations
6.
logs_utils.go(Utility Functions)Responsibility: Helper functions for workflow discovery and common operations
Functions to move:
getAgenticWorkflowNames()(lines 1273-1332)contains()(lines 1335-1342)Estimated LOC: ~100 lines
Rationale: Keeps utilities separate and easily reusable
Shared Types & Constants
Create
logs_types.goto hold:var logsLog = logger.New("cli:logs")Estimated LOC: ~100 lines
Test Coverage Plan
The existing test file
logs_test.go(1,646 lines) already provides excellent coverage. When splitting the file:Testing Strategy
make test-unitpassesOptional Test Organization
Consider splitting
logs_test.goto match the new structure (optional, not required):logs_command_test.go- Command flag parsing testslogs_orchestrator_test.go- Main workflow testslogs_download_test.go- Concurrent download testslogs_github_api_test.go- API integration testslogs_display_test.go- Output formatting testsTarget Coverage: Maintain current >80% coverage for all new files
Implementation Guidelines
Phase 1: Create Shared Types File
pkg/cli/logs_types.gologs.go💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.