github

package
v0.3.18 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchAllPages added in v0.2.27

func FetchAllPages[T any, R any](
	ctx context.Context,
	c *Client,
	cacheKey string,
	config FetchConfig,
	fetcher PageFetcher[T, R],
) ([]R, error)

FetchAllPages fetches all pages of a resource with caching, filtering, and early termination

Types

type Client

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

Client wraps the GitHub API client with rate limiting and caching

func NewClient

func NewClient(ctx context.Context, cfg *config.Config) (*Client, error)

NewClient creates a new GitHub client with the appropriate authentication

func (*Client) FetchIssueComments added in v0.2.24

func (c *Client) FetchIssueComments(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.IssueComment, error)

FetchIssueComments fetches comments on issues from a repository Uses early termination when sorted by date - stops when items are outside date range

func (*Client) FetchIssues

func (c *Client) FetchIssues(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.Issue, error)

FetchIssues fetches issues from a repository Uses early termination when sorted by date - stops when items are outside date range

func (*Client) FetchIssuesWithCommentsGraphQL added in v0.2.27

func (c *Client) FetchIssuesWithCommentsGraphQL(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.Issue, []models.IssueComment, error)

FetchIssuesWithCommentsGraphQL fetches issues and comments using GraphQL (much fewer API calls)

func (*Client) FetchPRsWithReviewsGraphQL added in v0.2.27

func (c *Client) FetchPRsWithReviewsGraphQL(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.PullRequest, []models.Review, error)

FetchPRsWithReviewsGraphQL fetches PRs and reviews using GraphQL (much fewer API calls)

func (*Client) FetchPullRequests

func (c *Client) FetchPullRequests(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.PullRequest, error)

FetchPullRequests fetches pull requests from a repository Fetches PRs targeting main branches, filters by merge date

func (*Client) FetchReviews

func (c *Client) FetchReviews(ctx context.Context, owner, repo string, prNumber int) ([]models.Review, error)

FetchReviews fetches reviews for a specific pull request

func (*Client) FetchUserProfiles

func (c *Client) FetchUserProfiles(ctx context.Context, logins []string) (map[string]UserProfile, error)

FetchUserProfiles fetches GitHub profiles for a list of logins This is useful for deduplication by getting user IDs, names, and public emails

func (*Client) GetCommitCountSince added in v0.2.27

func (c *Client) GetCommitCountSince(ctx context.Context, owner, repo string, since time.Time) (int, error)

GetCommitCountSince returns the approximate number of commits since a given date. This is used to determine the optimal shallow clone depth. It makes a single lightweight API call with per_page=1 to get pagination info.

func (*Client) HasGraphQL added in v0.2.27

func (c *Client) HasGraphQL() bool

HasGraphQL returns true if the GraphQL client is available

func (*Client) ListOrgRepos

func (c *Client) ListOrgRepos(ctx context.Context, org, pattern string) ([]string, error)

ListOrgRepos lists repositories in an organization matching a pattern

func (*Client) SetProgressCallback

func (c *Client) SetProgressCallback(cb ProgressCallback)

SetProgressCallback sets the callback function for progress reporting

type DateFilterResult added in v0.2.27

type DateFilterResult int

DateFilterResult represents the result of date filtering

const (
	// DateInclude means the item is within the date range
	DateInclude DateFilterResult = iota
	// DateTooNew means the item is newer than the 'until' date
	DateTooNew
	// DateTooOld means the item is older than the 'since' date
	DateTooOld
)

func FilterByDate added in v0.2.27

func FilterByDate(t time.Time, since, until *time.Time) DateFilterResult

FilterByDate checks if a time falls within the specified date range

type DateFilteredFetcher added in v0.2.27

type DateFilteredFetcher[T any, R any] struct {
	FetchFn   func(ctx context.Context, page int) ([]T, *github.Response, error)
	ConvertFn func(item T) R
	GetDateFn func(item T) time.Time
	SkipFn    func(item T) bool
	Since     *time.Time
	Until     *time.Time
}

DateFilteredFetcher extends SimpleFetcher with date filtering

func (*DateFilteredFetcher[T, R]) Convert added in v0.2.27

func (f *DateFilteredFetcher[T, R]) Convert(item T) R

func (*DateFilteredFetcher[T, R]) Fetch added in v0.2.27

func (f *DateFilteredFetcher[T, R]) Fetch(ctx context.Context, page int) ([]T, *github.Response, error)

func (*DateFilteredFetcher[T, R]) Filter added in v0.2.27

func (f *DateFilteredFetcher[T, R]) Filter(item T) DateFilterResult

func (*DateFilteredFetcher[T, R]) ShouldSkip added in v0.2.27

func (f *DateFilteredFetcher[T, R]) ShouldSkip(item T) bool

