-
Notifications
You must be signed in to change notification settings - Fork 127
External PR 1410: Refactor the inconsistent access token resolution between ENV and CLI args #1481
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
Unit Test Results 1 files 1 suites 10m 25s ⏱️ Results for commit 75e8af6. ♻️ This comment has been updated with latest results. |
…gh-gei into brianaj/external-pr-1410 # Conflicts: # RELEASENOTES.md
- Add test Should_Pass_Source_Pat_From_Cli_Args_To_Factory to verify source PAT from CLI args is passed to factory - Add test Should_Pass_Target_Pat_From_Cli_Args_To_Factory to verify target PAT from CLI args is passed to factory - Tests prove that CLI args are properly passed through to the factory, demonstrating the bug fix works
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 fixes a bug in alert migration commands where tokens provided via CLI arguments were being ignored when environment variables were not set. The fix refactors token resolution to be handled consistently by the factory classes, with proper fallback logic from CLI args → environment variables → validation errors.
Key changes:
- Moved token resolution and validation logic from command classes into factory classes
- Changed environment variable resolution to use
throwIfNotFound=falseto allow CLI args to take precedence - Added explicit validation in factories with user-friendly error messages
- Added tests to verify CLI arguments are properly passed to factories
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/gei/Factories/SecretScanningAlertServiceFactory.cs | Added token resolution from environment variables (with throwIfNotFound=false), token validation with user-friendly errors, and explicit null parameter for uploadsUrl when calling GithubApiFactory |
| src/gei/Factories/CodeScanningAlertServiceFactory.cs | Added token resolution from environment variables (with throwIfNotFound=false), token validation with user-friendly errors, and explicit null parameter for uploadsUrl when calling GithubApiFactory |
| src/gei/Commands/MigrateSecretAlerts/MigrateSecretAlertsCommand.cs | Removed environment variable resolution logic, delegating it to the factory |
| src/gei/Commands/MigrateCodeScanningAlerts/MigrateCodeScanningAlertsCommand.cs | Removed environment variable resolution logic, delegating it to the factory |
| src/OctoshiftCLI.Tests/gei/Commands/MigrateSecretAlerts/MigrateSecretAlertsCommandTests.cs | Added tests to verify CLI arguments are passed correctly to factory |
| src/OctoshiftCLI.Tests/gei/Commands/MigrateCodeScanningAlerts/MigrateCodeScanningAlertsCommandTests.cs | Added tests to verify CLI arguments are passed correctly to factory |
| RELEASENOTES.md | Added user-facing description of the bug fix |
src/OctoshiftCLI.Tests/gei/Commands/MigrateSecretAlerts/MigrateSecretAlertsCommandTests.cs
Outdated
Show resolved
Hide resolved
...iftCLI.Tests/gei/Commands/MigrateCodeScanningAlerts/MigrateCodeScanningAlertsCommandTests.cs
Outdated
Show resolved
Hide resolved
Renamed Source_Pat_Should_Default_To_Target_Pat to Should_Pass_Target_Pat_From_Cli_Args_To_Factory for clarity - the new name better describes what the test is verifying.
External PR from #1410 by @theztefan
This is based on external PR but scoped down to only the alert migration commands that were specifically affected by issue #1409. The original PR included changes to repository and organization migration commands, but those changes were incomplete (missing validation logic). To ship this fix safely, I've limited the scope to only the commands where the fix is complete.