github

package
v0.4.1-rc3 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package github provides a client for interacting with the GitHub API. It wraps both the REST API (google/go-github) and the GraphQL API (shurcooL/githubv4), providing high-level methods for operations like listing projects, managing issues, and repository creation.

Index

Constants

View Source
const GHTokenEnvVar = "GITHUB_TOKEN"

GHTokenEnvVar is the environment variable name for the GitHub token.

Variables

View Source
var (

	// ErrInvalidRemoteURL is returned when the remote URL is invalid.
	ErrInvalidRemoteURL = errors.New("invalid remote URL")
	// ErrTokenNotFound is returned when the GitHub token is not found.
	ErrTokenNotFound = errors.New("GitHub token not found")
	// ErrProjectNotFound is returned when a project is not found.
	ErrProjectNotFound = errors.New("project not found")
	// ErrInvalidProjectID is returned when a project ID is invalid.
	ErrInvalidProjectID = errors.New("invalid project ID")
	// ErrUserLoginNotFound is returned when the user login cannot be determined.
	ErrUserLoginNotFound = errors.New("could not determine user login")
	// ErrRepoAlreadyExists is returned when a repository already exists.
	ErrRepoAlreadyExists = errors.New("repository already exists")
	// ErrRepoNotFoundOrAuth is returned when a repository is not found or auth fails.
	ErrRepoNotFoundOrAuth = errors.New("repository not found or token lacks permission")
)

Functions

func ParseGitHubRemote

func ParseGitHubRemote(remoteURL string) (owner, repo string, err error)

ParseGitHubRemote extracts the owner and repository name from a GitHub remote URL.

Types

type Client

type Client struct {
	*github.Client

	GraphQL *githubv4.Client
	// contains filtered or unexported fields
}

Client wraps the go-github clients for both REST and GraphQL APIs.

func NewClient

func NewClient(ctx context.Context, logger *slog.Logger, owner, repo string) (*Client, error)

NewClient creates a new GitHub client, authenticating using the GITHUB_TOKEN environment variable.

func (*Client) AddIssueToProject

func (c *Client) AddIssueToProject(ctx context.Context, projectID string, issueID string) error

AddIssueToProject adds an issue (by its GraphQL Node ID) to a project (by its GraphQL Node ID).

func (*Client) CreateRepo

func (c *Client) CreateRepo(
	ctx context.Context,
	owner, name, description string,
	isPrivate bool,
) (*github.Repository, error)

CreateRepo creates a new repository on GitHub for a specific owner (user or org).

func (*Client) GetAuthenticatedUserLogin

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

GetAuthenticatedUserLogin returns the login name of the user authenticated by the token.

func (*Client) GetProjectByNumber

func (c *Client) GetProjectByNumber(ctx context.Context, number int) (*ProjectWithID, error)

GetProjectByNumber fetches a single project by its number to get its GraphQL Node ID.

func (*Client) ListProjects

func (c *Client) ListProjects(ctx context.Context) ([]Project, error)

ListProjects fetches the first 100 GitHub Projects (V2) for the repository's owner.

func (*Client) UpdateBranchProtection

func (c *Client) UpdateBranchProtection(
	ctx context.Context,
	branch string,
	request github.ProtectionRequest,
) error

UpdateBranchProtection applies a set of protection rules to the client's configured branch.

type Project

type Project struct {
	Title  string
	Number int
	URL    string
}

Project represents a GitHub Project (V2) for listing.

type ProjectWithID

type ProjectWithID struct {
	ID     string
	Title  string
	Number int
	URL    string
}

ProjectWithID represents a GitHub Project (V2) with its GraphQL Node ID.

Jump to

Keyboard shortcuts

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