githubcli

package
v0.0.0-...-e21a11a Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: BSD-3-Clause, MIT Imports: 13 Imported by: 0

Documentation

Overview

Package githubcli will wrap `gh` CLI calls behind a testable adapter.

Index

Constants

View Source
const (
	NotificationSubjectTypePullRequest = "PullRequest"
	NotificationSubjectTypeIssue       = "Issue"
	NotificationSubjectTypeRelease     = "Release"
)

Variables

View Source
var (
	ErrUnavailable                  = errors.New("gh is unavailable")
	ErrUnauthenticated              = errors.New("gh is not authenticated")
	ErrInvalidConnectedUserResponse = errors.New("invalid connected user response")
	ErrEmptyConnectedUser           = errors.New("empty connected user response")
)
View Source
var (
	ErrInvalidNotificationResponse      = fmt.Errorf("invalid notification response")
	ErrInvalidIssueDetailResponse       = fmt.Errorf("invalid issue detail response")
	ErrInvalidReleaseDetailResponse     = fmt.Errorf("invalid release detail response")
	ErrMissingNotificationSubjectTarget = fmt.Errorf("missing notification subject target")
)
View Source
var (
	ErrMissingNotificationThreadID     = errors.New("missing notification thread id")
	ErrNotificationEndpointAuthRefused = errors.New("notification endpoint authentication refused")
)
View Source
var (
	ErrInvalidPullRequestBuildResponse = errors.New("invalid pull request build response")
	ErrPullRequestBuildInfoNotFound    = errors.New("pull request build info not found")
)
View Source
var (
	ErrMissingPullRequestIdentity = errors.New("missing pull request identity")
	ErrEmptyPullRequestComment    = errors.New("empty pull request comment")
)
View Source
var (
	ErrInvalidPullRequestDetailResponse        = fmt.Errorf("invalid pull request detail response")
	ErrInvalidPullRequestInlineCommentResponse = fmt.Errorf("invalid pull request inline comment response")
)
View Source
var (
	ErrInvalidReactionTarget   = errors.New("invalid reaction target")
	ErrInvalidReactionContent  = errors.New("invalid reaction content")
	ErrInvalidReactionResponse = errors.New("invalid reaction response")
)
View Source
var (
	ErrInvalidPullRequestReactionTargetsResponse            = fmt.Errorf("invalid pull request reaction targets response")
	ErrInvalidPullRequestReviewCommentReactionGroupsPayload = fmt.Errorf("invalid pull request review comment reaction groups response")
)
View Source
var (
	ErrMissingPullRequestBuildLink    = errors.New("missing pull request build link")
	ErrInvalidPullRequestBuildLink    = errors.New("invalid pull request build link")
	ErrPullRequestBuildRunJobNotFound = errors.New("pull request build run job not found")
)
View Source
var (
	ErrInvalidPullRequestResponse               = fmt.Errorf("invalid pull request response")
	ErrInvalidPullRequestReviewMetadataResponse = fmt.Errorf("invalid pull request review metadata response")
)
View Source
var ErrEmptyPullRequestReviewBody = errors.New("empty pull request review body")
View Source
var ErrEmptyPullRequestTitle = errors.New("empty pull request title")
View Source
var ErrInvalidAssignableUsersResponse = fmt.Errorf("invalid assignable users response")
View Source
var ErrInvalidPendingPullRequestReviewResponse = errors.New("invalid pending pull request review response")
View Source
var ErrInvalidPullRequestDiffFilesResponse = fmt.Errorf("invalid pull request diff files response")
View Source
var ErrInvalidPullRequestReviewCommentMutation = errors.New("invalid pull request review comment mutation")
View Source
var ErrInvalidPullRequestReviewSubmission = errors.New("invalid pull request review submission")
View Source
var ErrInvalidPullRequestReviewThreadMutation = errors.New("invalid pull request review thread mutation")
View Source
var ErrInvalidPullRequestReviewThreadReply = errors.New("invalid pull request review thread reply")
View Source
var ErrInvalidPullRequestReviewThreadResponse = errors.New("invalid pull request review thread response")
View Source
var ErrInvalidPullRequestReviewThreadTarget = errors.New("invalid pull request review thread target")
View Source
var ErrInvalidPullRequestReviewThreadsResponse = fmt.Errorf("invalid pull request review threads response")
View Source
var ErrInvalidPullRequestURL = errors.New("invalid GitHub pull request URL")
View Source
var ErrInvalidSubmittedPullRequestReviewResponse = errors.New("invalid submitted pull request review response")

