Help us shape the future of Go! Take the 2026 Go Developer Survey

github

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package github provides a client for fetching issue and PR status from GitHub.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseNumbers

func ParseNumbers(input string) ([]int, error)

ParseNumbers splits a space-separated string of issue numbers into ints. Each token may optionally have a '#' prefix. Returns error on invalid input.

Types

type BranchPRStatus

type BranchPRStatus struct {
	Number      int
	Title       string
	State       string // "open", "closed", "merged"
	Draft       bool
	ReviewState string // "approved", "changes_requested", "pending", or ""
}

BranchPRStatus holds the PR info found for a worktree branch.

type Client

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

Client wraps the GitHub API client.

func NewClient

func NewClient(token string) *Client

NewClient creates a GitHub client authenticated with the given PAT. Uses a 30-second HTTP timeout to prevent indefinite hangs on network issues. Wraps the transport with ETag caching so conditional requests (304 Not Modified) don't count against the GitHub API rate limit.

func NewClientWithBaseURL

func NewClientWithBaseURL(token, baseURL string) *Client

NewClientWithBaseURL creates a GitHub client pointing at a custom API base URL. Used for testing with httptest servers.

func (*Client) AddLabel

func (c *Client) AddLabel(ctx context.Context, owner, repo string, number int, label string) error

AddLabel adds a label to an issue/PR. Creates the label if it doesn't exist.

func (*Client) CreateComment

func (c *Client) CreateComment(ctx context.Context, owner, repo string, number int, body string) (int64, error)

CreateComment posts a comment on an issue or PR and returns the comment ID.

func (*Client) EnableAutoMerge

func (c *Client) EnableAutoMerge(ctx context.Context, owner, repo string, number int, method string) error

EnableAutoMerge enables GitHub's auto-merge on a PR so it merges when CI passes. Falls back to immediate merge if auto-merge is not available (e.g., not enabled on repo).

func (*Client) FetchItem

func (c *Client) FetchItem(ctx context.Context, owner, repo string, number int) (*ItemStatus, error)

FetchItem fetches the current status of an issue or PR. It first tries as a PR (to detect merged state), then falls back to issue.

func (*Client) FetchItemContent

func (c *Client) FetchItemContent(ctx context.Context, owner, repo string, number int, itemType string) (*ItemContent, error)

FetchItemContent fetches the body and last 10 comments for an issue or PR. Uses the Issues API which works for both issues and PRs.

func (*Client) FetchItemWithHint

func (c *Client) FetchItemWithHint(ctx context.Context, owner, repo string, number int, itemType string) (*ItemStatus, error)

FetchItemWithHint fetches status, using itemType hint to skip unnecessary API calls. If hint is "issue", skips the PR attempt. If hint is "pull_request", only tries PR. If hint is empty, tries PR first then falls back to issue.

func (*Client) FetchPRForBranch

func (c *Client) FetchPRForBranch(ctx context.Context, owner, repo, branch string) (*BranchPRStatus, error)

FetchPRForBranch looks up an open PR whose head branch matches the given branch name. Returns nil (no error) if no PR exists for that branch.

func (*Client) FetchPRReviewState

func (c *Client) FetchPRReviewState(ctx context.Context, owner, repo string, number int) string

FetchPRReviewState returns the aggregate review state for a pull request. It examines the most recent review from each reviewer and returns: "approved" if at least one approval and no outstanding changes_requested, "changes_requested" if any reviewer has requested changes, "pending" if there are no decisive reviews yet, or "" on error.

func (*Client) FindMilestoneNumber

func (c *Client) FindMilestoneNumber(ctx context.Context, owner, repo, name string) (int, error)

FindMilestoneNumber looks up a milestone by name and returns its number.

func (*Client) IsPRMerged

func (c *Client) IsPRMerged(ctx context.Context, owner, repo string, number int) (bool, error)

IsPRMerged returns whether a PR has been merged.

func (*Client) ListAssignees

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

ListAssignees returns available assignees for a repo.

func (*Client) ListIssuesByLabel

