github

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package github is loupe's narrow view of the GitHub REST API, behind an interface so tests can fake it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	PullRequest(ctx context.Context, owner, repo string, number int) (PullRequest, error)
	PullRequestsForBranch(ctx context.Context, owner, repo, headOwner, branch string) ([]PullRequest, error)
	Viewer(ctx context.Context) (string, error)
	ListReviews(ctx context.Context, owner, repo string, number int) ([]Review, error)
	CreateReview(ctx context.Context, owner, repo string, number int, req ReviewRequest) (Review, error)
	Compare(ctx context.Context, owner, repo, base, head string) (Comparison, error)
}

type Commit

type Commit struct {
	SHA     string
	Message string
}

type ComparedFile

type ComparedFile struct {
	Filename         string
	PreviousFilename string
}

type Comparison

type Comparison struct {
	Status  string
	AheadBy int
	Commits []Commit
	// Files stops at GitHub's cap of 300 files.
	Files []ComparedFile
}

Comparison is what head adds to base. Status is GitHub's: ahead only when base is an ancestor of head.

type HTTPError

type HTTPError struct {
	Status  int
	Message string
}

HTTPError is a response GitHub actually sent. Anything else (transport failure, timeout) leaves the outcome of a write unknown.

func (*HTTPError) Definite

func (e *HTTPError) Definite() bool

Definite reports whether GitHub rejected the request outright; a 5xx may still have recorded a write.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type PullRequest

type PullRequest struct {
	Number  int
	URL     string
	Title   string
	State   string
	Author  string
	BaseRef string
	BaseSHA string
	HeadSHA string
	// HeadOwner and HeadRepo name the repository the head lives in, a fork for a cross-repository pull request. Both are
	// empty once that fork is deleted.
	HeadOwner string
	HeadRepo  string
}

type REST

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

func NewREST

func NewREST(transport http.RoundTripper) (*REST, error)

NewREST uses gh's stored token for github.com. A nil transport means the default.

func NewRESTWithToken

func NewRESTWithToken(transport http.RoundTripper, token string) (*REST, error)

NewRESTWithToken skips gh's token lookup so tests never read the developer's credentials.

func (*REST) Compare

func (c *REST) Compare(ctx context.Context, owner, repo, base, head string) (Comparison, error)

func (*REST) CreateReview

func (c *REST) CreateReview(ctx context.Context, owner, repo string, number int, req ReviewRequest) (Review, error)

func (*REST) ListReviews

func (c *REST) ListReviews(ctx context.Context, owner, repo string, number int) ([]Review, error)

func (*REST) PullRequest

func (c *REST) PullRequest(ctx context.Context, owner, repo string, number int) (PullRequest, error)

func (*REST) PullRequestsForBranch

func (c *REST) PullRequestsForBranch(ctx context.Context, owner, repo, headOwner, branch string) ([]PullRequest, error)

func (*REST) Viewer

func (c *REST) Viewer(ctx context.Context) (string, error)

type Review

type Review struct {
	ID       int64
	User     string
	CommitID string
	State    string
	Body     string
	HTMLURL  string
}

type ReviewComment

type ReviewComment struct {
	Path      string `json:"path"`
	Line      int    `json:"line"`
	Side      string `json:"side"`
	StartLine int    `json:"start_line,omitempty"`
	StartSide string `json:"start_side,omitempty"`
	Body      string `json:"body"`
}

type ReviewRequest

type ReviewRequest struct {
	CommitID string          `json:"commit_id"`
	Body     string          `json:"body"`
	Event    string          `json:"event"`
	Comments []ReviewComment `json:"comments,omitempty"`
}

Jump to

Keyboard shortcuts

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