github

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 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 RetryWithBackoff added in v0.0.12

func RetryWithBackoff(ctx context.Context, maxRetries int, fn func() error) error

RetryWithBackoff executes fn with exponential backoff retry for retryable errors. It retries up to maxRetries times with exponential backoff starting at 1 second. Maximum backoff is capped at 30 seconds.

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.

func (Job) IsCompleted added in v0.0.11

func (j Job) IsCompleted() bool

IsCompleted returns true if the job has completed.

func (Job) IsQueued added in v0.0.11

func (j Job) IsQueued() bool

IsQueued returns true if the job is queued.

type ListRunsOpts

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

ListRunsOpts represents options for listing workflow runs.

type MockClient

type MockClient struct {
	// CancelRunFunc mocks the CancelRun method.
	CancelRunFunc func(ctx context.Context, repo Repository, runID int64) error

	// GetJobLogsFunc mocks the GetJobLogs method.
	GetJobLogsFunc func(ctx context.Context, repo Repository, jobID int64) (string, error)

	// ListJobsFunc mocks the ListJobs method.
	ListJobsFunc func(ctx context.Context, repo Repository, runID int64) ([]Job, error)

	// ListRunsFunc mocks the ListRuns method.
	ListRunsFunc func(ctx context.Context, repo Repository, opts *ListRunsOpts) ([]Run, error)

	// ListWorkflowsFunc mocks the ListWorkflows method.
	ListWorkflowsFunc func(ctx context.Context, repo Repository) ([]Workflow, error)

	// RateLimitRemainingFunc mocks the RateLimitRemaining method.
	RateLimitRemainingFunc func() int

	// RerunFailedJobsFunc mocks the RerunFailedJobs method.
	RerunFailedJobsFunc func(ctx context.Context, repo Repository, runID int64) error

	// RerunWorkflowFunc mocks the RerunWorkflow method.
	RerunWorkflowFunc func(ctx context.Context, repo Repository, runID int64) error

	// TriggerWorkflowFunc mocks the TriggerWorkflow method.
	TriggerWorkflowFunc func(ctx context.Context, repo Repository, workflowFile string, ref string, inputs map[string]interface{}) error
	// contains filtered or unexported fields
}

MockClient is a mock implementation of Client.

func TestSomethingThatUsesClient(t *testing.T) {

	// make and configure a mocked Client
	mockedClient := &MockClient{
		CancelRunFunc: func(ctx context.Context, repo Repository, runID int64) error {
			panic("mock out the CancelRun method")
		},
		GetJobLogsFunc: func(ctx context.Context, repo Repository, jobID int64) (string, error) {
			panic("mock out the GetJobLogs method")
		},
		ListJobsFunc: func(ctx context.Context, repo Repository, runID int64) ([]Job, error) {
			panic("mock out the ListJobs method")
		},
		ListRunsFunc: func(ctx context.Context, repo Repository, opts *ListRunsOpts) ([]Run, error) {
			panic("mock out the ListRuns method")
		},
		ListWorkflowsFunc: func(ctx context.Context, repo Repository) ([]Workflow, error) {
			panic("mock out the ListWorkflows method")
		},
		RateLimitRemainingFunc: func() int {
			panic("mock out the RateLimitRemaining method")
		},
		RerunFailedJobsFunc: func(ctx context.Context, repo Repository, runID int64) error {
			panic("mock out the RerunFailedJobs method")
		},
		RerunWorkflowFunc: func(ctx context.Context, repo Repository, runID int64) error {
			panic("mock out the RerunWorkflow method")
		},
		TriggerWorkflowFunc: func(ctx context.Context, repo Repository, workflowFile string, ref string, inputs map[string]interface{}) error {
			panic("mock out the TriggerWorkflow method")
		},
	}

	// use mockedClient in code that requires Client
	// and then make assertions.

}

func (*MockClient) CancelRun

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

CancelRun calls CancelRunFunc.

func (*MockClient) CancelRunCalls added in v0.0.9

func (mock *MockClient) CancelRunCalls() []struct {
	Ctx   context.Context
	Repo  Repository
	RunID int64
}

