Add URL parsing support to audit command for cross-repository and GitHub Enterprise auditing #2052
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.
Audit Command URL Parsing Enhancement - COMPLETE ✅
Add support for extracting owner/repo and API root from workflow run URLs in the audit command.
Plan
extractRunIDto also extract owner, repo, and API hostname from URLsfetchWorkflowRunMetadatato accept and use explicit owner/repo instead of relying on{owner}/{repo}placeholders/actions/runs/and/runs/URL patternsLatest Changes
Fixed compilation error introduced during merge where
runIDvariable was used instead ofrunInfo.RunIDon line 310. Code is now properly formatted and all tests pass.Implementation Summary
The audit command can now accept workflow run URLs from any repository and GitHub instance, properly extracting all necessary information to make the correct API calls.
Key Features
1. RunURLInfo Struct
2. Enhanced URL Parsing
/actions/runs/and/runs/patterns3. Supported URL Patterns
1234567890https://github.com/owner/repo/actions/runs/12345678https://github.com/owner/repo/runs/12345678https://github.com/owner/repo/actions/runs/12345678/job/98765432https://github.example.com/org/repo/actions/runs/99999API Call Examples
Numeric ID (uses current repo context):
gh api repos/{owner}/{repo}/actions/runs/1234567890 --jq {...}GitHub URL (uses explicit owner/repo):
gh api repos/owner/repo/actions/runs/12345678 --jq {...}Enterprise URL (uses hostname flag):
gh api --hostname github.example.com repos/org/repo/actions/runs/99999 --jq {...}Test Coverage
New Tests:
TestParseRunURL: 8 comprehensive test cases covering all URL patternsTestExtractRunID: 10 test cases including new URL patternsTest Results: ✅ All tests pass
Benefits
✅ Cross-repository auditing: Audit runs from any repository by providing the URL
✅ GitHub Enterprise support: Works with custom GitHub domains
✅ Multiple URL formats: Handles various GitHub URL patterns
✅ Backward compatible: Numeric IDs still work as before
✅ Proper API root resolution: Correctly identifies and uses the GitHub instance
Code Quality Checks
✅ All unit tests pass (
make test-unit)✅ Code formatted (
make fmt)✅ Linter passes (
make lint)✅ Build succeeds (
make build)✅ Help text updated and verified
✅ Manual testing confirms functionality
Files Changed
pkg/cli/audit.go- Enhanced URL parsing and API calls, fixed merge issuepkg/cli/audit_test.go- Comprehensive test coverageProblem Statement Addressed
The implementation successfully resolves all requirements:
/actions/runs/and/runs/patternsThe audit command is now fully functional for auditing workflow runs from any repository and GitHub instance!
Original prompt
💡 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.