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 ¶
- func IsDependabotBranch(branchName string) bool
- func MatchesBranchPattern(branchName, pattern string) bool
- type ActionResult
- type BranchStatus
- type CheckStatus
- type Client
- type MockClient
- func (m *MockClient) GetBranchStatus(ctx context.Context, owner, repo string, prNumber int) (*BranchStatus, error)
- func (m *MockClient) GetCheckStatus(ctx context.Context, owner, repo, ref string) (*CheckStatus, error)
- func (m *MockClient) GetPullRequest(ctx context.Context, owner, repo string, number int) (*PullRequest, error)
- func (m *MockClient) ListPullRequests(ctx context.Context, owner, repo, defaultBranch string) ([]PullRequest, error)
- func (m *MockClient) ListRepositories(ctx context.Context, org string) ([]Repository, error)
- func (m *MockClient) MergePullRequest(ctx context.Context, owner, repo string, prNumber int) error
- func (m *MockClient) PostRebaseComment(ctx context.Context, owner, repo string, prNumber int) error
- func (m *MockClient) UpdateBranch(ctx context.Context, owner, repo string, prNumber int) error
- type PullRequest
- type RealClient
- func (c *RealClient) GetBranchStatus(ctx context.Context, owner, repo string, prNumber int) (*BranchStatus, error)
- func (c *RealClient) GetCheckStatus(ctx context.Context, owner, repo, ref string) (*CheckStatus, error)
- func (c *RealClient) GetPullRequest(ctx context.Context, owner, repo string, number int) (*PullRequest, error)
- func (c *RealClient) ListPullRequests(ctx context.Context, owner, repo, defaultBranch string) ([]PullRequest, error)
- func (c *RealClient) ListRepositories(ctx context.Context, org string) ([]Repository, error)
- func (c *RealClient) MergePullRequest(ctx context.Context, owner, repo string, prNumber int) error
- func (c *RealClient) PostRebaseComment(ctx context.Context, owner, repo string, prNumber int) error
- func (c *RealClient) UpdateBranch(ctx context.Context, owner, repo string, prNumber int) error
- type Repository
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDependabotBranch ¶
IsDependabotBranch checks if a branch name indicates Dependabot ownership.
func MatchesBranchPattern ¶
MatchesBranchPattern checks if a branch name matches the given pattern using substring matching.
Types ¶
type ActionResult ¶
ActionResult represents the result of an action on a pull request.
type BranchStatus ¶
BranchStatus represents the status of a branch relative to its base.
type CheckStatus ¶
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 ¶
MergePullRequest mocks merging a pull request.
func (*MockClient) PostRebaseComment ¶
PostRebaseComment mocks posting a rebase comment.
func (*MockClient) UpdateBranch ¶
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 ¶
MergePullRequest merges a pull request.
func (*RealClient) PostRebaseComment ¶
PostRebaseComment posts a rebase comment on a pull request for Dependabot.
func (*RealClient) UpdateBranch ¶
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.