type FetchConfig added in v0.2.27

type FetchConfig struct {
	// ResourceName is used for progress messages (e.g., "issues", "pull requests")
	ResourceName string
	// EarlyTermination enables stopping when all items on a page are too old
	EarlyTermination bool
	// EarlyTerminationThreshold is the number of consecutive old pages before stopping
	EarlyTerminationThreshold int
	// Quiet suppresses per-page progress messages (useful for sub-fetches like reviews)
	Quiet bool
}

FetchConfig holds configuration for paginated fetching

func DefaultFetchConfig added in v0.2.27

func DefaultFetchConfig(resourceName string) FetchConfig

DefaultFetchConfig returns sensible defaults

type GQLFetchConfig added in v0.2.27

type GQLFetchConfig[Q any, T any, R any] struct {
	Label         string
	Query         *Q
	GetPageResult func(q *Q) PageResult[T]
	// ProcessNode returns items, whether this node is "old" (outside date range),
	// and whether to hard stop immediately (past cutoff date)
	ProcessNode func(node T, repo string) (items []R, isOld bool, hardStop bool)
	// ConsecutiveOldPagesToStop controls early termination (default: 2)
	ConsecutiveOldPagesToStop int
}

GQLFetchConfig configures the generic paginated fetcher for GraphQL

type GraphQLClient added in v0.2.27

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

GraphQLClient wraps the githubv4 client for GitHub API

func NewGraphQLClient added in v0.2.27

func NewGraphQLClient(token string) *GraphQLClient

NewGraphQLClient creates a new GraphQL client for GitHub

func (*GraphQLClient) FetchIssuesWithComments added in v0.2.27

func (g *GraphQLClient) FetchIssuesWithComments(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.Issue, []models.IssueComment, error)

FetchIssuesWithComments fetches issues with their comments using GraphQL

func (*GraphQLClient) FetchPRsWithReviews added in v0.2.27

func (g *GraphQLClient) FetchPRsWithReviews(ctx context.Context, owner, repo string, since, until *time.Time) ([]models.PullRequest, []models.Review, error)

FetchPRsWithReviews fetches pull requests with their reviews using GraphQL

type PageFetcher added in v0.2.27

type PageFetcher[T any, R any] interface {
	// Fetch retrieves a page of items
	Fetch(ctx context.Context, page int) (items []T, resp *github.Response, err error)
	// Convert transforms a raw item into the result type
	Convert(item T) R
	// Filter determines if an item should be included based on date range
	// Returns DateInclude to include, DateTooNew/DateTooOld to exclude
	Filter(item T) DateFilterResult
	// ShouldSkip returns true if the item should be skipped entirely (e.g., PRs in issues list)
	ShouldSkip(item T) bool
}

PageFetcher is a generic interface for fetching paginated resources

type PageInfo added in v0.2.27

type PageInfo struct {
	HasNextPage bool
	EndCursor   githubv4.String
}

PageInfo contains pagination info from GraphQL responses

type PageResult added in v0.2.27

type PageResult[T any] struct {
	TotalCount int
	PageInfo   PageInfo
	Nodes      []T
}

PageResult represents a page of results from GraphQL

type ProgressCallback

type ProgressCallback func(message string)

ProgressCallback is called to report progress during API operations

type RetryConfig

type RetryConfig struct {
	MaxRetries     int
	InitialBackoff time.Duration
	MaxBackoff     time.Duration
}

RetryConfig holds retry settings

func DefaultRetryConfig

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns the default retry configuration

type SimpleFetcher added in v0.2.27

type SimpleFetcher[T any, R any] struct {
	FetchFn   func(ctx context.Context, page int) ([]T, *github.Response, error)
	ConvertFn func(item T) R
}

SimpleFetcher is a helper for creating simple fetchers without date filtering

func (*SimpleFetcher[T, R]) Convert added in v0.2.27

func (f *SimpleFetcher[T, R]) Convert(item T) R

func (*SimpleFetcher[T, R]) Fetch added in v0.2.27

func (f *SimpleFetcher[T, R]) Fetch(ctx context.Context, page int) ([]T, *github.Response, error)

func (*SimpleFetcher[T, R]) Filter added in v0.2.27

func (f *SimpleFetcher[T, R]) Filter(item T) DateFilterResult

func (*SimpleFetcher[T, R]) ShouldSkip added in v0.2.27

func (f *SimpleFetcher[T, R]) ShouldSkip(item T) bool

type UserProfile

type UserProfile struct {
	ID        int64  // GitHub user ID
	Login     string // GitHub username
	Name      string // Display name
	Email     string // Public email (may be empty)
	AvatarURL string
}

UserProfile contains GitHub user profile information useful for deduplication

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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