graphql

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package graphql provides GitHub GraphQL API utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(ctx context.Context, token string) *githubv4.Client

NewClient creates a GitHub GraphQL client authenticated with the given token.

func NewEnterpriseClient

func NewEnterpriseClient(ctx context.Context, token, baseURL string) *githubv4.Client

NewEnterpriseClient creates a GitHub GraphQL client for GitHub Enterprise.

func NewTokenClient

func NewTokenClient(ctx context.Context, token string) *http.Client

NewTokenClient creates an HTTP client authenticated with the given token.

Types

type CommitStats

type CommitStats struct {
	Username     string
	From         time.Time
	To           time.Time
	Visibility   Visibility
	TotalCommits int
	Additions    int
	Deletions    int
	ByMonth      []MonthlyCommitStats
	ByRepo       []RepoCommitStats
}

CommitStats represents detailed commit statistics including additions and deletions.

func GetCommitStats

func GetCommitStats(ctx context.Context, client *githubv4.Client, username string, from, to time.Time, visibility Visibility) (*CommitStats, error)

GetCommitStats retrieves detailed commit statistics including additions and deletions. This method iterates through all repositories the user has contributed to and aggregates commit data. Use the visibility parameter to filter by public/private repositories.

func GetCommitStatsByVisibility

func GetCommitStatsByVisibility(ctx context.Context, client *githubv4.Client, username string, from, to time.Time) (all, public, private *CommitStats, err error)

GetCommitStatsByVisibility returns separate stats for public, private, and combined.

type ContributionStats

type ContributionStats struct {
	Username                     string
	From                         time.Time
	To                           time.Time
	TotalCommitContributions     int
	TotalIssueContributions      int
	TotalPRContributions         int
	TotalPRReviewContributions   int
	TotalRepositoryContributions int
	RestrictedContributions      int // All private contributions (not just commits)
	ContributionsByMonth         []MonthlyContribution
}

ContributionStats represents aggregated contribution statistics from the contributionsCollection query. This provides quick stats similar to what's shown on a user's GitHub profile page.

Note: RestrictedContributions includes all private contribution types (commits, issues, PRs, reviews), not just commits.

func GetContributionStats

func GetContributionStats(ctx context.Context, client *githubv4.Client, username string, from, to time.Time) (*ContributionStats, error)

GetContributionStats retrieves contribution statistics for a user within a date range. The GitHub API limits queries to a maximum of 1 year at a time.

func GetContributionStatsMultiYear

func GetContributionStatsMultiYear(ctx context.Context, client *githubv4.Client, username string, from, to time.Time) (*ContributionStats, error)

GetContributionStatsMultiYear retrieves contribution statistics spanning multiple years. It automatically handles the 1-year limit by making multiple queries.

type MonthlyCommitStats

type MonthlyCommitStats struct {
	Year      int
	Month     time.Month
	Commits   int
	Additions int
	Deletions int
}

MonthlyCommitStats represents commit statistics for a specific month.

func (MonthlyCommitStats) YearMonth

func (mcs MonthlyCommitStats) YearMonth() string

YearMonth returns a formatted string like "2024-01".

type MonthlyContribution

type MonthlyContribution struct {
	Year  int
	Month time.Month
	Count int
}

MonthlyContribution represents contribution counts for a specific month.

func (MonthlyContribution) YearMonth

func (mc MonthlyContribution) YearMonth() string

YearMonth returns a formatted string like "2024-01".

type RepoCommitStats

type RepoCommitStats struct {
	Owner     string
	Name      string
	IsPrivate bool
	Commits   int
	Additions int
	Deletions int
}

RepoCommitStats represents commit statistics for a specific repository.

type Visibility

type Visibility int

Visibility represents repository visibility for filtering.

const (
	// VisibilityAll includes both public and private repositories.
	VisibilityAll Visibility = iota
	// VisibilityPublic includes only public repositories.
	VisibilityPublic
	// VisibilityPrivate includes only private repositories.
	VisibilityPrivate
)

Jump to

Keyboard shortcuts

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