github

package
v0.0.0-...-04628bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareProtectionRules

func CompareProtectionRules(rules []*ProtectionRule) map[string][]string

CompareProtectionRules compares protection rules across repositories

func ComputeBranchStats

func ComputeBranchStats(runs []RunTiming, baseBranch string) map[string]*BranchStats

func ComputeJobStats

func ComputeJobStats(runs []RunTiming) map[string]*JobStats

func ComputeWorkflowStats

func ComputeWorkflowStats(runs []RunTiming) map[string]*WorkflowStats

func FilterByCommit

func FilterByCommit(commits ...string) func(TestRun) bool

FilterByCommit creates a filter for specific commits Higher-order function for functional composition

func FilterByRepository

func FilterByRepository(repos ...string) func(TestRun) bool

FilterByRepository creates a filter for specific repositories Higher-order function returning a filter predicate

func FormatAsJSON

func FormatAsJSON(contexts []*ErrorContext) (string, error)

FormatAsJSON formats error context as JSON for AI consumption Pure function: serializes to JSON

func FormatAsMarkdown

func FormatAsMarkdown(contexts []*ErrorContext) string

FormatAsMarkdown formats error context as Markdown for AI consumption Pure function: generates Markdown string

func FormatDuration

func FormatDuration(d time.Duration) string

func GroupSecretsByScope

func GroupSecretsByScope(secrets []Secret) map[string][]Secret

GroupSecretsByScope groups secrets by their scope (org/repo) Pure function: creates grouped map

func ScanWorkflowForSecrets

func ScanWorkflowForSecrets(workflowContent string) []string

ScanWorkflowForSecrets extracts secret references from workflow YAML Pure function: parses YAML content for secrets.* references

func SortRunsByDate

func SortRunsByDate(runs []RunTiming, ascending bool)

Types

type Branch

type Branch struct {
	Name           string
	SHA            string
	Protected      bool
	Ahead          int
	Behind         int
	LastCommitDate time.Time
}

Branch represents a GitHub branch

type BranchStats

type BranchStats struct {
	Branch         string
	TotalRuns      int
	AvgDuration    time.Duration
	WorkflowStats  map[string]*WorkflowStats
	DeltaVsBase    float64
	DeltaVsBasePct float64
}

type BranchWithComparison

type BranchWithComparison struct {
	Branch
	ComparedTo string
}

BranchWithComparison extends Branch with comparison data

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the GitHub API client

func NewClient

func NewClient(ctx context.Context) (*Client, error)

NewClient creates a new GitHub API client It will use gh CLI authentication if available, or fall back to GITHUB_TOKEN env var

func NewClientWithToken

func NewClientWithToken(ctx context.Context, token string) (*Client, error)

NewClientWithToken creates a new GitHub API client with an explicit token

func (*Client) AddCollaborator

func (c *Client) AddCollaborator(owner, repo, username, permission string) error

AddCollaborator adds a collaborator to a repository

func (*Client) CompareBranches

func (c *Client) CompareBranches(owner, repo, base, head string) (ahead, behind int, err error)

CompareBranches compares two branches and returns ahead/behind counts

func (*Client) Context

func (c *Client) Context() context.Context

Context returns the client's context

func (*Client) CreatePullRequest

func (c *Client) CreatePullRequest(owner, repo, title, body, head, base string) (int, error)

CreatePullRequest creates a new pull request

func (*Client) Delete

func (c *Client) Delete(path string, response interface{}) error

Delete performs a DELETE request to the GitHub API

func (*Client) DeleteBranch

func (c *Client) DeleteBranch(owner, repo, branch string) error

DeleteBranch deletes a branch

func (*Client) DeleteRepoSubscription

func (c *Client) DeleteRepoSubscription(owner, repo string) error

func (*Client) FetchRunDetails

func (c *Client) FetchRunDetails(owner, repo string, runID int) (*RunTiming, error)

func (*Client) FetchWorkflowRuns

func (c *Client) FetchWorkflowRuns(owner, repo string, opts FetchWorkflowRunsOptions) ([]RunTiming, error)

func (*Client) FetchWorkflowRunsWithDetails

func (c *Client) FetchWorkflowRunsWithDetails(owner, repo string, opts FetchWorkflowRunsOptions) ([]RunTiming, error)

