github

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PRURL

func PRURL(host, owner, repo string, number int) string

PRURL constructs the web URL for a pull request on the given host.

Types

type Client

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

Client wraps GitHub API operations.

func NewClient

func NewClient(host, owner, repo string) (*Client, error)

NewClient creates a new GitHub API client for the given repository. The host parameter specifies the GitHub hostname (e.g. "github.com" or a GHES hostname like "github.mycompany.com"). If empty, it defaults to "github.com".

func (*Client) CreatePR

func (c *Client) CreatePR(base, head, title, body string, draft bool) (*PullRequest, error)

CreatePR creates a new pull request.

func (*Client) CreateStack

func (c *Client) CreateStack(prNumbers []int) (int, error)

CreateStack creates a stack on GitHub from an ordered list of PR numbers. The PR numbers must be ordered from bottom to top of the stack and must form a valid base-to-head chain. Returns the server-assigned stack ID.

func (*Client) DeleteStack

func (c *Client) DeleteStack(stackID string) error

DeleteStack deletes a stack on GitHub. The stack is identified by stackID. Returns nil on success (204).

func (*Client) FindPRByNumber

func (c *Client) FindPRByNumber(number int) (*PullRequest, error)

FindPRByNumber fetches a pull request by its number.

func (*Client) FindPRDetailsForBranch

func (c *Client) FindPRDetailsForBranch(branch string) (*PRDetails, error)

FindPRDetailsForBranch fetches enriched PR data for display purposes. Returns nil without error if no PR exists for the branch.

func (*Client) FindPRForBranch

func (c *Client) FindPRForBranch(branch string) (*PullRequest, error)

FindPRForBranch finds an open PR by head branch name.

func (*Client) ListStacks

func (c *Client) ListStacks() ([]RemoteStack, error)

ListStacks returns all stacks in the repository. Returns an empty slice if no stacks exist. A 404 response indicates stacked PRs are not enabled for this repository.

func (*Client) MarkPRReadyForReview added in v0.0.3

func (c *Client) MarkPRReadyForReview(prID string) error

MarkPRReadyForReview converts a draft pull request to ready for review.

func (*Client) UpdatePRBase

func (c *Client) UpdatePRBase(number int, base string) error

UpdatePRBase updates the base branch of an existing pull request.

func (*Client) UpdateStack

func (c *Client) UpdateStack(stackID string, prNumbers []int) error

UpdateStack adds pull requests to an existing stack on GitHub. The stack is identified by stackID. The full list of PR numbers in the updated stack must be provided, including existing and new PRs, ordered from bottom to top.

type ClientOps

type ClientOps interface {
	FindPRForBranch(branch string) (*PullRequest, error)
	FindPRByNumber(number int) (*PullRequest, error)
	FindPRDetailsForBranch(branch string) (*PRDetails, error)
	CreatePR(base, head, title, body string, draft bool) (*PullRequest, error)
	UpdatePRBase(number int, base string) error
	MarkPRReadyForReview(prID string) error
	ListStacks() ([]RemoteStack, error)
	CreateStack(prNumbers []int) (int, error)
	UpdateStack(stackID string, prNumbers []int) error
	DeleteStack(stackID string) error
}

ClientOps defines the interface for GitHub API operations. The concrete Client type satisfies this interface. Tests can substitute a MockClient.

type MergeQueueEntry

type MergeQueueEntry struct {
	ID string `graphql:"id"`
}

MergeQueueEntry represents a merge queue entry. When the GraphQL field mergeQueueEntry is null (PR not queued), the pointer will be nil.

type MockClient

type MockClient struct {
	FindPRForBranchFn        func(string) (*PullRequest, error)
	FindPRByNumberFn         func(int) (*PullRequest, error)
	FindPRDetailsForBranchFn func(string) (*PRDetails, error)
	CreatePRFn               func(string, string, string, string, bool) (*PullRequest, error)
	UpdatePRBaseFn           func(int, string) error
	MarkPRReadyForReviewFn   func(string) error
	ListStacksFn             func() ([]RemoteStack, error)
	CreateStackFn            func([]int) (int, error)
	UpdateStackFn            func(string, []int) error
	DeleteStackFn            func(string) error
}

MockClient is a test double for GitHub API operations. Each field is an optional function that, when set, handles the corresponding ClientOps method call. When nil, a reasonable default is returned.

func (*MockClient) CreatePR

func (m *MockClient) CreatePR(base, head, title, body string, draft bool) (*PullRequest, error)

func (*MockClient) CreateStack

func (m *MockClient) CreateStack(prNumbers []int) (int, error)

func (*MockClient) DeleteStack

func (m *MockClient) DeleteStack(stackID string) error

func (*MockClient) FindPRByNumber

func (m *MockClient) FindPRByNumber(number int) (*PullRequest, error)

func (*MockClient) FindPRDetailsForBranch

func (m *MockClient) FindPRDetailsForBranch(branch string) (*PRDetails, error)

func (*MockClient) FindPRForBranch

func (m *MockClient) FindPRForBranch(branch string) (*PullRequest, error)

func (*MockClient) ListStacks

func (m *MockClient) ListStacks() ([]RemoteStack, error)

func (*MockClient) MarkPRReadyForReview added in v0.0.3

func (m *MockClient) MarkPRReadyForReview(prID string) error

func (*MockClient) UpdatePRBase

func (m *MockClient) UpdatePRBase(number int, base string) error

func (*MockClient) UpdateStack

func (m *MockClient) UpdateStack(stackID string, prNumbers []int) error

type PRDetails

type PRDetails struct {
	Number   int
	State    string // OPEN, CLOSED, MERGED
	URL      string
	IsDraft  bool
	Merged   bool
	IsQueued bool
}

PRDetails holds enriched pull request data for display in the TUI.

type PullRequest

type PullRequest struct {
	ID              string           `graphql:"id"`
	Number          int              `graphql:"number"`
	State           string           `graphql:"state"`
	URL             string           `graphql:"url"`
	HeadRefName     string           `graphql:"headRefName"`
	BaseRefName     string           `graphql:"baseRefName"`
	IsDraft         bool             `graphql:"isDraft"`
	Merged          bool             `graphql:"merged"`
	MergeQueueEntry *MergeQueueEntry `graphql:"mergeQueueEntry"`
}

PullRequest represents a GitHub pull request.

func (*PullRequest) IsQueued

func (pr *PullRequest) IsQueued() bool

IsQueued reports whether the pull request is currently in a merge queue.

type RemoteStack

type RemoteStack struct {
	ID           int   `json:"id"`
	PullRequests []int `json:"pull_requests"`
}

Jump to

Keyboard shortcuts

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