github

package
v0.1.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: BlueOak-1.0.0 Imports: 8 Imported by: 0

Documentation

Overview

Package github provides GitHub API integration for gh-stack.

internal/github/github.go

Index

Constants

View Source
const StackCommentMarker = "<!-- gh-stack:nav -->"

StackCommentMarker identifies gh-stack managed comments.

Variables

This section is empty.

Functions

func CreatePR

func CreatePR(head, base, title, body string) (int, error)

CreatePR creates a new pull request using the default client. Deprecated: Use NewClient() and call methods directly for better error handling.

func GenerateStackComment

func GenerateStackComment(root *tree.Node, currentBranch, trunk string) string

GenerateStackComment builds markdown for a PR's stack position. It includes a warning if the PR targets a non-trunk branch.

func UpdatePRBase

func UpdatePRBase(number int, base string) error

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 NewClient

func NewClient() (*Client, error)

NewClient creates a new GitHub client for the current repository.

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

func (c *Client) CreateComment(prNumber int, body string) (int, error)

CreateComment adds a comment to a PR (PRs are issues in GitHub's API).

func (*Client) CreateDraftPR

func (c *Client) CreateDraftPR(head, base, title, body string) (int, error)

CreateDraftPR creates a new pull request as a draft.

func (*Client) CreateOrUpdateStackComment

func (c *Client) CreateOrUpdateStackComment(prNumber int, body string) error

CreateOrUpdateStackComment finds an existing stack comment by marker and updates it, or creates a new one if none exists.

func (*Client) CreatePR

func (c *Client) CreatePR(head, base, title, body string) (int, error)

CreatePR creates a new pull request and returns the PR number.

func (*Client) FindStackComment

func (c *Client) FindStackComment(prNumber int) (int, error)

FindStackComment searches for an existing gh-stack comment on a PR. Returns the comment ID if found, or 0 if not found.

func (*Client) GetPR

func (c *Client) GetPR(number int) (*PR, error)

GetPR fetches PR details by number.

func (*Client) ListComments

func (c *Client) ListComments(prNumber int) ([]Comment, error)

ListComments retrieves all comments on a PR.

func (*Client) MarkPRReady

func (c *Client) MarkPRReady(prNumber int) error

MarkPRReady converts a draft PR to ready for review. Uses the GraphQL API since REST doesn't support this operation.

func (*Client) UpdateComment

func (c *Client) UpdateComment(commentID int, body string) error

UpdateComment updates an existing comment by ID.

func (*Client) UpdatePRBase

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

UpdatePRBase updates the base branch of a PR.

type Comment

type Comment struct {
	ID   int    `json:"id"`
	Body string `json:"body"`
}

Comment represents a GitHub issue/PR comment.

type PR

type PR struct {
	Number int    `json:"number"`
	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.

func GetPR

func GetPR(number int) (*PR, error)

GetPR fetches PR details using the default client.

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.

Jump to

Keyboard shortcuts

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