func (*Client) Get

func (c *Client) Get(path string, response interface{}) error

Get performs a GET request to the GitHub API

func (*Client) GetAuthenticatedUser

func (c *Client) GetAuthenticatedUser() (string, error)

func (*Client) GetBranchProtection

func (c *Client) GetBranchProtection(owner, repo, branch string) (*ProtectionRule, error)

GetBranchProtection retrieves branch protection rules

func (*Client) GetBranchesWithComparison

func (c *Client) GetBranchesWithComparison(owner, repo, baseBranch string) ([]BranchWithComparison, error)

GetBranchesWithComparison fetches branches and compares them to a base branch

func (*Client) GetDefaultBranch

func (c *Client) GetDefaultBranch(owner, repo string) (string, error)

GetDefaultBranch fetches the default branch for a repository

func (*Client) GetLatestRelease

func (c *Client) GetLatestRelease(owner, repo string) (*Release, error)

GetLatestRelease returns the most recent release

func (*Client) GetPullRequestsForBranch

func (c *Client) GetPullRequestsForBranch(owner, repo, branch string) ([]PullRequest, error)

func (*Client) GetRepoSettings

func (c *Client) GetRepoSettings(owner, repo string) (*RepoSettings, error)

GetRepoSettings retrieves repository settings

func (*Client) GetRepoSubscription

func (c *Client) GetRepoSubscription(owner, repo string) (*Subscription, error)

func (*Client) ListBranches

func (c *Client) ListBranches(owner, repo string) ([]Branch, error)

ListBranches lists all branches for a repository

func (*Client) ListCollaborators

func (c *Client) ListCollaborators(owner, repo string) ([]Collaborator, error)

ListCollaborators lists all collaborators for a repository

func (*Client) ListNamespaceRepositories

func (c *Client) ListNamespaceRepositories(namespace string) ([]Repository, bool, error)

func (*Client) ListOrgRepositories

func (c *Client) ListOrgRepositories(org string) ([]Repository, error)

func (*Client) ListOrgSecrets

func (c *Client) ListOrgSecrets(org string) ([]Secret, error)

ListOrgSecrets lists organization-level secrets

func (*Client) ListPRComments

func (c *Client) ListPRComments(owner, repo string, prNumber int) ([]Comment, error)

ListPRComments lists all comments for a pull request

func (*Client) ListPullRequests

func (c *Client) ListPullRequests(owner, repo, state string) ([]PullRequest, error)

func (*Client) ListReleases

func (c *Client) ListReleases(owner, repo string) ([]Release, error)

ListReleases lists all releases for a repository

func (*Client) ListRepoSecrets

func (c *Client) ListRepoSecrets(owner, repo string) ([]Secret, error)

ListRepoSecrets lists repository-level secrets

func (*Client) ListUserRepos

func (c *Client) ListUserRepos() ([]RepoBasic, error)

func (*Client) ListUserRepositories

func (c *Client) ListUserRepositories(username string) ([]Repository, error)

func (*Client) ListWebhookDeliveries

func (c *Client) ListWebhookDeliveries(owner, repo string, hookID int) ([]WebhookDelivery, error)

ListWebhookDeliveries lists recent deliveries for a webhook

func (*Client) ListWebhooks

func (c *Client) ListWebhooks(owner, repo string) ([]Webhook, error)

ListWebhooks lists all webhooks for a repository

func (*Client) ListWorkflowRuns

func (c *Client) ListWorkflowRuns(owner, repo string) ([]WorkflowRun, error)

ListWorkflowRuns lists workflow runs for a repository

func (*Client) ListWorkflows

func (c *Client) ListWorkflows(owner, repo string) ([]WorkflowFile, error)

func (*Client) Patch

func (c *Client) Patch(path string, body interface{}, response interface{}) error

Patch performs a PATCH request to the GitHub API

func (*Client) Post

func (c *Client) Post(path string, body interface{}, response interface{}) error

Post performs a POST request to the GitHub API

func (*Client) Put

func (c *Client) Put(path string, body interface{}, response interface{}) error

Put performs a PUT request to the GitHub API

func (*Client) RemoveCollaborator

