Documentation
¶
Overview ¶
Package profile provides aggregated GitHub user profile statistics.
Index ¶
- type ActivityTimeline
- func (t *ActivityTimeline) AverageMonthlyContributions() float64
- func (t *ActivityTimeline) GetMonth(year int, month time.Month) *MonthlyActivity
- func (t *ActivityTimeline) MonthsWithActivity() int
- func (t *ActivityTimeline) MostActiveMonth() *MonthlyActivity
- func (t *ActivityTimeline) SortByDate()
- func (t *ActivityTimeline) SortByDateDesc()
- func (t *ActivityTimeline) TotalCommits() int
- func (t *ActivityTimeline) TotalContributions() int
- type CalendarDay
- type CalendarWeek
- type ContributionCalendar
- func (c *ContributionCalendar) CurrentStreak() int
- func (c *ContributionCalendar) DaysWithContributions() int
- func (c *ContributionCalendar) GetDateRange() (first, last time.Time)
- func (c *ContributionCalendar) GetDay(date time.Time) *CalendarDay
- func (c *ContributionCalendar) GetWeek(date time.Time) *CalendarWeek
- func (c *ContributionCalendar) LongestStreak() int
- type ContributionLevel
- type MonthlyActivity
- func (m *MonthlyActivity) CommitRepoCount() int
- func (m *MonthlyActivity) CommitSummary() string
- func (m *MonthlyActivity) IssueSummary() string
- func (m *MonthlyActivity) MonthName() string
- func (m *MonthlyActivity) PRSummary() string
- func (m *MonthlyActivity) RepoCreatedSummary() string
- func (m *MonthlyActivity) ReviewSummary() string
- func (m *MonthlyActivity) TopCommitRepos(n int) []RepoCommitCount
- func (m *MonthlyActivity) TotalContributions() int
- func (m *MonthlyActivity) YearMonth() string
- type Options
- type ProgressFunc
- type ProgressInfo
- type RepoCommitCount
- type RepoContribution
- type UserProfile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActivityTimeline ¶
type ActivityTimeline struct {
Username string
From time.Time
To time.Time
Months []MonthlyActivity
}
ActivityTimeline represents a chronological list of monthly activity.
func (*ActivityTimeline) AverageMonthlyContributions ¶
func (t *ActivityTimeline) AverageMonthlyContributions() float64
AverageMonthlyContributions returns the average contributions per month.
func (*ActivityTimeline) GetMonth ¶
func (t *ActivityTimeline) GetMonth(year int, month time.Month) *MonthlyActivity
GetMonth returns activity for a specific year/month. Returns nil if not found.
func (*ActivityTimeline) MonthsWithActivity ¶
func (t *ActivityTimeline) MonthsWithActivity() int
MonthsWithActivity returns the count of months that have any contributions.
func (*ActivityTimeline) MostActiveMonth ¶
func (t *ActivityTimeline) MostActiveMonth() *MonthlyActivity
MostActiveMonth returns the month with the most total contributions.
func (*ActivityTimeline) SortByDate ¶
func (t *ActivityTimeline) SortByDate()
SortByDate sorts months chronologically (oldest first).
func (*ActivityTimeline) SortByDateDesc ¶
func (t *ActivityTimeline) SortByDateDesc()
SortByDateDesc sorts months reverse chronologically (newest first).
func (*ActivityTimeline) TotalCommits ¶
func (t *ActivityTimeline) TotalCommits() int
TotalCommits returns the sum of commits across all months.
func (*ActivityTimeline) TotalContributions ¶
func (t *ActivityTimeline) TotalContributions() int
TotalContributions returns the sum of all contribution types across all months.
type CalendarDay ¶
type CalendarDay struct {
Date time.Time
Weekday time.Weekday
ContributionCount int
Level ContributionLevel // Intensity level for coloring (0-4)
}
CalendarDay represents a single day in the contribution calendar.
type CalendarWeek ¶
type CalendarWeek struct {
StartDate time.Time // Sunday of this week
Days [7]CalendarDay // Sunday (0) through Saturday (6)
}
CalendarWeek represents a single week in the contribution calendar.
func (*CalendarWeek) TotalForWeek ¶
func (w *CalendarWeek) TotalForWeek() int
TotalForWeek returns the total contributions for a specific week.
type ContributionCalendar ¶
type ContributionCalendar struct {
TotalContributions int
Weeks []CalendarWeek
}
ContributionCalendar represents the GitHub contribution calendar grid. This mirrors the visual contribution graph shown on GitHub user profiles.
func NewCalendarFromDays ¶
func NewCalendarFromDays(days []CalendarDay) *ContributionCalendar
NewCalendarFromDays creates a ContributionCalendar from a slice of day data. Days should be provided in chronological order.
func (*ContributionCalendar) CurrentStreak ¶
func (c *ContributionCalendar) CurrentStreak() int
CurrentStreak returns the current ongoing streak ending today (or most recent day).
func (*ContributionCalendar) DaysWithContributions ¶
func (c *ContributionCalendar) DaysWithContributions() int
DaysWithContributions returns the number of days with at least one contribution.
func (*ContributionCalendar) GetDateRange ¶
func (c *ContributionCalendar) GetDateRange() (first, last time.Time)
GetDateRange returns the first and last dates in the calendar.
func (*ContributionCalendar) GetDay ¶
func (c *ContributionCalendar) GetDay(date time.Time) *CalendarDay
GetDay returns the contribution data for a specific date. Returns nil if the date is not in the calendar.
func (*ContributionCalendar) GetWeek ¶
func (c *ContributionCalendar) GetWeek(date time.Time) *CalendarWeek
GetWeek returns the week containing the given date. Returns nil if the date is not in the calendar.
func (*ContributionCalendar) LongestStreak ¶
func (c *ContributionCalendar) LongestStreak() int
LongestStreak returns the longest consecutive streak of days with contributions.
type ContributionLevel ¶
type ContributionLevel int
ContributionLevel represents the intensity of contributions for visual display.
const ( LevelNone ContributionLevel = 0 // No contributions LevelLow ContributionLevel = 1 // 1-3 contributions LevelMedium ContributionLevel = 2 // 4-6 contributions LevelHigh ContributionLevel = 3 // 7-9 contributions LevelMaximum ContributionLevel = 4 // 10+ contributions )
func CalculateLevel ¶
func CalculateLevel(count int) ContributionLevel
CalculateLevel determines the contribution level based on count. These thresholds approximate GitHub's visual intensity levels.
type MonthlyActivity ¶
type MonthlyActivity struct {
Year int
Month time.Month
// Contribution counts
Commits int
Issues int
PRs int
Reviews int
// Commit details
Additions int
Deletions int
// Repository breakdown for commits
CommitsByRepo map[string]int // "owner/repo" -> commit count
// Repos where user opened issues/PRs this month
IssueRepos []string
PRRepos []string
// New repos created this month
ReposCreated []string
}
MonthlyActivity represents contribution activity for a single month. This mirrors the activity feed format shown on GitHub user profiles.
func (*MonthlyActivity) CommitRepoCount ¶
func (m *MonthlyActivity) CommitRepoCount() int
CommitRepoCount returns the number of distinct repos with commits.
func (*MonthlyActivity) CommitSummary ¶
func (m *MonthlyActivity) CommitSummary() string
CommitSummary returns a GitHub-style summary string. Example: "Created 42 commits in 5 repositories"
func (*MonthlyActivity) IssueSummary ¶
func (m *MonthlyActivity) IssueSummary() string
IssueSummary returns a GitHub-style summary for issues. Example: "Opened 5 issues in 3 repositories"
func (*MonthlyActivity) MonthName ¶
func (m *MonthlyActivity) MonthName() string
MonthName returns the full month name (e.g., "January").
func (*MonthlyActivity) PRSummary ¶
func (m *MonthlyActivity) PRSummary() string
PRSummary returns a GitHub-style summary for PRs. Example: "Opened 3 pull requests in 2 repositories"
func (*MonthlyActivity) RepoCreatedSummary ¶
func (m *MonthlyActivity) RepoCreatedSummary() string
RepoCreatedSummary returns a summary for created repos.
func (*MonthlyActivity) ReviewSummary ¶
func (m *MonthlyActivity) ReviewSummary() string
ReviewSummary returns a summary for PR reviews.
func (*MonthlyActivity) TopCommitRepos ¶
func (m *MonthlyActivity) TopCommitRepos(n int) []RepoCommitCount
TopCommitRepos returns the top N repositories by commit count.
func (*MonthlyActivity) TotalContributions ¶
func (m *MonthlyActivity) TotalContributions() int
TotalContributions returns the sum of all contribution types.
func (*MonthlyActivity) YearMonth ¶
func (m *MonthlyActivity) YearMonth() string
YearMonth returns a formatted string like "2024-01".
type Options ¶
type Options struct {
// Visibility filters which repositories to include.
// Default is VisibilityAll.
Visibility graphql.Visibility
// IncludeReleases fetches release counts for each contributed repository.
// This requires additional API calls and may be slow for users with many repos.
IncludeReleases bool
// MaxReleaseFetchRepos limits how many repos to fetch releases for.
// 0 means no limit. Only used if IncludeReleases is true.
MaxReleaseFetchRepos int
// Progress is called to report progress during fetching.
// If nil, no progress is reported.
Progress ProgressFunc
}
Options configures what data to fetch for a user profile.
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions returns sensible default options.
type ProgressFunc ¶
type ProgressFunc func(info ProgressInfo)
ProgressFunc is called to report progress during profile fetching.
type ProgressInfo ¶
type ProgressInfo struct {
Stage int // Current stage number (1-based)
TotalStages int // Total number of stages
Description string // What's happening in this stage
Current int // Current item within stage (0 if not applicable)
Total int // Total items in stage (0 if not applicable)
Done bool // True if this stage is complete
}
ProgressInfo contains information about the current progress state.
type RepoCommitCount ¶
RepoCommitCount pairs a repository name with its commit count.
type RepoContribution ¶
type RepoContribution struct {
Owner string
Name string
FullName string // "owner/repo"
IsPrivate bool
Commits int
Additions int
Deletions int
Releases int // Number of releases (optional, may be 0 if not fetched)
}
RepoContribution contains contribution statistics for a single repository.
type UserProfile ¶
type UserProfile struct {
Username string
From time.Time
To time.Time
// Summary counts (from GitHub's contribution collection)
// TotalCommits is the official GitHub count shown on the profile page.
TotalCommits int
TotalIssues int
TotalPRs int
TotalReviews int
TotalReposCreated int
// Private contributions (requires authentication as the user)
RestrictedContributions int
// Detailed commit stats from traversing default branch history.
// CommitsDefaultBranch may differ from TotalCommits because it only
// counts commits on default branches, missing feature branches,
// squash-merged commits, and inaccessible repositories.
CommitsDefaultBranch int
TotalAdditions int
TotalDeletions int
// Repository data
ReposContributedTo int
RepoStats []RepoContribution
// Time-series data
Calendar *ContributionCalendar
Activity *ActivityTimeline
}
UserProfile contains comprehensive GitHub contribution statistics for a user. This aggregates data from multiple GitHub API endpoints to provide a complete picture of a user's contributions, similar to what's shown on their profile page.
func GetUserProfile ¶
func GetUserProfile(ctx context.Context, restClient *github.Client, gqlClient *githubv4.Client, username string, from, to time.Time, opts *Options) (*UserProfile, error)
GetUserProfile fetches comprehensive profile statistics for a GitHub user. This function makes multiple API calls to gather all data:
- GraphQL: contributionsCollection for summary stats and calendar
- GraphQL: commit history for additions/deletions per repo
- REST: release counts (optional)
func (*UserProfile) PrivateRepos ¶
func (p *UserProfile) PrivateRepos() []RepoContribution
PrivateRepos returns only private repository contributions.
func (*UserProfile) PublicRepos ¶
func (p *UserProfile) PublicRepos() []RepoContribution
PublicRepos returns only public repository contributions.
func (*UserProfile) Summary ¶
func (p *UserProfile) Summary() string
Summary returns a brief text summary of the profile.
func (*UserProfile) TopReposByAdditions ¶
func (p *UserProfile) TopReposByAdditions(n int) []RepoContribution
TopReposByAdditions returns the top N repositories by lines added.
func (*UserProfile) TopReposByCommits ¶
func (p *UserProfile) TopReposByCommits(n int) []RepoContribution
TopReposByCommits returns the top N repositories by commit count.