github

package
v0.0.0-...-52ee643 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package github provides a low-level client for the GitHub REST and GraphQL APIs.

Index

Constants

View Source
const (
	// API is the default GitHub API base URL.
	API = "https://api.github.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckRun

type CheckRun struct {
	Name        string    `json:"name"`
	StartedAt   time.Time `json:"started_at"`
	CompletedAt time.Time `json:"completed_at"`
	Conclusion  string    `json:"conclusion"`
	Status      string    `json:"status"`
	Output      struct {
		Title   string `json:"title"`
		Summary string `json:"summary"`
	} `json:"output"`
}

CheckRun represents a GitHub check run from the REST API.

type CheckRuns

type CheckRuns struct {
	CheckRuns []*CheckRun `json:"check_runs"`
}

CheckRuns represents a list of GitHub check runs.

type Client

type Client struct {
	HTTPClient *http.Client
	Token      string
	BaseURL    string
}

Client is a low-level client for interacting with the GitHub API.

func (*Client) Collaborators

func (c *Client) Collaborators(ctx context.Context, owner, repo string) (map[string]string, error)

Collaborators fetches all users with repository access and their permission levels. Returns a map of username -> permission level ("admin", "write", "read", "none"). Uses affiliation=all to include direct collaborators, org members, and outside collaborators.

func (*Client) Do

func (c *Client) Do(ctx context.Context, path string) ([]byte, *Response, error)

Do performs an HTTP GET request to the GitHub API.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, v any) (*Response, error)

Get makes a GET request to the GitHub API and decodes the response into v.

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 query and variables are sent as JSON, and the response is decoded into result.

func (*Client) Raw

func (c *Client) Raw(ctx context.Context, path string) (json.RawMessage, *Response, error)

Raw makes a GET request to the GitHub API and returns the raw JSON response.

type Error

type Error struct {
	Status     string
	Body       string
	URL        string
	StatusCode int
}

Error represents an error response from the GitHub API.

func (*Error) Error

func (e *Error) Error() string

type Option

type Option func(*Platform)

Option configures a Platform.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets a custom base URL for the GitHub API.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets a custom HTTP client for the GitHub platform.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets a custom logger for the GitHub platform.

type Platform

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

Platform implements the prx.Platform interface for GitHub.

func NewPlatform

func NewPlatform(token string, opts ...Option) *Platform

NewPlatform creates a new GitHub platform client.

func NewTestPlatform

func NewTestPlatform(token, baseURL string) *Platform

NewTestPlatform creates a Platform for testing with a custom base URL. Exported for use in prx package tests.

func (*Platform) FetchPR

func (p *Platform) FetchPR(ctx context.Context, owner, repo string, number int, refTime time.Time) (*prx.PullRequestData, error)

FetchPR retrieves a pull request with all events and metadata.

func (*Platform) Name

func (*Platform) Name() string

Name returns the platform identifier.

type Response

type Response struct {
	NextPage int
}

Response wraps a GitHub API response with pagination info.

type Ruleset

type Ruleset struct {
	Name   string `json:"name"`
	Target string `json:"target"`
	Rules  []struct {
		Type       string `json:"type"`
		Parameters struct {
			RequiredStatusChecks []struct {
				Context string `json:"context"`
			} `json:"required_status_checks"`
		} `json:"parameters"`
	} `json:"rules"`
}

Ruleset represents a repository ruleset from the REST API.

type Transport

type Transport struct {
	Base http.RoundTripper
}

Transport wraps an http.RoundTripper with retry logic using exponential backoff with jitter.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface with retry logic.

type User

type User struct {
	Login string `json:"login"`
	Type  string `json:"type"`
}

User represents a GitHub user.

Jump to

Keyboard shortcuts

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