CancelRunCalls gets all the calls that were made to CancelRun. Check the length with:

len(mockedClient.CancelRunCalls())

func (*MockClient) GetJobLogs

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

GetJobLogs calls GetJobLogsFunc.

func (*MockClient) GetJobLogsCalls added in v0.0.9

func (mock *MockClient) GetJobLogsCalls() []struct {
	Ctx   context.Context
	Repo  Repository
	JobID int64
}

GetJobLogsCalls gets all the calls that were made to GetJobLogs. Check the length with:

len(mockedClient.GetJobLogsCalls())

func (*MockClient) ListJobs

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

ListJobs calls ListJobsFunc.

func (*MockClient) ListJobsCalls added in v0.0.9

func (mock *MockClient) ListJobsCalls() []struct {
	Ctx   context.Context
	Repo  Repository
	RunID int64
}

ListJobsCalls gets all the calls that were made to ListJobs. Check the length with:

len(mockedClient.ListJobsCalls())

func (*MockClient) ListRuns

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

ListRuns calls ListRunsFunc.

func (*MockClient) ListRunsCalls added in v0.0.9

func (mock *MockClient) ListRunsCalls() []struct {
	Ctx  context.Context
	Repo Repository
	Opts *ListRunsOpts
}

ListRunsCalls gets all the calls that were made to ListRuns. Check the length with:

len(mockedClient.ListRunsCalls())

func (*MockClient) ListWorkflows

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

ListWorkflows calls ListWorkflowsFunc.

func (*MockClient) ListWorkflowsCalls added in v0.0.9

func (mock *MockClient) ListWorkflowsCalls() []struct {
	Ctx  context.Context
	Repo Repository
}

ListWorkflowsCalls gets all the calls that were made to ListWorkflows. Check the length with:

len(mockedClient.ListWorkflowsCalls())

func (*MockClient) RateLimitRemaining

func (mock *MockClient) RateLimitRemaining() int

RateLimitRemaining calls RateLimitRemainingFunc.

func (*MockClient) RateLimitRemainingCalls added in v0.0.9

func (mock *MockClient) RateLimitRemainingCalls() []struct {
}

RateLimitRemainingCalls gets all the calls that were made to RateLimitRemaining. Check the length with:

len(mockedClient.RateLimitRemainingCalls())

func (*MockClient) RerunFailedJobs

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

RerunFailedJobs calls RerunFailedJobsFunc.

func (*MockClient) RerunFailedJobsCalls added in v0.0.9

func (mock *MockClient) RerunFailedJobsCalls() []struct {
	Ctx   context.Context
	Repo  Repository
	RunID int64
}

RerunFailedJobsCalls gets all the calls that were made to RerunFailedJobs. Check the length with:

len(mockedClient.RerunFailedJobsCalls())

func (*MockClient) RerunWorkflow

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

RerunWorkflow calls RerunWorkflowFunc.

func (*MockClient) RerunWorkflowCalls added in v0.0.9

func (mock *MockClient) RerunWorkflowCalls() []struct {
	Ctx   context.Context
	Repo  Repository
	RunID int64
}

RerunWorkflowCalls gets all the calls that were made to RerunWorkflow. Check the length with:

len(mockedClient.RerunWorkflowCalls())

func (*MockClient) TriggerWorkflow

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

TriggerWorkflow calls TriggerWorkflowFunc.

func (*MockClient) TriggerWorkflowCalls added in v0.0.9

func (mock *MockClient) TriggerWorkflowCalls() []struct {
	Ctx          context.Context
	Repo         Repository
	WorkflowFile string
	Ref          string
	Inputs       map[string]interface{}
}

TriggerWorkflowCalls gets all the calls that were made to TriggerWorkflow. Check the length with:

len(mockedClient.TriggerWorkflowCalls())

type Repository

type Repository struct {
	Owner string
	Name  string
}

Repository represents a GitHub repository.

type Run

type Run struct {
	ID         int64
	RunNumber  int // Sequential run number (e.g., 21 for #21)
	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.

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