github

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package github provides sanitization utilities for log content.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsPotentialSecrets

func ContainsPotentialSecrets(content string) bool

ContainsPotentialSecrets checks if the content contains potential secrets. Returns true if any secret pattern matches.

func IsRetryable

func IsRetryable(err error) bool

IsRetryable returns true if the error can be retried.

func SanitizeLogs

func SanitizeLogs(logs string) string

SanitizeLogs removes potential secrets from log content. It replaces matched patterns with "[REDACTED]".

Types

type AppError

type AppError struct {
	Type       ErrorType
	Message    string        // User-facing message
	Cause      error         // Underlying error
	Retryable  bool          // Whether the operation can be retried
	RetryAfter time.Duration // How long to wait before retrying
}

AppError represents an application-level error with additional context.

func WrapAPIError

func WrapAPIError(err error) *AppError

WrapAPIError wraps a GitHub API error into an AppError.

func (*AppError) Error

func (e *AppError) Error() string

Error implements the error interface.

func (*AppError) Unwrap

func (e *AppError) Unwrap() error

Unwrap returns the underlying error for errors.Is/As support.

type Client

type Client interface {
	// Workflows
	ListWorkflows(ctx context.Context, repo Repository) ([]Workflow, error)

	// Runs
	ListRuns(ctx context.Context, repo Repository, opts *ListRunsOpts) ([]Run, error)
	CancelRun(ctx context.Context, repo Repository, runID int64) error
	RerunWorkflow(ctx context.Context, repo Repository, runID int64) error
	RerunFailedJobs(ctx context.Context, repo Repository, runID int64) error
	TriggerWorkflow(ctx context.Context, repo Repository, workflowFile, ref string, inputs map[string]interface{}) error

	// Jobs
	ListJobs(ctx context.Context, repo Repository, runID int64) ([]Job, error)

	// Logs
	GetJobLogs(ctx context.Context, repo Repository, jobID int64) (string, error)

	// Rate limiting
	RateLimitRemaining() int
}

Client is the interface for GitHub API operations. It enables dependency injection for testing.

func NewClient

func NewClient(token, owner, repoName string) Client

NewClient creates a new GitHub API client

type ErrorType

type ErrorType int

ErrorType represents the type of error.

const (
	ErrTypeNetwork ErrorType = iota
	ErrTypeAuth
	ErrTypeRateLimit
	ErrTypeNotFound
	ErrTypeServer
	ErrTypeUnknown
)

type Job

type Job struct {
	ID         int64
	Name       string
	Status     string // queued, in_progress, completed
	Conclusion string // success, failure, cancelled
	Steps      []Step
}

Job represents a job within a workflow run.

type ListRunsOpts

type ListRunsOpts struct {
	WorkflowID int64
	Branch     string
	Event      string
	Status     string
	PerPage    int
}

ListRunsOpts represents options for listing workflow runs.

type MethodCall

type MethodCall struct {
	Method string
	Args   []interface{}
	Time   time.Time
}

MethodCall records a method invocation.

type MockClient

type MockClient struct {
	// Return values
	Workflows []Workflow
	Runs      []Run
	Jobs      []Job
	Logs      string
	Err       error
	RateLimit int
	// contains filtered or unexported fields
}

MockClient is a test mock with call tracking capabilities.

func (*MockClient) CallCount

func (m *MockClient) CallCount(method string) int

CallCount returns the number of times a method was called.

func (*MockClient) Calls

func (m *MockClient) Calls() []MethodCall

Calls returns a copy of all recorded calls.

func (*MockClient) CancelRun

func (m *MockClient) CancelRun(ctx context.Context, repo Repository, runID int64) error

CancelRun implements Client.CancelRun.

func (*MockClient) GetJobLogs

func (m *MockClient) GetJobLogs(ctx context.Context, repo Repository, jobID int64) (string, error)

GetJobLogs implements Client.GetJobLogs.

func (*MockClient) ListJobs

func (m *MockClient) ListJobs(ctx context.Context, repo Repository, runID int64) ([]Job, error)

ListJobs implements Client.ListJobs.

func (*MockClient) ListRuns

func (m *MockClient) ListRuns(ctx context.Context, repo Repository, opts *ListRunsOpts) ([]Run, error)

ListRuns implements Client.ListRuns.

func (*MockClient) ListWorkflows

func (m *MockClient) ListWorkflows(ctx context.Context, repo Repository) ([]Workflow, error)

ListWorkflows implements Client.ListWorkflows.

func (*MockClient) RateLimitRemaining

func (m *MockClient) RateLimitRemaining() int

RateLimitRemaining implements Client.RateLimitRemaining.

func (*MockClient) RecordCall

func (m *MockClient) RecordCall(method string, args ...interface{})

RecordCall records a method call with its arguments.

func (*MockClient) RerunFailedJobs

func (m *MockClient) RerunFailedJobs(ctx context.Context, repo Repository, runID int64) error

RerunFailedJobs implements Client.RerunFailedJobs.

func (*MockClient) RerunWorkflow

func (m *MockClient) RerunWorkflow(ctx context.Context, repo Repository, runID int64) error

RerunWorkflow implements Client.RerunWorkflow.

func (*MockClient) Reset

func (m *MockClient) Reset()

Reset clears the call history.

func (*MockClient) TriggerWorkflow

func (m *MockClient) TriggerWorkflow(ctx context.Context, repo Repository, workflowFile, ref string, inputs map[string]interface{}) error

TriggerWorkflow implements Client.TriggerWorkflow.

type Repository

type Repository struct {
	Owner string
	Name  string
}

Repository represents a GitHub repository.

func (Repository) FullName

func (r Repository) FullName() string

FullName returns the full repository name in the format "owner/name".

type Run

type Run struct {
	ID         int64
	Name       string
	Status     string // queued, in_progress, completed
	Conclusion string // success, failure, cancelled
	Branch     string
	Event      string // push, pull_request, workflow_dispatch
	CreatedAt  time.Time
	Actor      string
	URL        string
}

Run represents a workflow run.

func (Run) IsFailed

func (r Run) IsFailed() bool

IsFailed returns true if the run has failed.

func (Run) IsRunning

func (r Run) IsRunning() bool

IsRunning returns true if the run is in progress or queued.

type Step

type Step struct {
	Name       string
	Status     string // queued, in_progress, completed
	Conclusion string // success, failure, skipped
	Number     int
}

Step represents a step within a job.

func (Step) IsFailed

func (s Step) IsFailed() bool

IsFailed returns true if the step has failed.

type Workflow

type Workflow struct {
	ID    int64
	Name  string
	Path  string // .github/workflows/ci.yml
	State string // active, disabled
}

Workflow represents a GitHub Actions workflow definition.

Jump to

Keyboard shortcuts

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