Functions

func FormatAssignableUsersCommand

func FormatAssignableUsersCommand(repository string) string

func FormatPullRequestBuildRunCommand

func FormatPullRequestBuildRunCommand(repository string, check PullRequestStatusCheck) string

func FormatPullRequestBuildRunJobLogCommand

func FormatPullRequestBuildRunJobLogCommand(repository string, jobDatabaseID int) string

func FormatPullRequestBuildRunJobsCommand

func FormatPullRequestBuildRunJobsCommand(repository string, check PullRequestStatusCheck) string

func FormatPullRequestSearchCommand

func FormatPullRequestSearchCommand(commandArguments []string) string

Types

type Client

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

func NewClient

func NewClient() *Client

func NewClientWithRunner

func NewClientWithRunner(runner Runner) *Client

func (*Client) AddPullRequestReviewThread

func (client *Client) AddPullRequestReviewThread(pullRequestReviewID string, body string, target PullRequestReviewThreadTarget) error

func (*Client) AddPullRequestReviewThreadReply

func (client *Client) AddPullRequestReviewThreadReply(pullRequestReviewID string, pullRequestReviewThreadID string, body string) error

func (*Client) AddReaction

func (client *Client) AddReaction(subjectID string, content ReactionContent) error

func (*Client) ApprovePullRequest

func (client *Client) ApprovePullRequest(repository string, number int) error

func (*Client) CommentOnPullRequest

func (client *Client) CommentOnPullRequest(repository string, number int, body string) error

func (*Client) ConvertPullRequestToDraft

func (client *Client) ConvertPullRequestToDraft(repository string, number int) error

func (*Client) DeletePullRequestReviewComment

func (client *Client) DeletePullRequestReviewComment(commentID string) error

func (*Client) EditPullRequestDescription

func (client *Client) EditPullRequestDescription(repository string, number int, body string) error

func (*Client) EditPullRequestTitle

func (client *Client) EditPullRequestTitle(repository string, number int, title string) error

func (*Client) GetConnectedUser

func (client *Client) GetConnectedUser() (ConnectedUser, error)

func (*Client) GetIssueDetail

func (client *Client) GetIssueDetail(repository string, number int) (IssueDetail, error)

func (*Client) GetPendingPullRequestReviewID

func (client *Client) GetPendingPullRequestReviewID(repository string, number int) (string, bool, error)

func (*Client) GetPullRequestBuildInfo

func (client *Client) GetPullRequestBuildInfo(repository string, number int, check PullRequestStatusCheck) (PullRequestBuildInfo, error)

func (*Client) GetPullRequestBuildRun

func (client *Client) GetPullRequestBuildRun(repository string, check PullRequestStatusCheck) (string, error)

func (*Client) GetPullRequestBuildRunJobLog

func (client *Client) GetPullRequestBuildRunJobLog(repository string, jobDatabaseID int) (string, error)

func (*Client) GetPullRequestBuildRunJobLogForCheck

func (client *Client) GetPullRequestBuildRunJobLogForCheck(repository string, check PullRequestStatusCheck) (PullRequestBuildRunJob, string, error)

func (*Client) GetPullRequestBuildRunJobs

func (client *Client) GetPullRequestBuildRunJobs(repository string, check PullRequestStatusCheck) ([]PullRequestBuildRunJob, error)

