github

package
v0.0.0-...-f7e4cf8 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 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

This section is empty.

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

func (c *Client) CreateTag(ctx context.Context, p CreateTagParams) error

CreateTag creates an annotated tag ref for the given SHA.

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

func (c *Client) FindCherryPickedCommit(ctx context.Context, p FindCherryPickedCommitParams) (*github.RepositoryCommit, error)

FindCherryPickedCommit searches the commit history of a branch for a commit message containing the original commit SHA. It returns nil when no matching commit is 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) 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) UpdateReleaseBody

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

UpdateReleaseBody updates only the body of a release.

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 CreateTagParams

type CreateTagParams struct {
	Tag     string
	SHA     string
	Message string
}

CreateTagParams holds parameters for CreateTag.

type FindCherryPickedCommitParams

type FindCherryPickedCommitParams struct {
	Branch      string
	OriginalSHA string
}

FindCherryPickedCommitParams holds parameters for FindCherryPickedCommit.

Jump to

Keyboard shortcuts

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