func (c *Client) ListIssuesByLabel(ctx context.Context, owner, repo, label string) (*SearchResult, error)

ListIssuesByLabel returns open issues for a specific label. Uses the Issues list API instead of the Search API to avoid permission issues with tokens that lack search scope.

func (*Client) ListIssuesByLabels

func (c *Client) ListIssuesByLabels(ctx context.Context, owner, repo string, labels []string) (*SearchResult, error)

ListIssuesByLabels returns open issues that have ALL the given labels (AND logic). GitHub's Issues list API natively applies AND when multiple labels are specified.

func (*Client) ListIssuesByMilestone

func (c *Client) ListIssuesByMilestone(ctx context.Context, owner, repo string, milestoneNumber int) (*SearchResult, error)

ListIssuesByMilestone returns open issues for a specific milestone number. Uses the Issues list API instead of the Search API to avoid query syntax issues with special characters in milestone titles.

func (*Client) ListLabels

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

ListLabels returns all labels for a repo.

func (*Client) ListMilestones

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

ListMilestones returns open milestones for a repo.

func (*Client) ListPRsForBranch

func (c *Client) ListPRsForBranch(ctx context.Context, owner, repo, branch string) ([]int, error)

ListPRsForBranch returns PR numbers for open PRs from the given branch.

func (*Client) MergePR

func (c *Client) MergePR(ctx context.Context, owner, repo string, number int, method string, commitMsg string) error

MergePR merges a pull request using the specified method (merge, squash, rebase). Returns nil on success, or an error describing why the merge failed.

func (*Client) RemoveLabel

func (c *Client) RemoveLabel(ctx context.Context, owner, repo string, number int, label string)

RemoveLabel removes a label from an issue/PR. Ignores errors if label isn't present.

func (*Client) SearchIssues

func (c *Client) SearchIssues(ctx context.Context, owner, repo string, filterType FilterType, filterValue string) (*SearchResult, error)

SearchIssues searches for open issues in a repo matching the given filter. Requests up to 21 results to detect overflow beyond the 20-item cap.

type FilterType

type FilterType string

FilterType represents the type of filter for searching issues.

const (
	FilterLabel     FilterType = "label"
	FilterMilestone FilterType = "milestone"
	FilterProject   FilterType = "project"
	FilterAssignee  FilterType = "assignee"
)

type ItemContent

type ItemContent struct {
	Body     string
	Comments []string
}

ItemContent holds the body and recent comments for a GitHub issue or PR.

type ItemRef

type ItemRef struct {
	Owner  string
	Repo   string
	Number int
}

ItemRef holds the parsed components of a GitHub item reference.

func ParseItemRef

func ParseItemRef(input, defaultOwner, defaultRepo string) (*ItemRef, error)

ParseItemRef parses a GitHub item reference string. Supported formats:

  • "#42" (requires defaultOwner and defaultRepo)
  • "owner/repo#42"

Returns an error if the format is invalid or if owner/repo are needed but not provided.

type ItemStatus

type ItemStatus struct {
	Number      int
	Title       string
	Body        string // issue/PR body text
	State       string // "open", "closed", "merged"
	Labels      []string
	ItemType    string // "issue" or "pull_request"
	Draft       bool   // PR only: true if draft PR
	ReviewState string // PR only: "approved", "changes_requested", "pending", or ""
}

ItemStatus holds the fetched status of a GitHub issue or PR.

func (*ItemStatus) CompactStatus

func (s *ItemStatus) CompactStatus() string

CompactStatus returns a short TUI-friendly status tag.

type RepoChoice

type RepoChoice struct {
	Value       string // The value to use in the filter (label name, milestone title, username)
	Description string // Optional extra info (e.g., milestone due date)
	ID          int    // Numeric ID (e.g., milestone number) for API calls that need it
}

RepoChoice represents a selectable option fetched from a GitHub repo.

type SearchResult

type SearchResult struct {
	Items      []ItemStatus
	TotalCount int
}

SearchResult holds the results of a GitHub issue search.

Jump to

Keyboard shortcuts

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