Documentation
¶
Overview ¶
Package github provides GitHub API integration for gh-stack.
internal/github/github.go
Index ¶
- Constants
- func CollectPRNumbers(root *tree.Node) []int
- func CreatePR(head, base, title, body string) (int, error)deprecated
- func GenerateStackComment(root *tree.Node, currentBranch, trunk, repoURL string, prInfo map[int]PRInfo, ...) string
- func UpdatePRBase(number int, base string) error
- type Client
- func (c *Client) CreateComment(prNumber int, body string) (int, error)
- func (c *Client) CreateDraftPR(head, base, title, body string) (int, error)
- func (c *Client) CreateOrUpdateStackComment(prNumber int, body string) error
- func (c *Client) CreatePR(head, base, title, body string) (int, error)
- func (c *Client) CreateSubmitPR(head, base, title, body string, draft bool) (*PR, error)
- func (c *Client) FindPRByHead(branch string) (*PR, error)
- func (c *Client) FindStackComment(prNumber int) (int, string, error)
- func (c *Client) GenerateAndPostStackComment(root *tree.Node, branch, trunk string, prNumber int, ...) error
- func (c *Client) GetPR(number int) (*PR, error)
- func (c *Client) GetPRTitles(prNumbers []int) (map[int]PRInfo, error)
- func (c *Client) ListComments(prNumber int) ([]Comment, error)
- func (c *Client) MarkPRReady(prNumber int) error
- func (c *Client) PRURL(number int) string
- func (c *Client) RepoURL() string
- func (c *Client) UpdateComment(commentID int, body string) error
- func (c *Client) UpdatePRBase(number int, base string) error
- type Comment
- type PR
- type PRInfo
- type RESTClient
Constants ¶
const StackCommentMarker = "<!-- gh-stack:nav -->"
StackCommentMarker identifies gh-stack managed comments.
Variables ¶
This section is empty.
Functions ¶
func CollectPRNumbers ¶
CollectPRNumbers walks a tree and returns all PR numbers found.
func GenerateStackComment ¶
func GenerateStackComment(root *tree.Node, currentBranch, trunk, repoURL string, prInfo map[int]PRInfo, remoteBranches map[string]bool) string
GenerateStackComment builds markdown for a PR's stack position. It includes a warning if the PR targets a non-trunk branch. The repoURL should be the base repository URL (e.g., "https://github.com/owner/repo"). The prInfo map provides titles for PRs (keyed by PR number).
Only the current stack is rendered: the path from root to the current branch, plus all descendants of the current branch. Sibling stacks are excluded.
If remoteBranches is non-nil, branches without PRs that don't exist on the remote are omitted (their children are promoted up a level). Pass nil to disable this filtering.
func UpdatePRBase ¶
UpdatePRBase updates the base branch using the default client.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps a REST client with repo context.
func NewClientWithREST ¶
func NewClientWithREST(rest RESTClient, owner, repo string) *Client
NewClientWithREST creates a client with a custom REST implementation. This is primarily useful for testing.
func (*Client) CreateComment ¶
CreateComment adds a comment to a PR (PRs are issues in GitHub's API).
func (*Client) CreateDraftPR ¶
CreateDraftPR creates a new pull request as a draft.
func (*Client) CreateOrUpdateStackComment ¶
CreateOrUpdateStackComment finds an existing stack comment by marker and updates it, or creates a new one if none exists. Skips the update if the body hasn't changed.
func (*Client) CreateSubmitPR ¶
CreateSubmitPR creates a new pull request. This is the primary method for the submit workflow. If draft is true, creates a draft PR. The body parameter is used as the PR description; pass an empty string for no description.
func (*Client) FindPRByHead ¶
FindPRByHead finds an open PR with the given head branch. Returns nil, nil if no PR exists for this branch.
func (*Client) FindStackComment ¶
FindStackComment searches for an existing gh-stack comment on a PR. Returns the comment ID and body if found, or (0, "") if not found.
func (*Client) GenerateAndPostStackComment ¶
func (c *Client) GenerateAndPostStackComment(root *tree.Node, branch, trunk string, prNumber int, remoteBranches map[string]bool) error
GenerateAndPostStackComment generates and posts/updates a stack comment for a PR. It fetches PR titles via GraphQL and renders the full comment.
If remoteBranches is non-nil, branches without PRs that don't exist on the remote are omitted from the rendered comment. Pass nil to disable filtering.
func (*Client) GetPRTitles ¶
GetPRTitles fetches titles for multiple PRs in a single GraphQL request. Returns a map of PR number to PRInfo. PRs that don't exist are omitted.
Note: This builds a single GraphQL query with all PR requests. For extremely large stacks (100+ PRs), this could potentially hit query size limits. In practice, stacks rarely exceed 10-20 PRs, so batching is not implemented.
func (*Client) ListComments ¶
ListComments retrieves all comments on a PR.
func (*Client) MarkPRReady ¶
MarkPRReady converts a draft PR to ready for review. Uses the GraphQL API since REST doesn't support this operation.
func (*Client) RepoURL ¶
RepoURL returns the base URL for the repository (e.g., "https://github.com/owner/repo").
func (*Client) UpdateComment ¶
UpdateComment updates an existing comment by ID.
type PR ¶
type PR struct {
Number int `json:"number"`
Title string `json:"title"`
State string `json:"state"`
Merged bool `json:"merged"`
Draft bool `json:"draft"`
Base struct {
Ref string `json:"ref"`
} `json:"base"`
}
PR represents a GitHub pull request.
type RESTClient ¶
type RESTClient interface {
Get(path string, response any) error
Post(path string, body io.Reader, response any) error
Patch(path string, body io.Reader, response any) error
}
RESTClient defines the interface for GitHub REST API operations. The *api.RESTClient from go-gh satisfies this interface.