Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 0 additions & 106 deletions pkg/cli/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,116 +12,10 @@ import (
"testing"
"time"

"github.com/github/gh-aw/pkg/parser"
"github.com/github/gh-aw/pkg/testutil"
"github.com/github/gh-aw/pkg/workflow"
)

func TestParseRunURL(t *testing.T) {
tests := []struct {
name string
input string
expectedRunID int64
expectedOwner string
expectedRepo string
expectedHostname string
shouldErr bool
}{
{
name: "Numeric run ID",
input: "1234567890",
expectedRunID: 1234567890,
expectedOwner: "",
expectedRepo: "",
expectedHostname: "",
shouldErr: false,
},
{
name: "Run URL with /actions/runs/",
input: "https://github.com/owner/repo/actions/runs/12345678",
expectedRunID: 12345678,
expectedOwner: "owner",
expectedRepo: "repo",
expectedHostname: "github.com",
shouldErr: false,
},
{
name: "Job URL",
input: "https://github.com/owner/repo/actions/runs/12345678/job/98765432",
expectedRunID: 12345678,
expectedOwner: "owner",
expectedRepo: "repo",
expectedHostname: "github.com",
shouldErr: false,
},
{
name: "Workflow run URL without /actions/",
input: "https://github.com/owner/repo/runs/12345678",
expectedRunID: 12345678,
expectedOwner: "owner",
expectedRepo: "repo",
expectedHostname: "github.com",
shouldErr: false,
},
{
name: "GitHub Enterprise URL",
input: "https://github.example.com/owner/repo/actions/runs/12345678",
expectedRunID: 12345678,
expectedOwner: "owner",
expectedRepo: "repo",
expectedHostname: "github.example.com",
shouldErr: false,
},
{
name: "GitHub Enterprise URL without /actions/",
input: "https://ghe.company.com/myorg/myrepo/runs/99999",
expectedRunID: 99999,
expectedOwner: "myorg",
expectedRepo: "myrepo",
expectedHostname: "ghe.company.com",
shouldErr: false,
},
{
name: "Invalid URL format",
input: "https://github.com/owner/repo/actions",
shouldErr: true,
},
{
name: "Invalid string",
input: "not-a-number",
shouldErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
runID, owner, repo, hostname, err := parser.ParseRunURL(tt.input)

if tt.shouldErr {
if err == nil {
t.Errorf("Expected error but got none")
}
} else {
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if runID != tt.expectedRunID {
t.Errorf("Expected run ID %d, got %d", tt.expectedRunID, runID)
}
if owner != tt.expectedOwner {
t.Errorf("Expected owner '%s', got '%s'", tt.expectedOwner, owner)
}
if repo != tt.expectedRepo {
t.Errorf("Expected repo '%s', got '%s'", tt.expectedRepo, repo)
}
if hostname != tt.expectedHostname {
t.Errorf("Expected hostname '%s', got '%s'", tt.expectedHostname, hostname)
}
}
})
}
}

func TestIsPermissionError(t *testing.T) {
tests := []struct {
name string
Expand Down
43 changes: 0 additions & 43 deletions pkg/parser/github_urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"net/url"
"path/filepath"
"strconv"
"strings"

Expand Down Expand Up @@ -303,35 +302,6 @@ func parseRawGitHubContentURL(parsedURL *url.URL) (*GitHubURLComponents, error)
}, nil
}

// ParseRunURL is a convenience function that parses a run ID or URL and extracts run information.
// It accepts:
// - Numeric run ID: "1234567890"
// - GitHub Actions run URL: "https://github.com/owner/repo/actions/runs/12345678"
// - Short run URL: "https://github.com/owner/repo/runs/12345678"
// - Job URL: "https://github.com/owner/repo/actions/runs/12345678/job/98765432"
// - Job URL with step: "https://github.com/owner/repo/actions/runs/12345678/job/98765432#step:7:1"
// - Enterprise URLs: "https://github.example.com/owner/repo/actions/runs/12345678"
//
// For deep URLs with job/step information, use ParseRunURLExtended to get all details.
func ParseRunURL(input string) (runID int64, owner, repo, hostname string, err error) {
// First try to parse as a direct numeric ID
if runID, err := strconv.ParseInt(input, 10, 64); err == nil {
return runID, "", "", "", nil
}

// Try to parse as a GitHub URL
components, err := ParseGitHubURL(input)
if err != nil {
return 0, "", "", "", fmt.Errorf("invalid run ID or URL '%s': must be a numeric run ID or a GitHub URL containing '/actions/runs/{run-id}' or '/runs/{run-id}'", input)
}

if components.Type != URLTypeRun {
return 0, "", "", "", errors.New("URL is not a GitHub Actions run URL")
}

return components.Number, components.Owner, components.Repo, components.Host, nil
}

// ParseRunURLExtended is similar to ParseRunURL but returns additional information
// including job ID and step details from deep URLs.
func ParseRunURLExtended(input string) (*GitHubURLComponents, error) {
Expand Down Expand Up @@ -417,16 +387,3 @@ func IsValidGitHubIdentifier(s string) bool {
}
return true
}

// GetRepoSlug returns the repository slug in "owner/repo" format
func (c *GitHubURLComponents) GetRepoSlug() string {
return fmt.Sprintf("%s/%s", c.Owner, c.Repo)
}

// GetWorkflowName returns the workflow name from a file path (without .md extension)
func (c *GitHubURLComponents) GetWorkflowName() string {
if c.Path == "" {
return ""
}
return strings.TrimSuffix(filepath.Base(c.Path), ".md")
}
52 changes: 0 additions & 52 deletions pkg/parser/github_urls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,58 +837,6 @@ func TestIsValidGitHubIdentifier(t *testing.T) {
}
}

func TestGitHubURLComponents_GetRepoSlug(t *testing.T) {
c := &GitHubURLComponents{
Owner: "owner",
Repo: "repo",
}

got := c.GetRepoSlug()
want := "owner/repo"

if got != want {
t.Errorf("GetRepoSlug() = %v, want %v", got, want)
}
}

func TestGitHubURLComponents_GetWorkflowName(t *testing.T) {
tests := []struct {
name string
path string
want string
}{
{
name: "Markdown file",
path: "workflows/my-workflow.md",
want: "my-workflow",
},
{
name: "Nested path",
path: ".github/workflows/release.md",
want: "release",
},
{
name: "Empty path",
path: "",
want: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &GitHubURLComponents{
Path: tt.path,
}

got := c.GetWorkflowName()

if got != tt.want {
t.Errorf("GetWorkflowName() = %v, want %v", got, tt.want)
}
})
}
}

// TestParseGitHubURL_AdditionalEdgeCases tests additional edge cases for comprehensive coverage
func TestParseGitHubURL_AdditionalEdgeCases(t *testing.T) {
tests := []struct {
Expand Down
5 changes: 0 additions & 5 deletions pkg/parser/schema_compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,3 @@ func formatSchemaFailureDetail(pathInfo JSONPathInfo, schemaJSON, frontmatterCon
}
return fmt.Sprintf("at '%s' (line %d, column %d): %s", path, line, column, message)
}

// GetMainWorkflowSchema returns the embedded main workflow schema JSON
func GetMainWorkflowSchema() string {
return mainWorkflowSchema
}
Loading