Skip to content

Auto migrate hashicorp to ibm#189

Open
CreatorHead wants to merge 6 commits intomainfrom
auto-migrate-hashicorp-to-ibm
Open

Auto migrate hashicorp to ibm#189
CreatorHead wants to merge 6 commits intomainfrom
auto-migrate-hashicorp-to-ibm

Conversation

@CreatorHead
Copy link
Contributor

🛠️ 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:

  • Prevents regressions: Automatically catches old HashiCorp headers that might slip through
  • Zero configuration: Works transparently without additional flags
  • Format consistency: Ensures all headers follow the same IBM Corp. format
  • Comprehensive coverage: Handles all common comment styles and copyright variations

🔗 External Links

https://hashicorp.atlassian.net/browse/CCEN-223

👍 Definition of Done

  • New functionality works? [Yes]
  • Tests added? [Yes]

🤔 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.

@CreatorHead CreatorHead requested a review from a team as a code owner February 3, 2026 11:02
- 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
@CreatorHead CreatorHead force-pushed the auto-migrate-hashicorp-to-ibm branch from d7cdc4c to 19c688d Compare February 6, 2026 08:40
Comment on lines +276 to +280
updated, err := updateLicenseHolder(f.path, f.mode, license)
if err != nil {
logger.Printf("%s: %v", f.path, err)
return err
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

if fi.IsDir() {
return nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants