github

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssigneeNode added in v0.2.0

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

AssigneeNode represents an assignee in the GraphQL response.

type Client

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

Client provides methods to interact with GitHub's GraphQL API.

func NewClient

func NewClient() (*Client, error)

NewClient creates a new GitHub client using gh auth.

func (*Client) AddComment

func (c *Client) AddComment(subjectID, body string) error

AddComment adds a new comment to an issue or PR.

func (*Client) AddDiscussionComment

func (c *Client) AddDiscussionComment(discussionID, body string) error

AddDiscussionComment adds a new comment to a discussion.

func (*Client) AddDiscussionCommentReply

func (c *Client) AddDiscussionCommentReply(replyToID, body string) error

AddDiscussionCommentReply adds a reply to a discussion comment.

func (*Client) AddReviewThreadReply

func (c *Client) AddReviewThreadReply(threadID, body string) error

AddReviewThreadReply adds a reply to a PR review thread.

func (*Client) CloseIssue

func (c *Client) CloseIssue(id string) error

CloseIssue closes an issue.

func (*Client) ClosePullRequest

func (c *Client) ClosePullRequest(id string) error

ClosePullRequest closes a pull request.

func (*Client) FetchComments

func (c *Client) FetchComments(itemType ItemType, owner, repo string, number int) ([]RemoteComment, error)

FetchComments fetches current comments for an item.

func (*Client) FetchDiscussion

func (c *Client) FetchDiscussion(owner, repo string, number int) (*Discussion, error)

FetchDiscussion fetches a single discussion by number.

func (*Client) FetchDiscussions

func (c *Client) FetchDiscussions(owner, repo string, limit int, openOnly bool, since *time.Time, progress ProgressFunc) ([]Discussion, error)

FetchDiscussions fetches all discussions from a repository with pagination. If openOnly is true, only OPEN discussions are fetched; otherwise all states are fetched. If since is provided, fetching stops when encountering items older than the timestamp. If progress is non-nil, it's called after each page with the current count.

func (*Client) FetchIssue

func (c *Client) FetchIssue(owner, repo string, number int) (*Issue, error)

FetchIssue fetches a single issue by number.

func (*Client) FetchIssues

func (c *Client) FetchIssues(owner, repo string, limit int, openOnly bool, since *time.Time, progress ProgressFunc) ([]Issue, error)

FetchIssues fetches all issues from a repository with pagination. If openOnly is true, only OPEN issues are fetched; otherwise all states are fetched. If since is provided, fetching stops when encountering items older than the timestamp. If progress is non-nil, it's called after each page with the current count.

func (*Client) FetchPullRequest

func (c *Client) FetchPullRequest(owner, repo string, number int) (*PullRequest, error)

FetchPullRequest fetches a single PR by number.

func (*Client) FetchPullRequests

func (c *Client) FetchPullRequests(owner, repo string, limit int, openOnly bool, since *time.Time, progress ProgressFunc) ([]PullRequest, error)

FetchPullRequests fetches all PRs from a repository with pagination. If openOnly is true, only OPEN PRs are fetched; otherwise all states are fetched. If since is provided, fetching stops when encountering items older than the timestamp. If progress is non-nil, it's called after each page with the current count.

func (*Client) FetchRemoteState

func (c *Client) FetchRemoteState(itemType ItemType, owner, repo string, number int) (RemoteState, error)

FetchRemoteState fetches the updatedAt timestamp and state for an item.

func (*Client) Query

func (c *Client) Query(query string, variables map[string]interface{}, response interface{}) error

Query executes a GraphQL query.

func (*Client) ReopenIssue

func (c *Client) ReopenIssue(id string) error

ReopenIssue reopens an issue.

func (*Client) ReopenPullRequest

func (c *Client) ReopenPullRequest(id string) error

ReopenPullRequest reopens a pull request.

func (*Client) UpdateDiscussion

func (c *Client) UpdateDiscussion(id, title, body string) error

UpdateDiscussion updates a discussion's title and body.

func (*Client) UpdateDiscussionComment

func (c *Client) UpdateDiscussionComment(commentID, body string) error

UpdateDiscussionComment updates an existing discussion comment.

func (*Client) UpdateIssue

func (c *Client) UpdateIssue(id, title, body string) error

UpdateIssue updates an issue's title and body.

func (*Client) UpdateIssueComment

func (c *Client) UpdateIssueComment(commentID, body string) error

UpdateIssueComment updates an existing comment on an issue or PR.

func (*Client) UpdatePullRequest

func (c *Client) UpdatePullRequest(id, title, body string) error

UpdatePullRequest updates a PR's title and body.

type Comment

type Comment struct {
	ID        string    `json:"id"`
	Author    string    `json:"author"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

Comment represents a comment on an issue, PR, or discussion.

type Discussion

type Discussion struct {
	ID        string              `json:"id"`
	URL       string              `json:"url"`
	Number    int                 `json:"number"`
	Owner     string              `json:"owner"`
	Repo      string              `json:"repo"`
	Title     string              `json:"title"`
	Body      string              `json:"body"`
	State     string              `json:"state"`
	Category  string              `json:"category"`
	Author    string              `json:"author"`
	AnswerID  string              `json:"answerId,omitempty"`
	Locked    bool                `json:"locked"`
	CreatedAt time.Time           `json:"createdAt"`
	UpdatedAt time.Time           `json:"updatedAt"`
	Comments  []DiscussionComment `json:"comments"`
}

Discussion represents a GitHub discussion with all metadata.

func (*Discussion) GetNumber added in v0.2.0

func (d *Discussion) GetNumber() int

GetNumber returns the number for Discussion.

func (*Discussion) GetOwner added in v0.2.0

func (d *Discussion) GetOwner() string

GetOwner returns the owner for Discussion.

func (*Discussion) GetRepo added in v0.2.0

func (d *Discussion) GetRepo() string

GetRepo returns the repo for Discussion.

type DiscussionComment

type DiscussionComment struct {
	ID        string              `json:"id"`
	Author    string              `json:"author"`
	Body      string              `json:"body"`
	CreatedAt time.Time           `json:"createdAt"`
	UpdatedAt time.Time           `json:"updatedAt"`
	Replies   []DiscussionComment `json:"replies,omitempty"`
}

DiscussionComment represents a comment or reply in a discussion.

type DiscussionCommentNode

type DiscussionCommentNode struct {
	ID        string    `json:"id"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
	Author    struct {
		Login string `json:"login"`
	} `json:"author"`
	Replies struct {
		Nodes []struct {
			ID        string    `json:"id"`
			Body      string    `json:"body"`
			CreatedAt time.Time `json:"createdAt"`
			UpdatedAt time.Time `json:"updatedAt"`
			Author    struct {
				Login string `json:"login"`
			} `json:"author"`
		} `json:"nodes"`
	} `json:"replies"`
}

DiscussionCommentNode represents a comment in a discussion.

type DiscussionNode

