Documentation
¶
Overview ¶
Package github wraps the GitHub CLI operations live-pr needs.
Index ¶
- Constants
- Variables
- func SaveCache(path string, c Cache) error
- func SaveNavigatorCache(path string, c NavigatorCache) error
- func SaveReviewDraft(path string, draft ReviewDraft) error
- func StatusHint(err error) string
- func ValidateReviewComment(comment ReviewComment) error
- func ValidateReviewDraft(draft ReviewDraft) error
- func ValidateReviewEvent(event ReviewEvent) error
- type Activity
- type Cache
- type Client
- func (c Client) Checkout(number int) error
- func (c Client) Close(number int) error
- func (c Client) Create(base, head, title, bodyFile string, draft bool) (string, error)
- func (c Client) DeleteIssueComment(id int64) error
- func (c Client) EditIssueComment(id int64, body string) error
- func (c Client) Find(number int) (PR, error)
- func (c Client) FindAllForHead(head string) ([]PR, error)
- func (c Client) FindChecks(number int) (PR, error)
- func (c Client) FindForHead(head string) (PR, error)
- func (c Client) FindOpen(head string) (PR, error)
- func (c Client) FindPreview(number int) (PR, error)
- func (c Client) IssueActivities(number int) ([]Activity, error)
- func (c Client) IssueComments(number int) ([]Comment, error)
- func (c Client) LoadPRDetail(number int, prev PRDetail) PRDetail
- func (c Client) Merge(number int, headOID string, method MergeMethod) error
- func (c Client) PostIssueComment(number int, body string) error
- func (c Client) ReviewComments(number int) ([]ReviewThreadComment, error)
- func (c Client) Reviews(number int) ([]Review, error)
- func (c Client) SearchPRs(query, cursor string) (PRPage, error)
- func (c Client) SetStatus(pr PR, target string) error
- func (c Client) SubmitReview(draft ReviewDraft, event ReviewEvent) error
- func (c Client) Update(number int, title, bodyFile string) error
- func (c Client) UpdateBody(number int, bodyFile string) error
- type Comment
- type IssueRef
- type MergeMethod
- type NavigatorCache
- func (c NavigatorCache) Clone() NavigatorCache
- func (c *NavigatorCache) PrunePRs()
- func (c *NavigatorCache) SetSnapshot(snapshot PRSnapshot)
- func (c *NavigatorCache) SetView(name string, prs []PR, total int, fetchedAt string)
- func (c NavigatorCache) Snapshot(number int) (PRSnapshot, bool)
- func (c NavigatorCache) View(name string) ([]PR, PRViewCache, bool)
- type PR
- type PRCheck
- type PRCommit
- type PRConversationComment
- type PRDetail
- type PRLabel
- type PRPage
- type PRSnapshot
- type PRUser
- type PRViewCache
- type PageInfo
- type Review
- type ReviewComment
- type ReviewDraft
- type ReviewEvent
- type ReviewThreadComment
Constants ¶
const CacheVersion = 1
const PRPageSize = 25
Variables ¶
var ErrPRNotFound = errors.New("pull request not found")
ErrPRNotFound means no open pull request exists for the requested head.
Functions ¶
func SaveNavigatorCache ¶
func SaveNavigatorCache(path string, c NavigatorCache) error
func SaveReviewDraft ¶ added in v0.2.0
func SaveReviewDraft(path string, draft ReviewDraft) error
func StatusHint ¶ added in v0.6.8
StatusHint classifies a fetch failure for the status line so the TUI can tell setup problems apart from being offline. It returns "" when the failure looks like plain network trouble — callers keep their existing offline wording — and a short actionable hint otherwise. Deliberately a dumb string check over the flat error text runError/commandError build.
func ValidateReviewComment ¶ added in v0.2.0
func ValidateReviewComment(comment ReviewComment) error
func ValidateReviewDraft ¶ added in v0.2.0
func ValidateReviewDraft(draft ReviewDraft) error
func ValidateReviewEvent ¶ added in v0.2.0
func ValidateReviewEvent(event ReviewEvent) error
Types ¶
type Activity ¶
type Activity struct {
ID int64 `json:"id"`
NodeID string `json:"node_id"`
Event string `json:"event"`
CreatedAt string `json:"created_at"`
CommitID string `json:"commit_id"`
Actor struct {
Login string `json:"login"`
AvatarURL string `json:"avatar_url,omitempty"`
} `json:"actor"`
Label struct {
Name string `json:"name"`
} `json:"label"`
Assignee struct {
Login string `json:"login"`
} `json:"assignee"`
RequestedReviewer struct {
Login string `json:"login"`
} `json:"requested_reviewer"`
Rename struct {
From string `json:"from"`
To string `json:"to"`
} `json:"rename"`
}
Activity is a non-comment PR timeline event from GitHub's issue events API.
type Cache ¶
type Cache struct {
Version int `json:"version"`
Head string `json:"head,omitempty"`
PR *PR `json:"pr,omitempty"`
ExplicitCheckout bool `json:"explicit_checkout,omitempty"`
Comments []Comment `json:"comments,omitempty"`
Activities []Activity `json:"activities,omitempty"`
Reviews []Review `json:"reviews,omitempty"`
ReviewComments []ReviewThreadComment `json:"review_comments,omitempty"`
FetchedAt string `json:"fetched_at,omitempty"`
LastPublishedManagedBodyHash string `json:"last_published_managed_body_hash,omitempty"`
}
Cache is branch-local mutable GitHub state. Remote resources intentionally stay separate from the append-only local timeline.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client runs GitHub operations through gh.
func (Client) Checkout ¶
Checkout checks out a pull request using GitHub CLI's native branch handling.
func (Client) DeleteIssueComment ¶ added in v0.5.1
DeleteIssueComment removes a conversation comment by its ID.
func (Client) EditIssueComment ¶ added in v0.5.0
EditIssueComment updates an existing conversation comment by its ID.
func (Client) FindAllForHead ¶ added in v0.5.0
FindAllForHead returns every PR (any state) whose head is the given branch.
func (Client) FindChecks ¶ added in v0.2.0
FindChecks loads only the current head revision and its CI rollup. FindChecks polls the CI state. It also carries the pull request state: this call outlives a merge, and the poller needs to know when to stop.
func (Client) FindForHead ¶
FindForHead prefers an open PR, then returns the newest PR in any state. When multiple PRs share the same head branch, the newest (highest number) wins.
func (Client) FindOpen ¶
FindOpen finds the open PR for head. Operational errors are returned as-is; only a successful empty list becomes ErrPRNotFound.
func (Client) FindPreview ¶
FindPreview loads the expensive preview fields for one PR only.
func (Client) IssueActivities ¶
IssueActivities returns non-comment activity from the PR timeline.
func (Client) IssueComments ¶
IssueComments returns every top-level Conversation comment for a PR.
func (Client) LoadPRDetail ¶
LoadPRDetail loads preview metadata, comments, and activity concurrently. prev is the caller's cached snapshot of the same PR: when it carries comments, only those created or updated since the newest cached updated_at are fetched and merged in by ID. An empty prev, a number mismatch, or any doubt about the cache loads everything, exactly like a first load.
func (Client) Merge ¶
func (c Client) Merge(number int, headOID string, method MergeMethod) error
Merge merges a pull request with the given method.
func (Client) PostIssueComment ¶ added in v0.5.0
PostIssueComment posts a conversation comment on a pull request.
func (Client) ReviewComments ¶ added in v0.5.0
func (c Client) ReviewComments(number int) ([]ReviewThreadComment, error)
ReviewComments returns the inline review comments for a pull request.
func (Client) SearchPRs ¶
SearchPRs returns exactly one page. Callers decide when to request PageInfo.EndCursor.
func (Client) SetStatus ¶ added in v0.2.1
SetStatus changes a pull request to open, closed, or draft.
func (Client) SubmitReview ¶ added in v0.2.0
func (c Client) SubmitReview(draft ReviewDraft, event ReviewEvent) error
SubmitReview publishes a complete review and its inline comments atomically.
type Comment ¶
type Comment struct {
ID int64 `json:"id"`
NodeID string `json:"node_id"`
Body string `json:"body"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
HTMLURL string `json:"html_url"`
User struct {
Login string `json:"login"`
AvatarURL string `json:"avatar_url,omitempty"`
} `json:"user"`
}
Comment is a top-level PR conversation comment.
type MergeMethod ¶ added in v0.6.8
type MergeMethod string
MergeMethod selects how gh lands a pull request.
const ( MergeCommit MergeMethod = "merge" MergeSquash MergeMethod = "squash" MergeRebase MergeMethod = "rebase" )
type NavigatorCache ¶
type NavigatorCache struct {
}
NavigatorCache is repository-wide browse state. Publish conflict state remains in the branch-local Cache and is intentionally absent here.
func LoadNavigatorCache ¶
func LoadNavigatorCache(path string) (NavigatorCache, error)
func NewNavigatorCache ¶
func NewNavigatorCache() NavigatorCache
func (NavigatorCache) Clone ¶ added in v0.5.4
func (c NavigatorCache) Clone() NavigatorCache
Clone returns a copy that is safe to marshal while the original keeps mutating: the PRs backing array is rewritten in place by preview updates and the maps by SetView/SetSnapshot, but their values are only ever replaced wholesale, so element copies suffice.
func (*NavigatorCache) PrunePRs ¶
func (c *NavigatorCache) PrunePRs()
func (*NavigatorCache) SetSnapshot ¶
func (c *NavigatorCache) SetSnapshot(snapshot PRSnapshot)
func (*NavigatorCache) SetView ¶
func (c *NavigatorCache) SetView(name string, prs []PR, total int, fetchedAt string)
func (NavigatorCache) Snapshot ¶
func (c NavigatorCache) Snapshot(number int) (PRSnapshot, bool)
func (NavigatorCache) View ¶
func (c NavigatorCache) View(name string) ([]PR, PRViewCache, bool)
type PR ¶
type PR struct {
Number int `json:"number"`
URL string `json:"url"`
Title string `json:"title"`
Body string `json:"body"`
State string `json:"state"`
BaseRefName string `json:"baseRefName,omitempty"`
BaseRefOID string `json:"baseRefOid,omitempty"`
HeadRefName string `json:"headRefName,omitempty"`
HeadRefOID string `json:"headRefOid,omitempty"`
IsDraft bool `json:"isDraft,omitempty"`
IsCrossRepository bool `json:"isCrossRepository,omitempty"`
Mergeable string `json:"mergeable,omitempty"`
MergeStateStatus string `json:"mergeStateStatus,omitempty"`
ReviewDecision string `json:"reviewDecision,omitempty"`
Additions int `json:"additions,omitempty"`
Deletions int `json:"deletions,omitempty"`
ChangedFiles int `json:"changedFiles,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
Conversation []PRConversationComment `json:"comments,omitempty"`
CommentCount int `json:"commentCount,omitempty"`
CommitCount int `json:"commitCount,omitempty"`
Commits []PRCommit `json:"commits,omitempty"`
Checks []PRCheck `json:"statusCheckRollup,omitempty"`
CheckRollupState string `json:"checkRollupState,omitempty"`
Author PRUser `json:"author,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
Assignees []PRUser `json:"assignees,omitempty"`
Labels []PRLabel `json:"labels,omitempty"`
ReviewRequests []PRUser `json:"reviewRequests,omitempty"`
ClosingIssues []IssueRef `json:"closingIssues,omitempty"`
ViewerReviewRequested bool `json:"viewerReviewRequested,omitempty"`
PreviewLoaded bool `json:"previewLoaded,omitempty"`
}
PR is the remote pull-request state needed by live-pr.
type PRCheck ¶
type PRCheck struct {
Name string `json:"name,omitempty"`
Context string `json:"context,omitempty"`
Status string `json:"status,omitempty"`
Conclusion string `json:"conclusion,omitempty"`
State string `json:"state,omitempty"`
WorkflowName string `json:"workflowName,omitempty"`
StartedAt string `json:"startedAt,omitempty"`
CompletedAt string `json:"completedAt,omitempty"`
DetailsURL string `json:"detailsUrl,omitempty"`
TargetURL string `json:"targetUrl,omitempty"`
}
PRCheck covers both GitHub check runs and legacy status contexts.
type PRCommit ¶
type PRCommit struct {
OID string `json:"oid"`
CommittedDate string `json:"committedDate,omitempty"`
MessageHeadline string `json:"messageHeadline,omitempty"`
CheckRollupState string `json:"checkRollupState,omitempty"`
}
PRCommit is one pull-request commit with its commit-specific CI rollup.
type PRConversationComment ¶
type PRConversationComment struct {
Author PRUser `json:"author"`
Body string `json:"body"`
CreatedAt string `json:"createdAt"`
URL string `json:"url,omitempty"`
}
PRConversationComment is compact list-preview conversation metadata.
type PRDetail ¶
type PRDetail struct {
PR PR
Comments []Comment
Activities []Activity
Reviews []Review
ReviewComments []ReviewThreadComment
PreviewErr error
CommentsErr error
ActivitiesErr error
ReviewsErr error
ReviewCommentsErr error
}
PRDetail is one concurrently loaded pull-request detail snapshot.
type PRPage ¶
type PRPage struct {
Repository string
ViewerLogin string
PRs []PR
TotalCount int
PageInfo PageInfo
}
PRPage is one explicitly requested page of lightweight pull-request rows.
type PRSnapshot ¶
type PRSnapshot struct {
PR PR `json:"pr"`
Comments []Comment `json:"comments,omitempty"`
Activities []Activity `json:"activities,omitempty"`
FetchedAt string `json:"fetched_at,omitempty"`
}
PRSnapshot is cached Conversation data for one browsed pull request.
type PRViewCache ¶
type PRViewCache struct {
Numbers []int `json:"numbers,omitempty"`
TotalCount int `json:"total_count,omitempty"`
FetchedAt string `json:"fetched_at,omitempty"`
}
PRViewCache preserves loaded row order and an exact server count without duplicating PR metadata already stored in NavigatorCache.PRs.
type PageInfo ¶
type PageInfo struct {
HasNextPage bool `json:"hasNextPage"`
StartCursor string `json:"startCursor"`
EndCursor string `json:"endCursor"`
}
PageInfo is one GitHub cursor boundary.
type Review ¶ added in v0.5.0
type Review struct {
ID int64 `json:"id"`
Body string `json:"body"`
State string `json:"state"`
SubmittedAt string `json:"submitted_at"`
User struct {
Login string `json:"login"`
AvatarURL string `json:"avatar_url,omitempty"`
} `json:"user"`
}
Review is a submitted pull-request review (approve / request-changes / comment) with its optional summary body.
type ReviewComment ¶ added in v0.2.0
type ReviewComment struct {
Path string `json:"path"`
Line int `json:"line"`
Side string `json:"side"`
Body string `json:"body"`
}
ReviewComment is one pending inline GitHub review comment.
type ReviewDraft ¶ added in v0.2.0
type ReviewDraft struct {
Version int `json:"version"`
PR int `json:"pr"`
Commit string `json:"commit_id"`
Body string `json:"body,omitempty"`
Comments []ReviewComment `json:"comments,omitempty"`
}
ReviewDraft is a local, unpublished GitHub pull-request review.
func LoadReviewDraft ¶ added in v0.2.0
func LoadReviewDraft(path string, pr int, commit string) (ReviewDraft, error)
func NewReviewDraft ¶ added in v0.2.0
func NewReviewDraft(pr int, commit string) ReviewDraft
type ReviewEvent ¶ added in v0.2.0
type ReviewEvent string
ReviewEvent is one GitHub review verdict.
const ( ReviewCommentEvent ReviewEvent = "COMMENT" ReviewApproveEvent ReviewEvent = "APPROVE" ReviewRequestChangesEvent ReviewEvent = "REQUEST_CHANGES" )
type ReviewThreadComment ¶ added in v0.5.0
type ReviewThreadComment struct {
ID int64 `json:"id"`
Body string `json:"body"`
Path string `json:"path"`
Line int `json:"line"`
CreatedAt string `json:"created_at"`
User struct {
Login string `json:"login"`
AvatarURL string `json:"avatar_url,omitempty"`
} `json:"user"`
}
ReviewThreadComment is one inline review comment on a diff line.