github

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package github provides interfaces and implementations for interacting with GitHub API.

Package github provides interfaces and implementations for interacting with GitHub API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDependabotBranch

func IsDependabotBranch(branchName string) bool

IsDependabotBranch checks if a branch name indicates Dependabot ownership.

func MatchesBranchPattern

func MatchesBranchPattern(branchName, pattern string) bool

MatchesBranchPattern checks if a branch name matches the given pattern using substring matching.

Types

type ActionResult

type ActionResult struct {
	Action  string
	Success bool
	Error   error
}

ActionResult represents the result of an action on a pull request.

type BranchStatus

type BranchStatus struct {
	UpToDate    bool
	BehindBy    int
	HasConflict bool
}

BranchStatus represents the status of a branch relative to its base.

type CheckStatus

type CheckStatus struct {
	AllPassing bool
	Pending    bool
	NoChecks   bool
	Details    string
}

CheckStatus represents the overall status of checks on a commit.

type Client

type Client interface {
	// ListRepositories lists all repositories in an organization.
	ListRepositories(ctx context.Context, org string) ([]Repository, error)

	// ListPullRequests lists open pull requests for a repository targeting its default branch.
	ListPullRequests(ctx context.Context, owner, repo, defaultBranch string) ([]PullRequest, error)

	// GetPullRequest gets detailed information about a pull request.
	GetPullRequest(ctx context.Context, owner, repo string, number int) (*PullRequest, error)

	// GetCheckStatus gets the check status for a commit.
	GetCheckStatus(ctx context.Context, owner, repo, ref string) (*CheckStatus, error)

	// GetBranchStatus gets the status of a PR branch relative to its base.
	GetBranchStatus(ctx context.Context, owner, repo string, prNumber int) (*BranchStatus, error)

	// UpdateBranch updates a pull request branch with the base branch.
	UpdateBranch(ctx context.Context, owner, repo string, prNumber int) error

	// PostRebaseComment posts a rebase comment on a pull request for Dependabot.
	PostRebaseComment(ctx context.Context, owner, repo string, prNumber int) error

	// MergePullRequest merges a pull request.
	MergePullRequest(ctx context.Context, owner, repo string, prNumber int) error
}

Client defines the interface for GitHub API operations.

type MockClient

type MockClient struct {
	Repositories    []Repository
	PullRequests    map[string][]PullRequest // key: "owner/repo"
	CheckStatuses   map[string]*CheckStatus  // key: "owner/repo/ref"
	BranchStatuses  map[string]*BranchStatus // key: "owner/repo/prNumber"
	UpdateBranchErr map[string]error         // key: "owner/repo/prNumber"
	PostRebaseErr   map[string]error         // key: "owner/repo/prNumber"
	MergeErr        map[string]error         // key: "owner/repo/prNumber"
	ListReposErr    error
	ListPRsErr      map[string]error // key: "owner/repo"
	GetPRErr        map[string]error // key: "owner/repo/prNumber"

	// Track calls for verification
	UpdateBranchCalls []string
	PostRebaseCalls   []string
	MergeCalls        []string
}

MockClient is a mock implementation of the Client interface for testing.

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new MockClient with initialized maps.

func (*MockClient) GetBranchStatus

func (m *MockClient) GetBranchStatus(ctx context.Context, owner, repo string, prNumber int) (*BranchStatus, error)

GetBranchStatus returns mock branch status.

func (*MockClient) GetCheckStatus

func (m *MockClient) GetCheckStatus(ctx context.Context, owner, repo, ref string) (*CheckStatus, error)

GetCheckStatus returns mock check status.

func (*MockClient) GetPullRequest

func (m *MockClient) GetPullRequest(ctx context.Context, owner, repo string, number int) (*PullRequest, error)

GetPullRequest returns a mock pull request.

func (*MockClient) ListPullRequests

func (m *MockClient) ListPullRequests(ctx context.Context, owner, repo, defaultBranch string) ([]PullRequest, error)

ListPullRequests returns mock pull requests.

func (*MockClient) ListRepositories

func (m *MockClient) ListRepositories(ctx context.Context, org string) ([]Repository, error)

ListRepositories returns mock repositories.

func (*MockClient) MergePullRequest

func (m *MockClient) MergePullRequest(ctx context.Context, owner, repo string, prNumber int) error

MergePullRequest mocks merging a pull request.

func (*MockClient) PostRebaseComment

func (m *MockClient) PostRebaseComment(ctx context.Context, owner, repo string, prNumber int) error

PostRebaseComment mocks posting a rebase comment.

func (*MockClient) UpdateBranch

func (m *MockClient) UpdateBranch(ctx context.Context, owner, repo string, prNumber int) error

UpdateBranch mocks updating a branch.

type PullRequest

type PullRequest struct {
	Number       int
	Title        string
	URL          string
	HeadBranch   string
	BaseBranch   string
	State        string
	Draft        bool
	Mergeable    *bool
	HeadSHA      string
	RepoName     string
	RepoFullName string
}

PullRequest represents a GitHub pull request.

type RealClient

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

RealClient implements the Client interface using the real GitHub API.

func NewRealClient

func NewRealClient(token string) *RealClient

NewRealClient creates a new RealClient with the given token.

func (*RealClient) GetBranchStatus

func (c *RealClient) GetBranchStatus(ctx context.Context, owner, repo string, prNumber int) (*BranchStatus, error)

GetBranchStatus gets the status of a PR branch relative to its base.

func (*RealClient) GetCheckStatus

func (c *RealClient) GetCheckStatus(ctx context.Context, owner, repo, ref string) (*CheckStatus, error)

GetCheckStatus gets the check status for a commit.

func (*RealClient) GetPullRequest

func (c *RealClient) GetPullRequest(ctx context.Context, owner, repo string, number int) (*PullRequest, error)

GetPullRequest gets detailed information about a pull request.

func (*RealClient) ListPullRequests

func (c *RealClient) ListPullRequests(ctx context.Context, owner, repo, defaultBranch string) ([]PullRequest, error)

ListPullRequests lists open pull requests for a repository targeting its default branch.

func (*RealClient) ListRepositories

func (c *RealClient) ListRepositories(ctx context.Context, org string) ([]Repository, error)

ListRepositories lists all repositories in an organization.

func (*RealClient) MergePullRequest

func (c *RealClient) MergePullRequest(ctx context.Context, owner, repo string, prNumber int) error

MergePullRequest merges a pull request.

func (*RealClient) PostRebaseComment

func (c *RealClient) PostRebaseComment(ctx context.Context, owner, repo string, prNumber int) error

PostRebaseComment posts a rebase comment on a pull request for Dependabot.

func (*RealClient) UpdateBranch

func (c *RealClient) UpdateBranch(ctx context.Context, owner, repo string, prNumber int) error

UpdateBranch updates a pull request branch with the base branch. When GitHub returns HTTP 202 Accepted, it means the branch update has been successfully scheduled as a background job. This is treated as success since the rebase was triggered, even though it completes asynchronously.

type Repository

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

Repository represents a GitHub repository.

Jump to

Keyboard shortcuts

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