github

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 15 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)
	// ListReviewThreads reads every inline thread with its comments, since only GraphQL carries a thread's resolved state.
	ListReviewThreads(ctx context.Context, owner, repo string, number int) ([]ReviewThread, error)
	ListIssueComments(ctx context.Context, owner, repo string, number int) ([]IssueComment, error)
	CreateReview(ctx context.Context, owner, repo string, number int, req ReviewRequest) (Review, error)
	// UpdateReview replaces a submitted review's body, and nothing else about it.
	UpdateReview(ctx context.Context, owner, repo string, number int, id int64, body string) (Review, error)
	// PullRequestCommits lists the pull request's commits, which loupe assumes are oldest first, since GitHub documents
	// no order. GitHub stops at 250.
	PullRequestCommits(ctx context.Context, owner, repo string, number int) ([]Commit, error)
	Compare(ctx context.Context, owner, repo, base, head string) (Comparison, error)
	TokenKind() TokenKind
}

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 IssueComment added in v0.13.0

type IssueComment struct {
	ID        int64
	User      string
	Body      string
	HTMLURL   string
	CreatedAt time.Time
}

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) ListIssueComments added in v0.13.0

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

func (*REST) ListReviewThreads added in v0.13.0

func (c *REST) ListReviewThreads(ctx context.Context, owner, repo string, number int) ([]ReviewThread, 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) PullRequestCommits added in v0.15.0

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

func (*REST) PullRequestsForBranch

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

func (*REST) TokenKind added in v0.6.0

func (c *REST) TokenKind() TokenKind

func (*REST) UpdateReview added in v0.11.0

func (c *REST) UpdateReview(ctx context.Context, owner, repo string, number int, id int64, body string) (Review, 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
	SubmittedAt time.Time
}

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"`
}

type ReviewThread added in v0.13.0

type ReviewThread struct {
	Path         string
	Line         int
	OriginalLine int
	Side         string
	Resolved     bool
	Outdated     bool
	Comments     []ThreadComment
}

ReviewThread is one inline conversation. Line is 0 when the thread is outdated or on a whole file, and OriginalLine is the line it was left on.

type ThreadComment added in v0.13.0

type ThreadComment struct {
	ReviewID  int64
	User      string
	Body      string
	URL       string
	CreatedAt time.Time
}

ThreadComment's ReviewID is the REST id of the review that posted it, 0 when GitHub names none.

type TokenKind added in v0.6.0

type TokenKind string

TokenKind tells an App installation token, which posts as the App, from every token that acts as a person.

const (
	Installation TokenKind = "installation"
	User         TokenKind = "user"
)

Jump to

Keyboard shortcuts

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