type DiscussionNode struct {
	ID        string    `json:"id"`
	URL       string    `json:"url"`
	Number    int       `json:"number"`
	Title     string    `json:"title"`
	Body      string    `json:"body"`
	Closed    bool      `json:"closed"`
	Locked    bool      `json:"locked"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
	Category  struct {
		Name string `json:"name"`
	} `json:"category"`
	Author struct {
		Login string `json:"login"`
	} `json:"author"`
	Answer struct {
		ID string `json:"id"`
	} `json:"answer"`
	Comments struct {
		Nodes []DiscussionCommentNode `json:"nodes"`
	} `json:"comments"`
}

DiscussionNode represents a discussion in the GraphQL response.

type DiscussionsResponse

type DiscussionsResponse struct {
	Repository struct {
		Discussions struct {
			PageInfo struct {
				HasNextPage bool   `json:"hasNextPage"`
				EndCursor   string `json:"endCursor"`
			} `json:"pageInfo"`
			Nodes []DiscussionNode `json:"nodes"`
		} `json:"discussions"`
	} `json:"repository"`
}

DiscussionsResponse represents the GraphQL response for discussions.

type Issue

type Issue struct {
	ID               string            `json:"id"`
	URL              string            `json:"url"`
	Number           int               `json:"number"`
	Owner            string            `json:"owner"`
	Repo             string            `json:"repo"`
	Title            string            `json:"title"`
	Body             string            `json:"body"`
	State            string            `json:"state"`
	Author           string            `json:"author"`
	Labels           []string          `json:"labels"`
	Assignees        []string          `json:"assignees"`
	CreatedAt        time.Time         `json:"createdAt"`
	UpdatedAt        time.Time         `json:"updatedAt"`
	Comments         []Comment         `json:"comments"`
	Parent           *IssueReference   `json:"parent,omitempty"`
	Children         []IssueReference  `json:"children,omitempty"`
	SubIssuesSummary *SubIssuesSummary `json:"subIssuesSummary,omitempty"`
}

Issue represents a GitHub issue with all metadata.

func (*Issue) GetNumber added in v0.2.0

func (i *Issue) GetNumber() int

GetNumber returns the number for Issue.

func (*Issue) GetOwner added in v0.2.0

func (i *Issue) GetOwner() string

GetOwner returns the owner for Issue.

func (*Issue) GetRepo added in v0.2.0

func (i *Issue) GetRepo() string

GetRepo returns the repo for Issue.

type IssueNode

type IssueNode struct {
	ID     string `json:"id"`
	URL    string `json:"url"`
	Number int    `json:"number"`
	Title  string `json:"title"`
	Body   string `json:"body"`
	State  string `json:"state"`
	Author struct {
		Login string `json:"login"`
	} `json:"author"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
	Labels    struct {
		Nodes []LabelNode `json:"nodes"`
	} `json:"labels"`
	Assignees struct {
		Nodes []AssigneeNode `json:"nodes"`
	} `json:"assignees"`
	Comments struct {
		Nodes []struct {
			ID        string    `json:"id"`
			Body      string    `json:"body"`
			CreatedAt time.Time `json:"createdAt"`
			UpdatedAt time.Time `json:"updatedAt"`
			Author    struct {
				Login string `json:"login"`
			} `json:"author"`
		} `json:"nodes"`
	} `json:"comments"`
	Parent    *ParentIssueNode `json:"parent"`
	SubIssues struct {
		Nodes []SubIssueNode `json:"nodes"`
	} `json:"subIssues"`
	SubIssuesSummary *SubIssuesSummaryNode `json:"subIssuesSummary"`
}

IssueNode represents an issue in the GraphQL response.

type IssueReference

type IssueReference struct {
	ID     string `json:"id"`
	Number int    `json:"number"`
	Title  string `json:"title"`
	URL    string `json:"url"`
	State  string `json:"state"`
	Owner  string `json:"owner"`
	Repo   string `json:"repo"`
}

IssueReference represents a reference to a parent or child issue.

type IssuesResponse

type IssuesResponse struct {
	Repository struct {
		Issues struct {
			PageInfo struct {
				HasNextPage bool   `json:"hasNextPage"`
				EndCursor   string `json:"endCursor"`
			} `json:"pageInfo"`
			Nodes []IssueNode `json:"nodes"`
		} `json:"issues"`
	} `json:"repository"`
}

IssuesResponse represents the GraphQL response for issues.

type ItemType

type ItemType string

ItemType represents the type of GitHub item.

const (
	ItemTypeIssue       ItemType = "issue"
	ItemTypePullRequest ItemType = "pull"
	ItemTypeDiscussion  ItemType = "discussion"
)

func ItemTypeFromDirName added in v0.2.0

func ItemTypeFromDirName(dir string) (ItemType, bool)

ItemTypeFromDirName converts a local directory name or URL path segment into an ItemType. Accepted values: "issue", "issues", "pull", "pulls", "discussion", "discussions".

func (ItemType) DirName added in v0.2.0

func (t ItemType) DirName() (string, bool)

DirName returns the local storage directory name for an item type.

func (ItemType) Display added in v0.2.0

func (t ItemType) Display() string

Display returns the human-readable singular form.

func (ItemType) DisplayPlural added in v0.2.0

func (t ItemType) DisplayPlural() string

DisplayPlural returns the human-readable plural form.

func (ItemType) ListLabel added in v0.2.0

func (t ItemType) ListLabel() (string, bool)

ListLabel returns a short label used for displaying an item type in lists.