func (c *Client) RemoveCollaborator(owner, repo, username string) error

RemoveCollaborator removes a collaborator from a repository

func (*Client) SetRepoSubscription

func (c *Client) SetRepoSubscription(owner, repo string, subscribed, ignored bool) (*Subscription, error)

type Collaborator

type Collaborator struct {
	Login      string
	Permission string
	Repository string
}

Collaborator represents a repository collaborator

type CollaboratorGrant

type CollaboratorGrant struct {
	User       string
	Repository string
	Permission string
	GrantedBy  string
	GrantedAt  time.Time
	ExpiresAt  time.Time
	RevokedAt  *time.Time
}

CollaboratorGrant represents a time-boxed access grant

type Comment

type Comment struct {
	ID          int
	Repository  string
	PRNumber    int
	Author      string
	Body        string
	Path        string
	Line        int
	CreatedAt   time.Time
	UpdatedAt   time.Time
	InReplyToID *int
	Resolved    bool
}

Comment represents a PR review comment

func FilterUnresolvedComments

func FilterUnresolvedComments(comments []Comment) []Comment

FilterUnresolvedComments filters comments to only unresolved ones

type DuplicateSecret

type DuplicateSecret struct {
	Name   string
	Count  int
	Scopes []string // List of scopes where it appears
	Repos  []string // List of repositories (for repo-scoped secrets)
}

DuplicateSecret represents a secret name that appears multiple times

func FindDuplicateSecrets

func FindDuplicateSecrets(secrets []Secret) []DuplicateSecret

FindDuplicateSecrets identifies secret names that appear in multiple scopes/repos Pure function: analyzes secret list for duplicates

type ErrorContext

type ErrorContext struct {
	Repository   string    `json:"repository"`
	WorkflowName string    `json:"workflow_name"`
	JobName      string    `json:"job_name"`
	StepName     string    `json:"step_name,omitempty"`
	Conclusion   string    `json:"conclusion"`
	Timestamp    time.Time `json:"timestamp"`
	ErrorLines   []string  `json:"error_lines"`
	Context      []string  `json:"context_lines,omitempty"`
	ErrorType    string    `json:"error_type,omitempty"`
	Summary      string    `json:"summary"`
}

ErrorContext represents extracted error information

func BatchExtractErrors

func BatchExtractErrors(logs []JobLog, workflow string, config LogExtractionConfig) []*ErrorContext

BatchExtractErrors extracts errors from multiple logs Pure function: maps over logs

func ExtractErrorContext

func ExtractErrorContext(log JobLog, workflow string, config LogExtractionConfig) *ErrorContext

ExtractErrorContext extracts actionable error information from job logs Pure function: deterministic, no side effects

type FetchWorkflowRunsOptions

type FetchWorkflowRunsOptions struct {
	WorkflowFile string
	Branch       string
	Status       string
	Limit        int
	CreatedAfter time.Time
}

type FlakyDetectionConfig

type FlakyDetectionConfig struct {
	MinFlips       int     // Minimum flips to be considered flaky
	MinFailureRate float64 // Minimum failure rate (0.0-1.0)
	TimeWindow     time.Duration
	SameCommitOnly bool // Only detect same-commit flips
	IncludeSkipped bool // Include skipped tests in analysis
}

FlakyDetectionConfig configures flaky test detection

func DefaultFlakyConfig

func DefaultFlakyConfig() FlakyDetectionConfig

DefaultFlakyConfig returns sensible defaults

type FlakyTest

type FlakyTest struct {
	Name         string
	FailureRate  float64
	FirstFailure time.Time
	LastFlip     time.Time
	FlipCount    int
	TotalRuns    int
	FailureCount int
	Pattern      string // "same-commit-flip", "intermittent", "consistent"
}

FlakyTest represents a test that exhibits flaky behavior

func DetectFlakyTests

func DetectFlakyTests(runs []TestRun, config FlakyDetectionConfig) []FlakyTest

DetectFlakyTests identifies flaky tests from test runs Pure function: no side effects, deterministic output

type JobLog

type JobLog struct {
	JobID      int
	JobName    string
	WorkflowID int
	Repository string
	Conclusion string
	Lines      []string
	Timestamp  time.Time
}

JobLog represents a GitHub Actions job log

