github

package
v0.0.0-...-72f1ef6 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package github provides a GitHub API client for GitHub App interactions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the GitHub API client.

func New

func New(ctx context.Context, appID, privateKeyPEM, installationID string) (*Client, error)

New creates a new GitHub client configured as a GitHub App.

func (*Client) Client

func (c *Client) Client() any

Client returns the underlying GitHub client.

func (*Client) FindPRsForCommit

func (c *Client) FindPRsForCommit(ctx context.Context, owner, repo, sha string) ([]int, error)

FindPRsForCommit finds all open PRs associated with a commit SHA.

func (*Client) InstallationToken

func (c *Client) InstallationToken(ctx context.Context) string

InstallationToken returns the current installation token, refreshing if needed. This method is safe to call concurrently - only one goroutine will perform the refresh.

func (*Client) Organization

func (c *Client) Organization() string

Organization returns the organization associated with this installation.

func (*Client) RefreshToken

func (c *Client) RefreshToken(ctx context.Context) error

RefreshToken forces a token refresh.

type ClientInterface

type ClientInterface interface {
	// Client returns the underlying go-github client for advanced operations.
	Client() any

	// InstallationToken returns the current installation token for authentication.
	InstallationToken(ctx context.Context) string
}

ClientInterface defines the interface for GitHub API operations. This interface enables testing of code that depends on Client.

type GraphQLClient

type GraphQLClient = SearchClient

GraphQLClient is a deprecated alias for SearchClient for backwards compatibility. Use SearchClient instead.

func NewGraphQLClient

func NewGraphQLClient(ctx context.Context, token string) *GraphQLClient

NewGraphQLClient creates a new search client (deprecated name). Use NewSearchClient instead.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages multiple GitHub App installations.

func NewManager

func NewManager(ctx context.Context, appID, privateKeyPEM string, allowPersonalAccounts bool) (*Manager, error)

NewManager creates a new installation manager.

func (*Manager) AllOrgs

func (m *Manager) AllOrgs() []string

AllOrgs returns a list of all organizations with active installations.

func (*Manager) ClientForOrg

func (m *Manager) ClientForOrg(org string) (*Client, bool)

ClientForOrg returns the GitHub client for a specific organization.

func (*Manager) RefreshInstallations

func (m *Manager) RefreshInstallations(ctx context.Context) error

RefreshInstallations discovers all installations and creates clients for them.

type ManagerInterface

type ManagerInterface interface {
	// AllOrgs returns all configured organizations.
	AllOrgs() []string

	// ClientForOrg returns the GitHub client for a specific organization.
	ClientForOrg(org string) (ClientInterface, bool)
}

ManagerInterface defines the interface for GitHub installation management. This interface enables testing of code that depends on Manager.

func WrapManager

func WrapManager(m *Manager) ManagerInterface

WrapManager wraps a Manager to implement ManagerInterface. This is needed because Manager.ClientForOrg returns *Client, but ManagerInterface.ClientForOrg must return ClientInterface.

type PRInfo

type PRInfo struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	Owner     string
	Repo      string
	Title     string
	Author    string
	State     string
	URL       string
	BlockedOn []string
	Number    int
}

PRInfo contains simplified PR information.

type PRSnapshot

type PRSnapshot struct {
	UpdatedAt time.Time
	CreatedAt time.Time
	Owner     string
	Repo      string
	Title     string
	Author    string
	URL       string
	State     string // "OPEN", "CLOSED", "MERGED"
	Number    int
	IsDraft   bool
}

PRSnapshot contains minimal PR information from search query.

type SearchClient

type SearchClient struct {
	// contains filtered or unexported fields
}

SearchClient wraps the GitHub Search API client for querying PRs.

func NewSearchClient

func NewSearchClient(ctx context.Context, token string) *SearchClient

NewSearchClient creates a new search client with the given token.

func (*SearchClient) ListClosedPRs

func (c *SearchClient) ListClosedPRs(ctx context.Context, org string, updatedSinceHours int) ([]PRSnapshot, error)

ListClosedPRs queries all closed/merged PRs for an organization updated in the last N hours. This is used to update Slack threads when PRs are closed or merged.

func (*SearchClient) ListOpenPRs

func (c *SearchClient) ListOpenPRs(ctx context.Context, org string, updatedSinceHours int) ([]PRSnapshot, error)

ListOpenPRs queries all open PRs for an organization updated in the last N hours. Uses GitHub Search API which is simpler and more reliable than GraphQL.

type TurnClient

type TurnClient interface {
	Check(ctx context.Context, prURL, username string, eventTime time.Time) (*turn.CheckResponse, error)
}

TurnClient is an interface for PR analysis.

func NewTurnClient

func NewTurnClient(token string) (TurnClient, error)

NewTurnClient creates a turnclient with the given token.

Jump to

Keyboard shortcuts

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