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
- Variables
- func ParseGitHubRemote(remoteURL string) (owner, repo string, err error)
- type Client
- func (c *Client) AddIssueToProject(ctx context.Context, projectID string, issueID string) error
- func (c *Client) CreateRepo(ctx context.Context, owner, name, description string, isPrivate bool) (*github.Repository, error)
- func (c *Client) GetAuthenticatedUserLogin(ctx context.Context) (string, error)
- func (c *Client) GetProjectByNumber(ctx context.Context, number int) (*ProjectWithID, error)
- func (c *Client) ListProjects(ctx context.Context) ([]Project, error)
- func (c *Client) UpdateBranchProtection(ctx context.Context, branch string, request github.ProtectionRequest) error
- type Project
- type ProjectWithID
Constants ¶
const GHTokenEnvVar = "GITHUB_TOKEN"
GHTokenEnvVar is the environment variable name for the GitHub token.
const PassTokenKey = "github/token"
PassTokenKey is the key used in the password store.
Variables ¶
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") // ErrPassCommandNotFound is returned when the 'pass' command is not available. ErrPassCommandNotFound = errors.New("'pass' command not found") // ErrPassOutputEmpty is returned when 'pass' returns no output. ErrPassOutputEmpty = errors.New("pass output was empty") )
Functions ¶
func ParseGitHubRemote ¶
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 ¶
NewClient creates a new GitHub client. It first checks the GITHUB_TOKEN environment variable. If not found, it attempts to retrieve the token from 'pass' (github/token).
func (*Client) AddIssueToProject ¶
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 ¶
GetAuthenticatedUserLogin returns the login name of the user authenticated by the token.
func (*Client) GetProjectByNumber ¶
GetProjectByNumber fetches a single project by its number to get its GraphQL Node ID.
func (*Client) ListProjects ¶
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.