Documentation
¶
Overview ¶
Package githubapi wraps the GitHub REST and GraphQL APIs that stats-gh uses, including a rate-limit-aware HTTP transport and typed query helpers.
Index ¶
- type Client
- func (client *Client) EstimateExternalContributions(ctx context.Context, repositories []internalmodel.Repository) ([]internalmodel.ExternalContributionEstimate, error)
- func (client *Client) FetchContributorActivity(ctx context.Context, repositories []internalmodel.Repository, now time.Time, ...) ([]internalmodel.RepoActivity, int, int, error)
- func (client *Client) FetchTotalContributions(ctx context.Context) (int, error)
- func (client *Client) FetchViewerRepositories(ctx context.Context) (internalmodel.ViewerSummary, []internalmodel.Repository, ...)
- func (client *Client) FetchViews(ctx context.Context, repositories []internalmodel.Repository) (map[string]map[string]int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the stats-gh GitHub API wrapper, holding the REST client and the authenticated viewer login it should query on behalf of.
func NewClient ¶
func NewClient(cfg internalconfig.Config) *Client
NewClient returns a Client configured from the given Config, using OAuth2 bearer authentication on every outbound HTTP request.
func (*Client) EstimateExternalContributions ¶
func (client *Client) EstimateExternalContributions(ctx context.Context, repositories []internalmodel.Repository) ([]internalmodel.ExternalContributionEstimate, error)
EstimateExternalContributions approximates the viewer's contribution share for each external repository by ratio of their additions+deletions to the repo's total contributor activity, then scales the repo's language bytes by that ratio.
func (*Client) FetchContributorActivity ¶
func (client *Client) FetchContributorActivity(ctx context.Context, repositories []internalmodel.Repository, now time.Time, halfLife time.Duration, floor float64) ([]internalmodel.RepoActivity, int, int, error)
FetchContributorActivity walks each repository's default-branch commit history filtered by the configured actor, returning per-repo commit counts (raw and per-commit recency-weighted) plus the global additions/deletions totals. Each commit's contribution to WeightedCommits is max(floor, 0.5^(age/halfLife)).
func (*Client) FetchTotalContributions ¶
FetchTotalContributions returns the viewer's lifetime contribution count by summing per-year contribution calendars across every year GitHub reports activity for.
func (*Client) FetchViewerRepositories ¶
func (client *Client) FetchViewerRepositories(ctx context.Context) (internalmodel.ViewerSummary, []internalmodel.Repository, []internalmodel.Repository, error)
FetchViewerRepositories returns the authenticated viewer plus two paginated repository slices: those owned by the viewer, and those they have contributed to but do not own.
func (*Client) FetchViews ¶
func (client *Client) FetchViews(ctx context.Context, repositories []internalmodel.Repository) (map[string]map[string]int, error)
FetchViews returns a per-repo map of ISO date strings to view counts for the trailing-14-day window across every owned repository. Callers merge the result into a persisted history file so view totals can accumulate past the 14-day API window. Repos the token lacks push access to return 403 and are skipped with a warning log.