Documentation
¶
Overview ¶
Package github provides shared GitHub client utilities for release tools.
Index ¶
- Constants
- Variables
- func IsBot(username string) bool
- type AppIdentity
- type Client
- func (c *Client) API() *github.Client
- func (c *Client) BranchExists(ctx context.Context, branch string) (bool, error)
- func (c *Client) CommitExistsWithPattern(ctx context.Context, p FindCommitParams) (bool, error)
- func (c *Client) CreateBranch(ctx context.Context, p CreateBranchParams) error
- func (c *Client) CreateIssueComment(ctx context.Context, issueNumber int, body string) error
- func (c *Client) CreatePR(ctx context.Context, p CreatePRParams) (*github.PullRequest, error)
- func (c *Client) CreateTag(ctx context.Context, p CreateTagParams) error
- func (c *Client) DeleteBranch(ctx context.Context, branch string) error
- func (c *Client) EnsureLabel(ctx context.Context, p CreateLabelParams) (bool, error)
- func (c *Client) FindCommitWithPattern(ctx context.Context, p FindCommitParams) (string, error)
- func (c *Client) GetAppIdentity(ctx context.Context) (AppIdentity, error)
- func (c *Client) GetCommit(ctx context.Context, sha string) (*github.RepositoryCommit, error)
- func (c *Client) GetPR(ctx context.Context, number int) (*github.PullRequest, error)
- func (c *Client) GetRefSHA(ctx context.Context, ref string) (string, error)
- func (c *Client) GetReleaseByTag(ctx context.Context, tag string) (*github.RepositoryRelease, error)
- func (c *Client) GraphQL(ctx context.Context, query string, variables map[string]any, result any) error
- func (c *Client) IsBranchMergedInto(ctx context.Context, source, target string) (bool, error)
- func (c *Client) Owner() string
- func (c *Client) ReadManifest(ctx context.Context, ref string) (map[string]string, error)
- func (c *Client) Repo() string
- func (c *Client) UpdateReleaseBody(ctx context.Context, releaseID int64, body string) error
- func (c *Client) WaitForCheckRun(ctx context.Context, ref, checkName string) error
- type ClientConfig
- type CreateBranchParams
- type CreateLabelParams
- type CreatePRParams
- type CreateTagParams
- type FindCommitParams
Constants ¶
const BackportLabelColor = "63a504"
BackportLabelColor is the hex color for backport labels (without '#' prefix).
Variables ¶
var ErrCommitNotFound = errors.New("commit not found")
ErrCommitNotFound is returned when a commit matching the search criteria is not found.
Functions ¶
Types ¶
type AppIdentity ¶
type AppIdentity struct {
Name string // e.g., "my-app[bot]"
Email string // e.g., "12345+my-app[bot]@users.noreply.github.com"
}
AppIdentity represents a GitHub App's git identity for commits.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the GitHub API client with repository context.
func NewClient ¶
func NewClient(ctx context.Context, cfg ClientConfig) *Client
NewClient creates a new Client with the given configuration.
func NewClientFromEnv ¶
NewClientFromEnv creates a new Client from environment variables. Reads GITHUB_TOKEN and GITHUB_REPOSITORY (format: owner/repo).
func (*Client) BranchExists ¶
BranchExists checks if a branch exists in the repository.
func (*Client) CommitExistsWithPattern ¶
CommitExistsWithPattern checks if any commit in the branch history contains the pattern in its title.
func (*Client) CreateBranch ¶
func (c *Client) CreateBranch(ctx context.Context, p CreateBranchParams) error
CreateBranch creates a new branch from the given SHA.
func (*Client) CreateIssueComment ¶
CreateIssueComment adds a comment to an issue or pull request.
func (*Client) CreatePR ¶
func (c *Client) CreatePR(ctx context.Context, p CreatePRParams) (*github.PullRequest, error)
CreatePR creates a new pull request.
func (*Client) CreateTag ¶
func (c *Client) CreateTag(ctx context.Context, p CreateTagParams) error
CreateTag creates an annotated tag ref for the given SHA.
func (*Client) DeleteBranch ¶
DeleteBranch deletes the branch ref on the remote.
func (*Client) EnsureLabel ¶
EnsureLabel creates a label if it doesn't already exist. Returns true if the label was created, false if it already existed.
func (*Client) FindCommitWithPattern ¶
FindCommitWithPattern searches the commit history of a branch for a commit whose title contains the pattern. Returns the commit SHA if found, or an error if not found.
func (*Client) GetAppIdentity ¶
func (c *Client) GetAppIdentity(ctx context.Context) (AppIdentity, error)
GetAppIdentity returns the GitHub App's identity for use in git commits. It checks for APP_SLUG environment variable and fetches the bot user ID from the API. The bot user ID is required for GitHub to properly attribute commits.
func (*Client) GetReleaseByTag ¶
func (c *Client) GetReleaseByTag(ctx context.Context, tag string) (*github.RepositoryRelease, error)
GetReleaseByTag fetches a release by its tag name.
func (*Client) GraphQL ¶
func (c *Client) GraphQL(ctx context.Context, query string, variables map[string]any, result any) error
GraphQL executes a GraphQL query against the GitHub API. The result parameter should be a pointer to a struct that will be decoded from the response.
func (*Client) IsBranchMergedInto ¶
IsBranchMergedInto checks if the source branch is fully merged into the target branch. Returns true if target contains all commits from source (i.e., source is behind or equal to target).
func (*Client) ReadManifest ¶
ReadManifest reads the release-please manifest from the repository.
func (*Client) UpdateReleaseBody ¶
UpdateReleaseBody updates only the body of a release.
type ClientConfig ¶
ClientConfig holds configuration for creating a new Client.
type CreateBranchParams ¶
CreateBranchParams holds parameters for CreateBranch.
type CreateLabelParams ¶
type CreateLabelParams struct {
Name string // Label name
Color string // Hex color without '#' prefix (e.g., "ff0000")
Description string // Optional description
}
CreateLabelParams holds parameters for CreateLabel.
type CreatePRParams ¶
CreatePRParams holds parameters for CreatePR.
type CreateTagParams ¶
CreateTagParams holds parameters for CreateTag.
type FindCommitParams ¶
FindCommitParams holds parameters for FindCommitWithPattern and CommitExistsWithPattern.