func (*Client) GetPullRequestDetail

func (client *Client) GetPullRequestDetail(repository string, number int) (PullRequestDetail, error)

func (*Client) GetPullRequestDiff

func (client *Client) GetPullRequestDiff(repository string, number int) (PullRequestDiff, error)

func (*Client) GetReleaseDetail

func (client *Client) GetReleaseDetail(repository string, id int) (ReleaseDetail, error)

func (*Client) ListAssignableUsers

func (client *Client) ListAssignableUsers(repository string) ([]PullRequestAuthor, error)

func (*Client) ListNotifications

func (client *Client) ListNotifications() ([]Notification, error)

func (*Client) ListPullRequests

func (client *Client) ListPullRequests(commandArguments []string) ([]PullRequest, error)

func (*Client) MarkAllNotificationsDone

func (client *Client) MarkAllNotificationsDone(notifications []Notification) (int, error)

func (*Client) MarkAllNotificationsRead

func (client *Client) MarkAllNotificationsRead() (NotificationBulkReadResult, error)

func (*Client) MarkNotificationDone

func (client *Client) MarkNotificationDone(threadID string) error

func (*Client) MarkNotificationRead

func (client *Client) MarkNotificationRead(threadID string) error

func (*Client) MarkPullRequestReadyForReview

func (client *Client) MarkPullRequestReadyForReview(repository string, number int) error

func (*Client) OpenPullRequestInBrowser

func (client *Client) OpenPullRequestInBrowser(repository string, number int) error

func (*Client) RemoveReaction

func (client *Client) RemoveReaction(subjectID string, content ReactionContent) error

func (*Client) RequestChangesOnPullRequest

func (client *Client) RequestChangesOnPullRequest(repository string, number int, body string) error

func (*Client) ResolvePullRequestReviewThread

func (client *Client) ResolvePullRequestReviewThread(threadID string) error

func (*Client) ReviewPullRequestWithComment

func (client *Client) ReviewPullRequestWithComment(repository string, number int, body string) error

func (*Client) SquashMergePullRequest

func (client *Client) SquashMergePullRequest(repository string, number int) error

func (*Client) StartPendingPullRequestReview

func (client *Client) StartPendingPullRequestReview(repository string, number int) (string, error)

func (*Client) SubmitPullRequestReview

func (client *Client) SubmitPullRequestReview(pullRequestReviewID string, event PullRequestReviewEvent, body string) error

func (*Client) UnresolvePullRequestReviewThread

func (client *Client) UnresolvePullRequestReviewThread(threadID string) error

func (*Client) UpdatePullRequestAssignees

func (client *Client) UpdatePullRequestAssignees(repository string, number int, addLogins []string, removeLogins []string) error

func (*Client) UpdatePullRequestReviewComment

func (client *Client) UpdatePullRequestReviewComment(commentID string, body string) error

type CommandResult

type CommandResult struct {
	Stdout []byte
	Stderr []byte
}

type ConnectedUser

type ConnectedUser struct {
	Login       string `json:"login"`
	Name        string `json:"name"`
	Bio         string `json:"bio"`
	Company     string `json:"company"`
	Location    string `json:"location"`
	PublicRepos int    `json:"public_repos"`
	Followers   int    `json:"followers"`
	URL         string `json:"html_url"`
}

type IssueDetail

type IssueDetail struct {
	Title     string              `json:"title"`
	Number    int                 `json:"number"`
	URL       string              `json:"html_url"`
	Body      string              `json:"body"`
	Author    *PullRequestAuthor  `json:"user"`
	State     string              `json:"state"`
	CreatedAt string              `json:"created_at"`
	UpdatedAt string              `json:"updated_at"`
	Labels    []PullRequestLabel  `json:"labels"`
	Assignees []PullRequestAuthor `json:"assignees"`
	Comments  int                 `json:"comments"`
}

