github

package
v0.0.0-...-c10a854 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package github provides shared GitHub client utilities for release tools.

Index

Constants

View Source
const BackportLabelColor = "63a504"

BackportLabelColor is the hex color for backport labels (without '#' prefix).

Variables

View Source
var ErrCommitNotFound = errors.New("commit not found")

ErrCommitNotFound is returned when a commit matching the search criteria is not found.

Functions

func IsBot

func IsBot(username string) bool

IsBot checks if a username appears to be a bot account.

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

func NewClientFromEnv(ctx context.Context) (*Client, error)

NewClientFromEnv creates a new Client from environment variables. Reads GITHUB_TOKEN and GITHUB_REPOSITORY (format: owner/repo).

func (*Client) API

func (c *Client) API() *github.Client

API returns the underlying go-github client for advanced usage.

func (*Client) BranchExists

func (c *Client) BranchExists(ctx context.Context, branch string) (bool, error)

BranchExists checks if a branch exists in the repository.

func (*Client) CommitExistsWithPattern

func (c *Client) CommitExistsWithPattern(ctx context.Context, p FindCommitParams) (bool, error)

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

func (c *Client) CreateIssueComment(ctx context.Context, issueNumber int, body string) error

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

func (c *Client) DeleteBranch(ctx context.Context, branch string) error

DeleteBranch deletes the branch ref on the remote.

func (*Client) EnsureLabel

func (c *Client) EnsureLabel(ctx context.Context, p CreateLabelParams) (bool, error)

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

func (c *Client) FindCommitWithPattern(ctx context.Context, p FindCommitParams) (string, error)

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) GetCommit

func (c *Client) GetCommit(ctx context.Context, sha string) (*github.RepositoryCommit, error)

GetCommit fetches a commit by SHA.

func (*Client) GetPR

func (c *Client) GetPR(ctx context.Context, number int) (*github.PullRequest, error)

GetPR fetches a pull request by number.

func (*Client) GetRefSHA

func (c *Client) GetRefSHA(ctx context.Context, ref string) (string, error)

GetRefSHA resolves a ref (branch, tag, or commit SHA) to its SHA.

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

func (c *Client) IsBranchMergedInto(ctx context.Context, source, target string) (bool, error)

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) Owner

func (c *Client) Owner() string

Owner returns the repository owner.

func (*Client) ReadManifest

func (c *Client) ReadManifest(ctx context.Context, ref string) (map[string]string, error)

ReadManifest reads the release-please manifest from the repository.

func (*Client) Repo

func (c *Client) Repo() string

Repo returns the repository name.

func (*Client) UpdateReleaseBody

func (c *Client) UpdateReleaseBody(ctx context.Context, releaseID int64, body string) error

UpdateReleaseBody updates only the body of a release.

func (*Client) WaitForCheckRun

func (c *Client) WaitForCheckRun(ctx context.Context, ref, checkName string) error

WaitForCheckRun polls until the named check run has completed successfully on the given ref, or until the context is done (e.g. timeout). Ref can be a branch name or commit SHA.

type ClientConfig

type ClientConfig struct {
	Token string
	Owner string
	Repo  string
}

ClientConfig holds configuration for creating a new Client.

type CreateBranchParams

type CreateBranchParams struct {
	Branch string
	SHA    string
}

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

type CreatePRParams struct {
	Title string
	Head  string
	Base  string
	Body  string
	Draft bool
}

CreatePRParams holds parameters for CreatePR.

type CreateTagParams

type CreateTagParams struct {
	Tag     string
	SHA     string
	Message string
}

CreateTagParams holds parameters for CreateTag.

type FindCommitParams

type FindCommitParams struct {
	Branch  string
	Pattern string
}

FindCommitParams holds parameters for FindCommitWithPattern and CommitExistsWithPattern.

Jump to

Keyboard shortcuts

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