func (ItemType) URLSegment added in v0.2.0

func (t ItemType) URLSegment() (string, bool)

URLSegment returns the GitHub web URL path segment for an item type.

type LabelNode added in v0.2.0

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

LabelNode represents a label in the GraphQL response.

type ParentIssueNode

type ParentIssueNode struct {
	ID         string `json:"id"`
	Number     int    `json:"number"`
	Title      string `json:"title"`
	URL        string `json:"url"`
	State      string `json:"state"`
	Repository struct {
		Owner struct {
			Login string `json:"login"`
		} `json:"owner"`
		Name string `json:"name"`
	} `json:"repository"`
}

ParentIssueNode represents a parent issue in the GraphQL response.

type ParsedInput

type ParsedInput struct {
	Owner    string
	Repo     string
	Number   int      // 0 if fetching all
	ItemType ItemType // wEmpty if fetching all types
}

ParsedInput represents parsed command input (URL or owner/repo).

func ParseInput

func ParseInput(input string) (*ParsedInput, error)

ParseInput parses the input argument which can be a URL or owner/repo format.

func (*ParsedInput) FullName added in v0.4.0

func (pi *ParsedInput) FullName() string

type ProgressFunc added in v0.2.0

type ProgressFunc func(fetched int)

ProgressFunc is called during paginated fetches with the current count of fetched items.

type PullRequest

type PullRequest struct {
	ID            string         `json:"id"`
	URL           string         `json:"url"`
	Number        int            `json:"number"`
	Owner         string         `json:"owner"`
	Repo          string         `json:"repo"`
	Title         string         `json:"title"`
	Body          string         `json:"body"`
	State         string         `json:"state"`
	Author        string         `json:"author"`
	Draft         bool           `json:"draft"`
	Labels        []string       `json:"labels"`
	Assignees     []string       `json:"assignees"`
	Reviewers     []string       `json:"reviewers"`
	HeadRef       string         `json:"headRef"`
	BaseRef       string         `json:"baseRef"`
	MergeCommit   string         `json:"mergeCommit,omitempty"`
	CreatedAt     time.Time      `json:"createdAt"`
	UpdatedAt     time.Time      `json:"updatedAt"`
	MergedAt      time.Time      `json:"mergedAt,omitempty"`
	Comments      []Comment      `json:"comments"`
	ReviewThreads []ReviewThread `json:"reviewThreads"`
}

PullRequest represents a GitHub pull request with all metadata.

func (*PullRequest) GetNumber added in v0.2.0

func (p *PullRequest) GetNumber() int

GetNumber returns the number for PullRequest.

func (*PullRequest) GetOwner added in v0.2.0

func (p *PullRequest) GetOwner() string

GetOwner returns the owner for PullRequest.

func (*PullRequest) GetRepo added in v0.2.0

func (p *PullRequest) GetRepo() string

GetRepo returns the repo for PullRequest.

type PullRequestNode

type PullRequestNode struct {
	ID     string `json:"id"`
	URL    string `json:"url"`
	Number int    `json:"number"`
	Title  string `json:"title"`
	Body   string `json:"body"`
	State  string `json:"state"`
	Author struct {
		Login string `json:"login"`
	} `json:"author"`
	IsDraft     bool      `json:"isDraft"`
	CreatedAt   time.Time `json:"createdAt"`
	UpdatedAt   time.Time `json:"updatedAt"`
	MergedAt    time.Time `json:"mergedAt"`
	HeadRefName string    `json:"headRefName"`
	BaseRefName string    `json:"baseRefName"`
	MergeCommit struct {
		Oid string `json:"oid"`
	} `json:"mergeCommit"`
	Labels struct {
		Nodes []LabelNode `json:"nodes"`
	} `json:"labels"`
	Assignees struct {
		Nodes []AssigneeNode `json:"nodes"`
	} `json:"assignees"`
	ReviewRequests struct {
		Nodes []struct {
			RequestedReviewer struct {
				Login string `json:"login"` // User
				Name  string `json:"name"`  // Team
			} `json:"requestedReviewer"`
		} `json:"nodes"`
	} `json:"reviewRequests"`
	Comments struct {
		Nodes []struct {
			ID        string    `json:"id"`
			Body      string    `json:"body"`
			CreatedAt time.Time `json:"createdAt"`
			UpdatedAt time.Time `json:"updatedAt"`
			Author    struct {
				Login string `json:"login"`
			} `json:"author"`
		} `json:"nodes"`
	} `json:"comments"`
	ReviewThreads struct {
		Nodes []struct {
			ID         string `json:"id"`
			Path       string `json:"path"`
			Line       int    `json:"line"`
			IsResolved bool   `json:"isResolved"`
			IsOutdated bool   `json:"isOutdated"`
			Comments   struct {
				Nodes []struct {
					ID        string    `json:"id"`
					Body      string    `json:"body"`
					CreatedAt time.Time `json:"createdAt"`
					UpdatedAt time.Time `json:"updatedAt"`
					Author    struct {
						Login string `json:"login"`
					} `json:"author"`
				} `json:"nodes"`
			} `json:"comments"`
		} `json:"nodes"`
	} `json:"reviewThreads"`
}

PullRequestNode represents a PR in the GraphQL response.

type PullRequestsResponse

type PullRequestsResponse struct {
	Repository struct {
		PullRequests struct {
			PageInfo struct {
				HasNextPage bool   `json:"hasNextPage"`
				EndCursor   string `json:"endCursor"`
			} `json:"pageInfo"`
			Nodes []PullRequestNode `json:"nodes"`
		} `json:"pullRequests"`
	} `json:"repository"`
}

PullRequestsResponse represents the GraphQL response for pull requests.

type RemoteComment

type RemoteComment struct {
	ID   string
	Body string
}

RemoteComment represents a comment fetched from GitHub for comparison.

type RemoteState

type RemoteState struct {
	UpdatedAt time.Time
	State     string // "OPEN", "CLOSED", "MERGED" (PRs only)
}

RemoteState holds the remote item's current state info.

type ReviewComment

type ReviewComment struct {
	ID        string    `json:"id"`
	Author    string    `json:"author"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

ReviewComment represents an inline review comment on a PR.

type ReviewThread

type ReviewThread struct {
	ID         string          `json:"id"`
	Path       string          `json:"path"`
	Line       int             `json:"line"`
	IsResolved bool            `json:"isResolved"`
	IsOutdated bool            `json:"isOutdated"`
	Comments   []ReviewComment `json:"comments"`
}

ReviewThread represents a review thread on a PR (a conversation on a specific line).

type SingleDiscussionResponse

type SingleDiscussionResponse struct {
	Repository struct {
		Discussion DiscussionNode `json:"discussion"`
	} `json:"repository"`
}

SingleDiscussionResponse represents the GraphQL response for a single discussion.

type SingleIssueResponse

type SingleIssueResponse struct {
	Repository struct {
		Issue IssueNode `json:"issue"`
	} `json:"repository"`
}

SingleIssueResponse represents the GraphQL response for a single issue.

type SinglePullRequestResponse

type SinglePullRequestResponse struct {
	Repository struct {
		PullRequest PullRequestNode `json:"pullRequest"`
	} `json:"repository"`
}

SinglePullRequestResponse represents the GraphQL response for a single PR.

type SubIssueNode

type SubIssueNode struct {
	ID         string `json:"id"`
	Number     int    `json:"number"`
	Title      string `json:"title"`
	URL        string `json:"url"`
	State      string `json:"state"`
	Repository struct {
		Owner struct {
			Login string `json:"login"`
		} `json:"owner"`
		Name string `json:"name"`
	} `json:"repository"`
}

SubIssueNode represents a sub-issue in the GraphQL response.

type SubIssuesSummary

type SubIssuesSummary struct {
	Total           int `json:"total"`
	Completed       int `json:"completed"`
	PercentComplete int `json:"percentComplete"`
}

SubIssuesSummary provides statistics about sub-issues.

type SubIssuesSummaryNode

type SubIssuesSummaryNode struct {
	Total            int `json:"total"`
	Completed        int `json:"completed"`
	PercentCompleted int `json:"percentCompleted"`
}

SubIssuesSummaryNode represents the sub-issues summary in the GraphQL response.

Jump to

Keyboard shortcuts

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