type Notification

type Notification struct {
	ID              string              `json:"id"`
	Done            bool                `json:"done"`
	Unread          bool                `json:"unread"`
	Reason          string              `json:"reason"`
	UpdatedAt       string              `json:"updated_at"`
	LastReadAt      string              `json:"last_read_at"`
	URL             string              `json:"url"`
	SubscriptionURL string              `json:"subscription_url"`
	Repository      Repository          `json:"repository"`
	Subject         NotificationSubject `json:"subject"`
}

func (Notification) IssueIdentity

func (notification Notification) IssueIdentity() (string, int, bool)

func (Notification) PullRequestSummary

func (notification Notification) PullRequestSummary() (PullRequest, bool)

func (Notification) ReleaseIdentity

func (notification Notification) ReleaseIdentity() (string, int, bool)

type NotificationBulkReadResult

type NotificationBulkReadResult struct {
	Accepted bool
}

type NotificationSubject

type NotificationSubject struct {
	Title            string `json:"title"`
	Type             string `json:"type"`
	URL              string `json:"url"`
	LatestCommentURL string `json:"latest_comment_url"`
}

type PullRequest

type PullRequest struct {
	ID                     string                     `json:"id"`
	Title                  string                     `json:"title"`
	Number                 int                        `json:"number"`
	Repository             Repository                 `json:"repository"`
	URL                    string                     `json:"url"`
	Body                   string                     `json:"body"`
	State                  string                     `json:"state"`
	IsDraft                bool                       `json:"isDraft"`
	UpdatedAt              string                     `json:"updatedAt"`
	ReviewDecision         string                     `json:"reviewDecision"`
	ReviewRequests         []PullRequestReviewRequest `json:"reviewRequests"`
	MergeStateStatus       string                     `json:"mergeStateStatus"`
	Mergeable              string                     `json:"mergeable"`
	StatusCheckRollupState string                     `json:"statusCheckRollupState"`
}

func ParsePullRequestURL

func ParsePullRequestURL(raw string) (PullRequest, error)

type PullRequestAuthor

type PullRequestAuthor struct {
	Login string `json:"login"`
	Name  string `json:"name"`
	IsBot bool   `json:"is_bot"`
}

type PullRequestBuildInfo

type PullRequestBuildInfo struct {
	Bucket      string `json:"bucket"`
	CompletedAt string `json:"completedAt"`
	Description string `json:"description"`
	Event       string `json:"event"`
	Link        string `json:"link"`
	Name        string `json:"name"`
	StartedAt   string `json:"startedAt"`
	State       string `json:"state"`
	Workflow    string `json:"workflow"`
}

type PullRequestBuildRunJob

type PullRequestBuildRunJob struct {
	DatabaseID int    `json:"databaseId"`
	Name       string `json:"name"`
	Status     string `json:"status"`
	Conclusion string `json:"conclusion"`
	URL        string `json:"url"`
}

type PullRequestComment

type PullRequestComment struct {
	ID              string                    `json:"id"`
	Author          *PullRequestCommentAuthor `json:"author"`
	Body            string                    `json:"body"`
	CreatedAt       string                    `json:"createdAt"`
	URL             string                    `json:"url"`
	DiffHunk        string                    `json:"diffHunk"`
	State           string                    `json:"state"`
	ViewerDidAuthor bool                      `json:"viewerDidAuthor"`
	ReactionGroups  []ReactionGroup           `json:"reactionGroups,omitempty"`
}

type PullRequestCommentAuthor

type PullRequestCommentAuthor struct {
	Login string `json:"login"`
}

type PullRequestCommit

type PullRequestCommit struct {
	OID             string                    `json:"oid"`
	MessageHeadline string                    `json:"messageHeadline"`
	MessageBody     string                    `json:"messageBody"`
	AuthoredDate    string                    `json:"authoredDate"`
	CommittedDate   string                    `json:"committedDate"`
	Authors         []PullRequestCommitAuthor `json:"authors"`
}

