Conversation
- Adds updateLicenseHolder() function to auto-detect and replace HashiCorp copyright holders - Detects 'HashiCorp, Inc.', 'HashiCorp Inc', and 'HashiCorp' patterns - Works with all comment styles (Go, Python, Shell, C-style, HTML) - Preserves existing year information and updates to current format - Modifies processFile() to attempt holder update for files with existing licenses - Adds comprehensive test coverage with 14 test cases - Updates README with automatic migration feature documentation This feature ensures old HashiCorp headers are automatically caught and updated, preventing regressions from old PRs or copied code.
- Remove verbose flag check so files are always displayed during updates - Show '(copyright holder updated)' when HashiCorp->IBM migration happens - Show '(license header added)' when new headers are added - Improves visibility in both --plan and regular mode
- Add error check for os.Remove in test to satisfy errcheck linter - Remove ineffectual assignment to modified variable
- Add wouldUpdateLicenseHolder() function for dry-run detection of copyright holder changes - Modify processFile() to check for potential holder updates in checkonly/plan mode - Add test coverage for wouldUpdateLicenseHolder() function - Now --plan flag shows both missing headers and files that would have copyright holders updated from HashiCorp to IBM - Fix golangci-lint issues (errcheck and ineffassign) - Update .copywrite.hcl copyright_year configuration - Tested: reduced false positives from 29 to 5 files, correctly shows holder updates
- Add error check for tmpfile.Close() in TestWouldUpdateLicenseHolder
d7cdc4c to
19c688d
Compare
| updated, err := updateLicenseHolder(f.path, f.mode, license) | ||
| if err != nil { | ||
| logger.Printf("%s: %v", f.path, err) | ||
| return err | ||
| } |
There was a problem hiding this comment.
I'm not sure why this is only getting triggered in this branch/PR but when I run copywrite headers against a repository with a directory in it - perhaps a directory name of a specific pattern - it fails here with the following error:
Error: read releases/testdata/mock_api_tf_0_14_with_prereleases/terraform/0.14.11: is a directory
https://github.com/hashicorp/hc-install
It puzzles me why does a directory even get this far past
Lines 280 to 282 in 0be59e7
There was a problem hiding this comment.
Thanks for catching this:
Solution: Added isDirectory() helper using os.Stat() (follows symlinks) in both migration functions. Now directories are skipped gracefully instead of crashing.
Commit: 0a3f20d - please test with the updated branch.
- Add isDirectory helper function to check for directories and symlinks to directories - Use helper in updateLicenseHolder and wouldUpdateLicenseHolder functions - Resolves issue where filepath.Walk's fi.IsDir() misses symlinks to directories - Fixes error: 'read path: is a directory' reported in PR feedback This prevents crashes when processing repositories with symbolic links that point to directories, such as version directories in test fixtures.
radeksimko
left a comment
There was a problem hiding this comment.
The last revision resolves the problem with directories 👍🏻 - my only remaining ask would be to add a test case for this, to ensure it doesn't break with any future updates. Would you mind adding one?
🛠️ Description
Problem: When migrating from HashiCorp to IBM, old copyright headers with "HashiCorp, Inc.", "HashiCorp Inc", or "HashiCorp" needed to be manually updated, leading to inconsistency and potential regressions from old PRs or copied code.
Solution: Added automatic detection and replacement of HashiCorp copyright holders to IBM Corp format.
Why this approach:
🔗 External Links
https://hashicorp.atlassian.net/browse/CCEN-223
👍 Definition of Done
🤔 Can be merged upon approval? [Yes]
✅
PCI review checklist
I have documented a clear reason for, and description of, the change I am making.
If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.
If applicable, I've documented the impact of any changes to security controls.
Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.