Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 21, 2025

Audit Command URL Parsing Enhancement - COMPLETE ✅

Add support for extracting owner/repo and API root from workflow run URLs in the audit command.

Plan

  • Update extractRunID to also extract owner, repo, and API hostname from URLs
  • Create new function to parse full URL information (runID, owner, repo, hostname)
  • Update fetchWorkflowRunMetadata to accept and use explicit owner/repo instead of relying on {owner}/{repo} placeholders
  • Support both /actions/runs/ and /runs/ URL patterns
  • Support GitHub Enterprise URLs with custom hostnames
  • Add tests for new URL patterns (action run URLs, enterprise URLs)
  • Update command documentation with new URL format examples
  • Manually test the command with various URL formats
  • Fix merge conflicts and format code
  • All tests passing

Latest Changes

Fixed compilation error introduced during merge where runID variable was used instead of runInfo.RunID on 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

type RunURLInfo struct {
    RunID    int64   // The workflow run ID
    Owner    string  // Repository owner
    Repo     string  // Repository name
    Hostname string  // GitHub hostname
}

2. Enhanced URL Parsing

  • Parses numeric run IDs (backward compatible)
  • Extracts owner, repo, hostname from URLs
  • Supports both /actions/runs/ and /runs/ patterns
  • Handles GitHub Enterprise custom domains

3. Supported URL Patterns

Input Type Example What Gets Extracted
Numeric ID 1234567890 RunID only, uses current repo context
Standard run URL https://github.com/owner/repo/actions/runs/12345678 RunID, Owner, Repo, Hostname
Workflow run URL https://github.com/owner/repo/runs/12345678 RunID, Owner, Repo, Hostname
Job URL https://github.com/owner/repo/actions/runs/12345678/job/98765432 RunID, Owner, Repo, Hostname
Enterprise URL https://github.example.com/org/repo/actions/runs/99999 RunID, Owner, Repo, Hostname

API 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 patterns
  • Updated TestExtractRunID: 10 test cases including new URL patterns

Test 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 issue
  • pkg/cli/audit_test.go - Comprehensive test coverage

Problem Statement Addressed

The implementation successfully resolves all requirements:

  1. Action run URLs: Supports both /actions/runs/ and /runs/ patterns
  2. Run ID resolution: Correctly extracts run ID from URLs
  3. API root resolution: Properly identifies GitHub hostname (github.com, enterprise, etc.)
  4. Repository resolution: Extracts owner/repo from URLs for cross-repository auditing

The audit command is now fully functional for auditing workflow runs from any repository and GitHub instance!

Original prompt

Add support for "audit" command to take an action run URL or a workflow run URL to perform the auditing. Must resolve the runid, api root and repo properly


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

@pelikhan pelikhan marked this pull request as ready for review October 21, 2025 00:53
Copilot AI changed the title [WIP] Add support for audit command with run URL Add URL parsing support to audit command for cross-repository and GitHub Enterprise auditing Oct 21, 2025
Copilot AI requested a review from pelikhan October 21, 2025 00:54
Copilot finished work on behalf of pelikhan October 21, 2025 00:54
@pelikhan
Copy link
Contributor

@copilot format, lint, and fix tests

Copy link
Contributor Author

Copilot AI commented Oct 21, 2025

@copilot format, lint, and fix tests

Fixed in commit f6b99a1:

  • Fixed undefined runID variable (changed to runInfo.RunID)
  • Formatted code with make fmt
  • All tests now pass
  • Linter passes successfully

Copilot finished work on behalf of pelikhan October 21, 2025 01:01
@pelikhan pelikhan merged commit c48e0af into main Oct 21, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/add-audit-command-support branch October 21, 2025 01:07
github-actions bot added a commit that referenced this pull request Oct 21, 2025
Update CLI and MCP server documentation to reflect recent feature additions:

- Add --timeout option documentation for logs command with caching details
- Add --parse option documentation for audit command
- Add URL support documentation for audit command (cross-repo, GitHub Enterprise)
- Document continuation field in MCP server logs tool for pagination
- Document large output automatic file handling in MCP server (16K token threshold)

These changes document features from PRs #2066, #2064, #2060, #2058, #2052, and #2051.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
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