githubapi

package
v0.0.0-...-6a262f7 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: GPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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, options ...Options) (*Client, error)

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

func (client *Client) FetchTotalContributions(ctx context.Context) (int, error)

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.

type Options

type Options struct {
	HTTPClient      *http.Client
	RESTEndpoint    string
	GraphQLEndpoint string
}

Options overrides HTTP settings for a configured GitHub API endpoint. NewClient applies supplied values in order and ignores empty fields.

Jump to

Keyboard shortcuts

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