type PullRequestCommitAuthor

type PullRequestCommitAuthor struct {
	Login string `json:"login"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

type PullRequestDetail

type PullRequestDetail struct {
	ID                   string                     `json:"id,omitempty"`
	Title                string                     `json:"title"`
	Number               int                        `json:"number"`
	URL                  string                     `json:"url"`
	Body                 string                     `json:"body"`
	Author               *PullRequestAuthor         `json:"author"`
	State                string                     `json:"state"`
	IsDraft              bool                       `json:"isDraft"`
	CreatedAt            string                     `json:"createdAt"`
	UpdatedAt            string                     `json:"updatedAt"`
	Labels               []PullRequestLabel         `json:"labels"`
	Assignees            []PullRequestAuthor        `json:"assignees"`
	ReviewRequests       []PullRequestReviewRequest `json:"reviewRequests"`
	BaseRefName          string                     `json:"baseRefName"`
	HeadRefName          string                     `json:"headRefName"`
	MergeStateStatus     string                     `json:"mergeStateStatus"`
	Mergeable            string                     `json:"mergeable"`
	ReactionGroups       []ReactionGroup            `json:"reactionGroups,omitempty"`
	Comments             []PullRequestComment       `json:"comments"`
	Commits              []PullRequestCommit        `json:"commits"`
	Reviews              []PullRequestReview        `json:"reviews"`
	InlineComments       []PullRequestInlineComment `json:"-"`
	InlineCommentThreads []PullRequestReviewThread  `json:"-"`
	Additions            int                        `json:"additions"`
	Deletions            int                        `json:"deletions"`
	ChangedFiles         int                        `json:"changedFiles"`
	StatusCheckRollup    []PullRequestStatusCheck   `json:"statusCheckRollup"`
}

type PullRequestDiff

type PullRequestDiff struct {
	UnifiedDiff string
	Files       []PullRequestDiffFile
	Threads     []PullRequestReviewThread
}

type PullRequestDiffFile

type PullRequestDiffFile struct {
	Path         string `json:"filename"`
	PreviousPath string `json:"previous_filename"`
	ChangeType   string `json:"status"`
	Additions    int    `json:"additions"`
	Deletions    int    `json:"deletions"`
	Patch        string `json:"patch"`
}

type PullRequestInlineComment

type PullRequestInlineComment struct {
	ID                string                    `json:"node_id"`
	Author            *PullRequestCommentAuthor `json:"user"`
	Body              string                    `json:"body"`
	CreatedAt         string                    `json:"created_at"`
	URL               string                    `json:"html_url"`
	Path              string                    `json:"path"`
	DiffHunk          string                    `json:"diff_hunk"`
	Line              int                       `json:"line"`
	OriginalLine      int                       `json:"original_line"`
	StartLine         int                       `json:"start_line"`
	OriginalStartLine int                       `json:"original_start_line"`
	Side              string                    `json:"side"`
	StartSide         string                    `json:"start_side"`
	SubjectType       string                    `json:"subject_type"`
	ReactionGroups    []ReactionGroup           `json:"reactionGroups,omitempty"`
}

type PullRequestLabel

type PullRequestLabel struct {
	Name string `json:"name"`
}

type PullRequestRequestedReviewer

type PullRequestRequestedReviewer struct {
	TypeName     string                                `json:"__typename"`
	Login        string                                `json:"login"`
	Name         string                                `json:"name"`
	Slug         string                                `json:"slug"`
	Organization *PullRequestReviewRequestOrganization `json:"organization"`
}

type PullRequestReview

type PullRequestReview struct {
	Author      *PullRequestCommentAuthor `json:"author"`
	State       string                    `json:"state"`
	SubmittedAt string                    `json:"submittedAt"`
}

type PullRequestReviewEvent

type PullRequestReviewEvent string
const (
	PullRequestReviewEventComment        PullRequestReviewEvent = "COMMENT"
	PullRequestReviewEventApprove        PullRequestReviewEvent = "APPROVE"
	PullRequestReviewEventRequestChanges PullRequestReviewEvent = "REQUEST_CHANGES"
)

type PullRequestReviewRequest

type PullRequestReviewRequest struct {
	RequestedReviewer PullRequestRequestedReviewer `json:"requestedReviewer"`
}

func (*PullRequestReviewRequest) UnmarshalJSON

func (reviewRequest *PullRequestReviewRequest) UnmarshalJSON(data []byte) error

type PullRequestReviewRequestOrganization

type PullRequestReviewRequestOrganization struct {
	Login string `json:"login"`
}

type PullRequestReviewThread

type PullRequestReviewThread struct {
	ID                 string               `json:"id"`
	IsResolved         bool                 `json:"isResolved"`
	IsOutdated         bool                 `json:"isOutdated"`
	ViewerCanResolve   bool                 `json:"viewerCanResolve"`
	ViewerCanUnresolve bool                 `json:"viewerCanUnresolve"`
	Path               string               `json:"path"`
	Line               int                  `json:"line"`
	OriginalLine       int                  `json:"originalLine"`
	StartLine          int                  `json:"startLine"`
	OriginalStartLine  int                  `json:"originalStartLine"`
	DiffSide           string               `json:"diffSide"`
	StartDiffSide      string               `json:"startDiffSide"`
	Comments           []PullRequestComment `json:"-"`
}

type PullRequestReviewThreadTarget

type PullRequestReviewThreadTarget struct {
	Path        string
	Line        int
	Side        string
	StartLine   int
	StartSide   string
	SubjectType string
}

type PullRequestStatusCheck

type PullRequestStatusCheck struct {
	TypeName     string `json:"__typename"`
	Name         string `json:"name"`
	Status       string `json:"status"`
	Conclusion   string `json:"conclusion"`
	WorkflowName string `json:"workflowName"`
	Link         string `json:"link,omitempty"`
}

type ReactionContent

type ReactionContent string
const (
	ReactionContentThumbsUp   ReactionContent = "+1"
	ReactionContentThumbsDown ReactionContent = "-1"
	ReactionContentLaugh      ReactionContent = "laugh"
	ReactionContentHooray     ReactionContent = "hooray"
	ReactionContentConfused   ReactionContent = "confused"
	ReactionContentHeart      ReactionContent = "heart"
	ReactionContentRocket     ReactionContent = "rocket"
	ReactionContentEyes       ReactionContent = "eyes"
)

type ReactionGroup

type ReactionGroup struct {
	Content          ReactionContent `json:"content"`
	TotalCount       int             `json:"totalCount"`
	ViewerHasReacted bool            `json:"viewerHasReacted"`
}

func (*ReactionGroup) UnmarshalJSON

func (group *ReactionGroup) UnmarshalJSON(data []byte) error

type ReleaseDetail

type ReleaseDetail struct {
	Name        string             `json:"name"`
	TagName     string             `json:"tag_name"`
	URL         string             `json:"html_url"`
	Body        string             `json:"body"`
	Draft       bool               `json:"draft"`
	PreRelease  bool               `json:"prerelease"`
	CreatedAt   string             `json:"created_at"`
	UpdatedAt   string             `json:"updated_at"`
	PublishedAt string             `json:"published_at"`
	Author      *PullRequestAuthor `json:"author"`
}

type Repository

type Repository struct {
	Name          string `json:"name"`
	NameWithOwner string `json:"nameWithOwner"`
}

func (*Repository) UnmarshalJSON

func (repository *Repository) UnmarshalJSON(data []byte) error

type Runner

type Runner interface {
	Run(name string, args ...string) (CommandResult, error)
	RunWithInput(name string, input []byte, args ...string) (CommandResult, error)
}

Jump to

Keyboard shortcuts

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