type JobStats

type JobStats struct {
	WorkflowJob string
	TotalRuns   int
	AvgDuration time.Duration
	MinDuration time.Duration
	MaxDuration time.Duration
}

func GetTopJobsByDuration

func GetTopJobsByDuration(stats map[string]*JobStats, limit int) []*JobStats

type JobTiming

type JobTiming struct {
	Name            string        `json:"name"`
	DurationSeconds float64       `json:"duration_seconds"`
	Status          string        `json:"status"`
	Conclusion      string        `json:"conclusion"`
	StartedAt       time.Time     `json:"started_at"`
	CompletedAt     time.Time     `json:"completed_at"`
	Duration        time.Duration `json:"-"`
	Steps           []StepTiming  `json:"steps"`
}

type LogExtractionConfig

type LogExtractionConfig struct {
	TailLines         int      // Number of lines from end of log
	ContextLines      int      // Additional context lines around errors
	FilterNoise       bool     // Remove timestamps, ANSI codes
	ExtractStackTrace bool     // Include full stack traces
	IncludeSuccess    bool     // Include successful runs
	ErrorPatterns     []string // Custom regex patterns for errors
}

LogExtractionConfig configures log extraction behavior

func DefaultLogConfig

func DefaultLogConfig() LogExtractionConfig

DefaultLogConfig returns sensible defaults for log extraction

type PRRef

type PRRef struct {
	Ref  string
	SHA  string
	Repo string
}

type ProtectionRule

type ProtectionRule struct {
	Repository              string
	Branch                  string
	RequiredReviews         int
	RequireCodeOwnerReviews bool
	RequireStatusChecks     []string
	EnforceAdmins           bool
	RequireLinearHistory    bool
	AllowForcePushes        bool
	AllowDeletions          bool
}

ProtectionRule represents branch protection settings

type PullRequest

type PullRequest struct {
	Number   int
	Title    string
	State    string
	Head     PRRef
	Base     PRRef
	MergedAt *time.Time
	ClosedAt *time.Time
}

type Release

type Release struct {
	ID          int
	Repository  string
	TagName     string
	Name        string
	Body        string
	Author      string
	CreatedAt   time.Time
	PublishedAt time.Time
	Draft       bool
	Prerelease  bool
}

Release represents a GitHub release

type ReleaseComparison

type ReleaseComparison struct {
	Repositories   []string
	LatestReleases map[string]*Release
	OutdatedRepos  []string // Repos with no release in 90+ days
	NonSemVerRepos []string // Repos not following semver
}

ReleaseComparison compares releases across repositories

func CompareReleases

func CompareReleases(releases map[string]*Release) ReleaseComparison

CompareReleases compares releases across multiple repositories

type RepoBasic

type RepoBasic struct {
	Name     string
	FullName string
	Owner    string
	Private  bool
}

type RepoSettings

type RepoSettings struct {
	Repository          string
	DefaultBranch       string
	AllowMergeCommit    bool
	AllowSquashMerge    bool
	AllowRebaseMerge    bool
	DeleteBranchOnMerge bool
	HasIssues           bool
	HasProjects         bool
	HasWiki             bool
}

RepoSettings represents repository settings

type Repository

type Repository struct {
	Name          string
	FullName      string
	Owner         string
	Private       bool
	Archived      bool
	DefaultBranch string
}

type RunTiming

type RunTiming struct {
	RunID           int           `json:"run_id"`
	Workflow        string        `json:"workflow"`
	WorkflowID      int           `json:"workflow_id"`
	Branch          string        `json:"branch"`
	HeadSHA         string        `json:"head_sha"`
	Conclusion      string        `json:"conclusion"`
	CreatedAt       time.Time     `json:"created_at"`
	UpdatedAt       time.Time     `json:"updated_at"`
	DurationSeconds float64       `json:"duration_seconds"`
	Duration        time.Duration `json:"-"`
	Jobs            []JobTiming   `json:"jobs"`
}

func FilterRunsByBranch

func FilterRunsByBranch(runs []RunTiming, branch string) []RunTiming

func FilterRunsByTimeRange

func FilterRunsByTimeRange(runs []RunTiming, since, until time.Time) []RunTiming

func FilterRunsByWorkflows

