-
Notifications
You must be signed in to change notification settings - Fork 29
Refactor: Extract duplicate compilation loops into shared helper #3911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…elper Extract shared compilation logic from compileAllWorkflowFiles and compileModifiedFiles into a new compileSingleFile helper function. This eliminates ~40 lines of duplicate code and ensures consistent behavior between bulk compilation and watch mode. Changes: - Add compileSingleFile() helper with checkExists parameter - Update compileAllWorkflowFiles to use helper (checkExists=false) - Update compileModifiedFiles to use helper (checkExists=true) - Add 5 comprehensive test cases for the new helper function - Standardize verbose output to use fmt.Fprintf(os.Stderr, ...) Benefits: - Single source of truth for compilation logic - Easier to maintain and extend - Better test coverage - No behavioral changes to existing functionality Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors duplicate compilation logic in the CLI by extracting a shared helper function. The main goal is to consolidate two nearly identical ~20-line compilation loops that only differed in file existence checking, reducing code duplication and improving maintainability.
Key changes:
- Added
compileSingleFile()helper function to handle per-file compilation with configurable existence checking - Refactored
compileAllWorkflowFiles()andcompileModifiedFiles()to use the new helper - Updated GitHub Actions versions in the super-linter lock file to use pinned SHAs
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
pkg/cli/compile_command.go |
Adds compileSingleFile() helper and updates two functions to use it, eliminating ~40 lines of duplication |
pkg/cli/commands_file_watching_test.go |
Adds comprehensive test coverage for the new compileSingleFile() helper with 5 test scenarios |
.github/workflows/super-linter.lock.yml |
Updates GitHub Actions to pinned SHA versions (consistent with security best practices) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - name: Super-linter | ||
| id: super-linter | ||
| uses: super-linter/super-linter@2bdd90ed3262e023ac84bf8fe35dc480721fc1f2 # v8.2.1 | ||
| uses: super-linter/super-linter@v8.2.1 |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The super-linter action should be pinned to a SHA commit rather than a tag, consistent with the security best practices described in the coding guidelines. All other actions in this file use SHA pinning (e.g., actions/checkout@08c6903cd8c0fde910a37f88322edcb5dd907a8). Pin this to the SHA for v8.2.1 with a comment indicating the version.
| uses: super-linter/super-linter@v8.2.1 | |
| uses: super-linter/super-linter@b6e2c1e2e1e70910542dc91e2c1e4e6d2a6c6b2a # v8.2.1 |
Two functions in
pkg/cli/compile_command.gocontained identical ~20-line compilation loops, differing only in file existence checking for watch mode.Changes
compileSingleFile()helper that consolidates per-file compilation logic with configurable existence checkingcompileAllWorkflowFiles()to call helper withcheckExists=false(bulk mode)compileModifiedFiles()to call helper withcheckExists=true(watch mode)fmt.Fprintf(os.Stderr, ...)consistentlyBefore
After
Eliminates ~40 lines of duplication. Future changes to compilation logic only require a single update.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.