github

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDiffComment

func BuildDiffComment(codeDiff, repoName, baseBranch, oldCommit, newCommit string, sinceJip bool) string

BuildDiffComment generates a PR comment with interdiff output, using collapsible sections for each file. When sinceJip is true the header reads "Changes since last jip send" (the base is jip's own previous send rather than the current remote head).

func BuildStackBlock

func BuildStackBlock(prNumbers []int, current int) string

BuildStackBlock generates a markdown stack navigation block showing the current PR's position in the stack.

func BuildStackedPRBody

func BuildStackedPRBody(commitHash, repoFullName string, prNumber int, allPRs []int, commitBody string) string

BuildStackedPRBody generates the full PR body for a stacked PR. For a single PR (len(allPRs) <= 1), only the commitBody is returned.

func BuildUnavailableDiffComment added in v1.4.0

func BuildUnavailableDiffComment(repoName, baseBranch, oldCommit, newCommit string) string

BuildUnavailableDiffComment generates a PR comment for the case where --diff-since-jip knows the previous jip-pushed commit but cannot find it locally (e.g. it was pushed from another machine and not fetched). It documents that the diff could not be generated and points at the remote.

func ParsePushedCommit added in v1.4.0

func ParsePushedCommit(commentBody string) string

ParsePushedCommit extracts the commit hash from a jip pushed-commit marker in a PR body, or "" if the body has no marker or the value is not a valid hex hash. Uses LastIndex so that if multiple markers exist the newest one wins.

func ParseRepoFromURL

func ParseRepoFromURL(url string) (owner, repo string, err error)

ParseRepoFromURL extracts owner and repo name from a GitHub remote URL. Supports both HTTPS and SSH formats.

func ParseReviewCommit added in v1.4.0

func ParseReviewCommit(prBody string) string

ParseReviewCommit extracts the commit hash from the "Only review commit" link that BuildStackedPRBody writes into a stacked PR's body, or "" if the body has no such link (e.g. a standalone, non-stacked PR).

Only the line that starts with "Only review commit" is searched, and the hash is extracted from the exact /pull/<number>/commits/<hash> URL shape to avoid matching unrelated URLs in user-written descriptions.

func WithPushedCommitMarker added in v1.4.0

func WithPushedCommitMarker(body, commit string) string

WithPushedCommitMarker ensures the PR body contains exactly one pushed-commit marker reflecting commit. If the body already has that exact commit, it is returned unchanged. Otherwise any existing markers are stripped and the new marker is appended.

Types

type Client

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

Client wraps go-github for PR mutations and GraphQL queries.

func NewClient

func NewClient(token, remoteURL, apiURL string) (*Client, error)

NewClient creates a GitHub client for the given repository. remoteURL is the git remote URL (e.g. https://github.com/owner/repo.git), from which owner and repo are parsed. If apiURL is non-empty, it is used as the GitHub API base URL (for GitHub Enterprise or testing).

func (*Client) AddToStack added in v1.6.0

func (c *Client) AddToStack(stackNumber int, prNumbers []int) (*Stack, error)

AddToStack appends pull requests to the top of an existing stack. Only the new PR numbers (the delta) are given, ordered from the current top upward. The stacks API is append-only: reordering or mid-stack changes require Unstack followed by CreateStack.

func (*Client) CommentOnPR

func (c *Client) CommentOnPR(number int, body string) error

CommentOnPR posts a comment on a pull request.

func (*Client) CreatePR

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

CreatePR creates a new pull request and returns its info.

func (*Client) CreateStack added in v1.6.0

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

CreateStack creates a native GitHub stack from PR numbers ordered bottom to top. The PRs must already form a valid base-to-head chain (each PR based on the head branch of the one below), and there must be at least two.

func (*Client) FindStackForPR added in v1.6.0

func (c *Client) FindStackForPR(number int) (*Stack, error)

FindStackForPR returns the stack containing the given PR, or nil when the PR is not part of any stack.

func (*Client) GetAuthenticatedUser

func (c *Client) GetAuthenticatedUser() (string, error)

GetAuthenticatedUser returns the login of the authenticated user.

func (*Client) LookupPRsByBranch

func (c *Client) LookupPRsByBranch(branches []string) (map[string]*PRInfo, error)

LookupPRsByBranch queries GitHub's GraphQL API for open PRs matching the given head branch names. Returns a map from branch name to PRInfo for branches that have an open PR.

func (*Client) Owner

func (c *Client) Owner() string

Owner returns the repository owner.

func (*Client) Repo

func (c *Client) Repo() string

Repo returns the repository name.

func (*Client) RequestReviewers

func (c *Client) RequestReviewers(number int, reviewers []string) error

RequestReviewers adds reviewers to a pull request.

func (*Client) StacksEnabled added in v1.6.0

func (c *Client) StacksEnabled() (bool, error)

StacksEnabled reports whether the stacked-PRs preview is enabled for the repository. The stacks endpoints answer 404 when it is not.

func (*Client) Unstack added in v1.6.0

func (c *Client) Unstack(stackNumber int) (dissolved bool, err error)

Unstack removes the pull requests from a stack, dissolving it. The PRs themselves survive. PRs queued for merge or with auto-merge enabled cannot be removed; dissolved is false when any remain (HTTP 200 with the remaining stack instead of 204).

func (*Client) UpdatePR

func (c *Client) UpdatePR(number int, opts UpdatePROpts) error

UpdatePR updates fields on an existing pull request.

type PRInfo

type PRInfo struct {
	Number      int    `json:"number"`
	State       string `json:"state"`
	URL         string `json:"url"`
	Title       string `json:"title"`
	Body        string `json:"body"`
	HeadRefName string `json:"headRefName"`
	BaseRefName string `json:"baseRefName"`
	IsDraft     bool   `json:"isDraft"`
}

PRInfo holds the essential fields of a pull request.

type Service

type Service interface {
	CreatePR(head, base, title, body string, draft bool) (*PRInfo, error)
	UpdatePR(number int, opts UpdatePROpts) error
	CommentOnPR(number int, body string) error
	GetAuthenticatedUser() (string, error)
	RequestReviewers(number int, reviewers []string) error
	LookupPRsByBranch(branches []string) (map[string]*PRInfo, error)
	Owner() string
	Repo() string

	// Native GitHub stacked-PRs (private preview) operations.
	StacksEnabled() (bool, error)
	FindStackForPR(number int) (*Stack, error)
	CreateStack(prNumbers []int) (*Stack, error)
	AddToStack(stackNumber int, prNumbers []int) (*Stack, error)
	Unstack(stackNumber int) (dissolved bool, err error)
}

Service defines the GitHub operations needed by the send pipeline.

type Stack added in v1.6.0

type Stack struct {
	Number       int       `json:"number"`
	URL          string    `json:"url"`
	Open         bool      `json:"open"`
	Base         StackBase `json:"base"`
	PullRequests []StackPR `json:"pull_requests"`
}

Stack is a native GitHub stack of pull requests. Number is the human-facing stack number used in API paths; PullRequests is ordered bottom to top.

func (*Stack) OpenPRNumbers added in v1.6.0

func (s *Stack) OpenPRNumbers() []int

OpenPRNumbers returns the numbers of the stack's open, unmerged PRs, bottom to top. Merged PRs stay listed in a stack after a partial merge, so callers comparing against a local stack must ignore them.

type StackBase added in v1.6.0

type StackBase struct {
	Ref string `json:"ref"`
}

StackBase describes the base ref of a stack.

type StackPR added in v1.6.0

type StackPR struct {
	Number   int     `json:"number"`
	State    string  `json:"state"` // "open" or "closed"
	Draft    bool    `json:"draft"`
	MergedAt *string `json:"merged_at"`
}

StackPR is a pull request entry within a native GitHub stack.

func (StackPR) Merged added in v1.6.0

func (p StackPR) Merged() bool

Merged reports whether the pull request has been merged.

type UpdatePROpts

type UpdatePROpts struct {
	Title *string
	Body  *string
	Base  *string
	Draft *bool
}

UpdatePROpts contains optional fields for updating a PR.

Jump to

Keyboard shortcuts

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