func FilterRunsByWorkflows(runs []RunTiming, workflows []string) []RunTiming

type Secret

type Secret struct {
	Name       string
	Scope      string // "org" or "repo"
	Repository string // Empty for org secrets
	CreatedAt  string
	UpdatedAt  string
}

Secret represents a GitHub Actions secret

type SecretUsage

type SecretUsage struct {
	Name         string
	Scope        string
	Repository   string
	ReferencedIn []string // Workflow files that reference this secret
	Unused       bool
}

SecretUsage tracks secret usage in workflows

func DetectUnusedSecrets

func DetectUnusedSecrets(secrets []Secret, workflowRefs map[string][]string) []SecretUsage

DetectUnusedSecrets compares secrets against workflow references

type SettingsDiff

type SettingsDiff struct {
	Field    string
	Baseline interface{}
	Current  interface{}
	Severity string // critical, warning, info
}

SettingsDiff represents differences between repository settings

func CompareSettings

func CompareSettings(baseline, current *RepoSettings) []SettingsDiff

CompareSettings compares repository settings against a baseline

type StepTiming

type StepTiming struct {
	Name            string        `json:"name"`
	DurationSeconds float64       `json:"duration_seconds"`
	Status          string        `json:"status"`
	Conclusion      string        `json:"conclusion"`
	StartedAt       time.Time     `json:"started_at"`
	CompletedAt     time.Time     `json:"completed_at"`
	Duration        time.Duration `json:"-"`
}

type Subscription

type Subscription struct {
	Repository string
	Subscribed bool
	Ignored    bool
	Reason     string
	CreatedAt  time.Time
	State      WatchState
}

type TestRun

type TestRun struct {
	Name       string
	Status     string // "success", "failure", "skipped"
	CommitSHA  string
	Timestamp  time.Time
	Duration   time.Duration
	Repository string
	WorkflowID int
}

TestRun represents a single test execution

func ApplyFilters

func ApplyFilters(runs []TestRun, filters ...func(TestRun) bool) []TestRun

ApplyFilters applies a list of filters to test runs Functional composition helper

type WatchState

type WatchState string
const (
	WatchStateSubscribed  WatchState = "subscribed"
	WatchStateIgnored     WatchState = "ignored"
	WatchStateNotWatching WatchState = ""
)

type Webhook

type Webhook struct {
	ID         int
	Repository string
	URL        string
	Events     []string
	Active     bool
}

Webhook represents a repository webhook

type WebhookDelivery

type WebhookDelivery struct {
	ID        int
	Event     string
	Status    int
	Duration  int // milliseconds
	Timestamp string
}

WebhookDelivery represents a webhook delivery

type WebhookHealth

type WebhookHealth struct {
	WebhookID       int
	SuccessRate     float64
	TotalDeliveries int
	Failures        int
	AvgDuration     int
}

WebhookHealth represents webhook health metrics

func AnalyzeWebhookHealth

func AnalyzeWebhookHealth(deliveries []WebhookDelivery) WebhookHealth

AnalyzeWebhookHealth analyzes webhook delivery health

type WorkflowFile

type WorkflowFile struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Path  string `json:"path"`
	State string `json:"state"`
}

type WorkflowRun

type WorkflowRun struct {
	ID         int
	Name       string
	Status     string
	Conclusion string
	Branch     string
	HeadSHA    string
	CreatedAt  time.Time
	UpdatedAt  time.Time
	Duration   time.Duration
}

WorkflowRun represents a GitHub Actions workflow run

type WorkflowRunStats

type WorkflowRunStats struct {
	TotalRuns    int
	SuccessRate  float64
	FailureCount int
	AvgDuration  time.Duration
	Runs         []WorkflowRun
}

WorkflowRunStats represents statistics about workflow runs

func AnalyzeWorkflowRuns

func AnalyzeWorkflowRuns(runs []WorkflowRun) WorkflowRunStats

AnalyzeWorkflowRuns analyzes workflow runs and returns statistics

type WorkflowStats

type WorkflowStats struct {
	Workflow     string
	TotalRuns    int
	AvgDuration  time.Duration
	MinDuration  time.Duration
	MaxDuration  time.Duration
	SuccessRate  float64
	FailureCount int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL