Documentation
¶
Overview ¶
Package github provides a GitHub App-authenticated client and a set of gollem agent tools (search, get_issue, get_pull_request, get_file, list_commits) that the AI agent can call against GitHub.
Both the Source pipeline (legacy fetch methods) and the agent tools are served by the same *Client. There is no Service interface — there is only one implementation, and tool-side fakes are wired through a package-private interface in tools.go.
Index ¶
- Variables
- func New(client *Client) []gollem.Tool
- type Client
- func (c *Client) FetchRecentIssues(ctx context.Context, owner, repo string, since time.Time) iter.Seq2[*Issue, error]
- func (c *Client) FetchRecentPullRequests(ctx context.Context, owner, repo string, since time.Time) iter.Seq2[*PullRequest, error]
- func (c *Client) FetchUpdatedIssueComments(ctx context.Context, owner, repo string, since time.Time, ...) iter.Seq2[*IssueWithComments, error]
- func (c *Client) GetFileContent(ctx context.Context, owner, repo, path, ref string) (*FileContent, error)
- func (c *Client) GetIssue(ctx context.Context, owner, repo string, number int) (*Issue, error)
- func (c *Client) GetPullRequestDetail(ctx context.Context, owner, repo string, number int, includeFiles bool) (*PullRequestDetail, error)
- func (c *Client) ListCommits(ctx context.Context, opts ListCommitsOptions) (*CommitList, error)
- func (c *Client) SearchIssuesAndPRs(ctx context.Context, opts SearchOptions) (*SearchResult, error)
- func (c *Client) ValidateRepository(ctx context.Context, owner, repo string) (*RepositoryValidation, error)
- type Comment
- type Commit
- type CommitList
- type FileChange
- type FileContent
- type Issue
- type IssueWithComments
- type ListCommitsOptions
- type PullRequest
- type PullRequestDetail
- type RepositoryValidation
- type Review
- type SearchHit
- type SearchOptions
- type SearchResult
Constants ¶
This section is empty.
Variables ¶
var ErrIssueIsPR = errIssueIsPR
ErrIssueIsPR is the public alias for errIssueIsPR so callers (including the agent tool) can detect this case via errors.Is.
var ErrNotFound = goerr.New("github resource not found")
ErrNotFound is returned when a requested GitHub resource (issue, PR, file, commit) does not exist within a repository this GitHub App installation can read. Callers can use errors.Is to detect this without parsing error messages.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the GitHub App-authenticated GraphQL v4 + REST clients. There is exactly one production implementation; tests inject a fake via the package-private interface in tools.go. Both clients are built eagerly in NewClient and never reassigned: a single *Client is shared across concurrent agent runs (CommonDeps.GitHubClient), so lazily populating restClient on first use would be a data race.
func NewClient ¶
NewClient creates a Client using GitHub App credentials. privateKey can be a PEM string or a file path to a PEM file.
Named NewClient (not New) so the package-level New is reserved for the agent-tool factory in tools.go.
func (*Client) FetchRecentIssues ¶
func (c *Client) FetchRecentIssues(ctx context.Context, owner, repo string, since time.Time) iter.Seq2[*Issue, error]
FetchRecentIssues fetches issues (excluding PRs) created since the given time, with all comments.
func (*Client) FetchRecentPullRequests ¶
func (c *Client) FetchRecentPullRequests(ctx context.Context, owner, repo string, since time.Time) iter.Seq2[*PullRequest, error]
FetchRecentPullRequests fetches PRs created since the given time using the GitHub GraphQL search.
func (*Client) FetchUpdatedIssueComments ¶
func (c *Client) FetchUpdatedIssueComments(ctx context.Context, owner, repo string, since time.Time, excludeNumbers map[int]struct{}) iter.Seq2[*IssueWithComments, error]
FetchUpdatedIssueComments fetches issues/PRs that received new comments in the time range, excluding any numbers given in excludeNumbers.
func (*Client) GetFileContent ¶
func (*Client) GetPullRequestDetail ¶
func (*Client) ListCommits ¶
func (c *Client) ListCommits(ctx context.Context, opts ListCommitsOptions) (*CommitList, error)
func (*Client) SearchIssuesAndPRs ¶
func (c *Client) SearchIssuesAndPRs(ctx context.Context, opts SearchOptions) (*SearchResult, error)
func (*Client) ValidateRepository ¶
func (c *Client) ValidateRepository(ctx context.Context, owner, repo string) (*RepositoryValidation, error)
ValidateRepository checks repository accessibility and returns metadata.
type Commit ¶
type Commit struct {
SHA string
AuthorLogin string
AuthorName string
AuthorEmail string
AuthoredDate time.Time
CommitterDate time.Time
Message string
URL string
}
Commit represents a single commit in a list response.
type CommitList ¶
type CommitList struct {
Items []Commit
}
CommitList is the response of ListCommits.
type FileChange ¶
type FileChange struct {
Path string
Status string // "added" | "modified" | "removed" | "renamed"
Additions int
Deletions int
Patch string
PatchTruncated bool // true when Patch was truncated to fit the size cap
}
FileChange represents a single file's change set in a PR.
type FileContent ¶
type FileContent struct {
Path string
Ref string // resolved commit SHA
Size int64
Content string // empty when IsBinary is true
Truncated bool // true when the content was truncated to fit the size cap
IsBinary bool
}
FileContent is the response of GetFileContent.
type Issue ¶
type Issue struct {
Number int
Title string
Body string
Author string
State string
URL string
Labels []string
CreatedAt time.Time
UpdatedAt time.Time
ClosedAt *time.Time // nil when the issue is still open
Comments []Comment
}
Issue represents a GitHub issue with all comments.
type IssueWithComments ¶
type IssueWithComments struct {
Number int
Title string
Body string
Author string
State string
URL string
IsPR bool
CreatedAt time.Time
Comments []Comment
// Since marks the boundary; comments at or after this timestamp are NEW.
Since time.Time
}
IssueWithComments represents an issue or PR that received new comments since a given point in time, with the full comment history attached.
type ListCommitsOptions ¶
type ListCommitsOptions struct {
Owner string
Repo string
Ref string // branch / tag / SHA; empty means default branch
Path string // limit to commits touching this path; empty for any
Author string // GitHub login or email; empty for any
Since time.Time // zero value means no lower bound
Until time.Time // zero value means no upper bound
PerPage int // 1..50; 0 defaults to 20
}
ListCommitsOptions configures a ListCommits call.
type PullRequest ¶
type PullRequest struct {
Number int
Title string
Body string
Author string
State string
URL string
Labels []string
CreatedAt time.Time
Comments []Comment
Reviews []Review
}
PullRequest represents a GitHub pull request with all comments and reviews.
type PullRequestDetail ¶
type PullRequestDetail struct {
PullRequest
Merged bool
Draft bool
BaseRef string
HeadRef string
UpdatedAt time.Time
ClosedAt *time.Time // nil when the PR is still open
// Files is non-nil only when GetPullRequestDetail was called with
// includeFiles=true.
Files []FileChange
}
PullRequestDetail is a PR with extra metadata and optionally the file diff. Embeds PullRequest so all base fields (comments, reviews, labels) are accessible directly on the detail value.
type RepositoryValidation ¶
type RepositoryValidation struct {
Valid bool
Owner string
Repo string
FullName string
Description string
IsPrivate bool
PullRequestCount int
IssueCount int
CanFetchPullRequests bool
CanFetchIssues bool
ErrorMessage string
}
RepositoryValidation holds the result of repository validation.
type SearchHit ¶
type SearchHit struct {
Number int
Title string
URL string
Author string
State string
CreatedAt time.Time
Labels []string
IsPR bool
RepoOwner string
RepoName string
}
SearchHit is a single matched issue or PR in the search response.
type SearchOptions ¶
type SearchOptions struct {
// Query is the GitHub search query. Supports all GitHub search operators
// (repo:, is:open, author:, label:, etc).
Query string
// Type narrows results: "issue", "pr", or "" / "both" for no narrowing.
// When set, the corresponding "is:issue" / "is:pr" qualifier is appended
// to Query if not already present.
Type string
// PerPage is the page size, clamped to [1, 50]. Zero defaults to 20.
PerPage int
}
SearchOptions configures a SearchIssuesAndPRs call.
type SearchResult ¶
SearchResult is the response of a SearchIssuesAndPRs call.