profile

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package profile provides aggregated GitHub user profile statistics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMonthlyFileCount added in v0.12.0

func GetMonthlyFileCount(filepath string) (int, error)

GetMonthlyFileCount returns the count of merged months for reporting.

func RenderToFile added in v0.12.0

func RenderToFile(path string, report *StatsReport, opts RenderOptions) error

RenderToFile renders a StatsReport to a file.

func RenderToHTML added in v0.12.0

func RenderToHTML(report *StatsReport, opts RenderOptions) (string, error)

RenderToHTML renders a StatsReport to HTML format.

func RenderToMarkdown added in v0.12.0

func RenderToMarkdown(report *StatsReport, opts RenderOptions) (string, error)

RenderToMarkdown renders a StatsReport to Markdown format.

func RenderToText added in v0.12.0

func RenderToText(report *StatsReport, opts RenderOptions) (string, error)

RenderToText renders a StatsReport to plain text format.

func WriteMonthlyFile added in v0.12.0

func WriteMonthlyFile(dir string, username string, stats MonthlyStats, meta QueryMetadata) (string, error)

WriteMonthlyFile writes a single month's stats to a file. Filename format: {username}_github_{YYYY-MM}.json

func WriteMonthlyFiles added in v0.12.0

func WriteMonthlyFiles(dir string, p *UserProfile, opts *Options) ([]string, error)

WriteMonthlyFiles writes individual files for each month in the profile. Returns a list of written file paths.

func WriteMonthlyMultiFile added in v0.12.0

func WriteMonthlyMultiFile(fp string, p *UserProfile, opts *Options) error

WriteMonthlyMultiFile writes all months to a single file with merge support. If the file exists, new months are merged with existing data (overwriting duplicates). Months are sorted in descending order (newest first).

func WriteStatsReport added in v0.12.0

func WriteStatsReport(path string, report *StatsReport) error

WriteStatsReport writes a StatsReport to a JSON file.

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) GetMonthStats added in v0.12.0

func (t *ActivityTimeline) GetMonthStats(year int, month time.Month) *MonthlyStats

GetMonthStats returns MonthlyStats 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) ToMonthlyStats added in v0.12.0

func (t *ActivityTimeline) ToMonthlyStats() []MonthlyStats

ToMonthlyStats converts all months to MonthlyStats slice.

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 AggregateStats added in v0.12.0

type AggregateStats struct {
	Commits              int `json:"commits"`
	Issues               int `json:"issues"`
	PRs                  int `json:"prs"`
	Reviews              int `json:"reviews"`
	Releases             int `json:"releases"`
	Additions            int `json:"additions"`
	Deletions            int `json:"deletions"`
	NetAdditions         int `json:"netAdditions"`
	RepoCountContributed int `json:"repoCountContributed"`
	RepoCountCreated     int `json:"repoCountCreated"`
}

AggregateStats contains the actual statistics that can be summed.

func (*AggregateStats) Add added in v0.12.0

func (a *AggregateStats) Add(b AggregateStats)

Add adds another AggregateStats to this one (for rollups).

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 DateRange added in v0.12.0

type DateRange struct {
	From string `json:"from"` // YYYY-MM-DD
	To   string `json:"to"`   // YYYY-MM-DD
}

DateRange represents a date range.

type MonthStats added in v0.12.0

type MonthStats struct {
	Year      int            `json:"year"`
	Month     int            `json:"month"`
	MonthName string         `json:"monthName"`
	Stats     AggregateStats `json:"stats"`
}

MonthStats contains statistics for a single month within a report.

type MonthlyActivity

type MonthlyActivity struct {
	Year  int
	Month time.Month

	// Contribution counts
	Commits  int
	Issues   int
	PRs      int
	Reviews  int
	Releases int // Releases published in contributed repos this month

	// 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) NetAdditions added in v0.12.0

func (m *MonthlyActivity) NetAdditions() int

NetAdditions returns the net lines changed (additions - deletions).

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) RepoCountCreated added in v0.12.0

func (m *MonthlyActivity) RepoCountCreated() int

RepoCountCreated returns the number of repositories created this month.

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) ToMonthlyStats added in v0.12.0

func (m *MonthlyActivity) ToMonthlyStats() MonthlyStats

ToMonthlyStats converts MonthlyActivity to a JSON-serializable MonthlyStats.

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 MonthlyOutputFile added in v0.12.0

type MonthlyOutputFile struct {
	Metadata  QueryMetadata `json:"metadata"`
	Username  string        `json:"username"`
	Year      int           `json:"year"`
	Month     int           `json:"month"`
	MonthName string        `json:"monthName"`
	Stats     MonthlyStats  `json:"stats"`
}

MonthlyOutputFile is the structure for a single monthly output file.

func LoadMonthlyFiles added in v0.12.0

func LoadMonthlyFiles(dir string) ([]MonthlyOutputFile, error)

LoadMonthlyFiles loads all monthly JSON files from a directory.

type MonthlyOutputMulti added in v0.12.0

type MonthlyOutputMulti struct {
	Metadata QueryMetadata  `json:"metadata"`
	Username string         `json:"username"`
	Months   []MonthlyStats `json:"months"`
}

MonthlyOutputMulti is the structure for a combined monthly output file.

type MonthlyStats added in v0.12.0

type MonthlyStats struct {
	Year      int    `json:"year"`
	Month     int    `json:"month"`
	MonthName string `json:"monthName"`

	// Contribution counts
	Commits  int `json:"commits"`
	Issues   int `json:"issues"`
	PRs      int `json:"prs"`
	Reviews  int `json:"reviews"`
	Releases int `json:"releases"`

	// Code changes
	Additions    int `json:"additions"`
	Deletions    int `json:"deletions"`
	NetAdditions int `json:"netAdditions"`

	// Repository counts
	RepoCountContributed int `json:"repoCountContributed"`
	RepoCountCreated     int `json:"repoCountCreated"`
}

MonthlyStats is the JSON-serializable representation of monthly activity. This includes all computed fields for easy consumption by external tools.

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

	// ReleaseOrgs filters which organizations/owners to count releases for.
	// If empty, counts releases from all repos. If set, only repos owned by
	// these orgs/users are counted (e.g., ["grokify", "plexusone"]).
	ReleaseOrgs []string

	// 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 QuarterStats added in v0.12.0

type QuarterStats struct {
	Quarter int            `json:"quarter"` // 1-4
	Year    int            `json:"year"`
	Label   string         `json:"label"` // e.g., "Q1 2026"
	Stats   AggregateStats `json:"stats"`
	Months  []MonthStats   `json:"months"`
}

QuarterStats contains statistics for a single quarter.

type QueryMetadata added in v0.12.0

type QueryMetadata struct {
	// Query parameters
	Username    string   `json:"username"`
	From        string   `json:"from"`                  // YYYY-MM-DD format
	To          string   `json:"to"`                    // YYYY-MM-DD format
	Visibility  string   `json:"visibility"`            // all, public, private
	ReleaseOrgs []string `json:"releaseOrgs,omitempty"` // orgs to filter releases

	// Feature flags
	IncludeReleases bool `json:"includeReleases"`

	// Generation info
	GeneratedAt time.Time `json:"generatedAt"`
	Command     string    `json:"command,omitempty"` // CLI command used (optional)
}

QueryMetadata captures the parameters used to generate the output. This enables reproducibility and consistent generation of additional data.

func NewQueryMetadata added in v0.12.0

func NewQueryMetadata(username string, from, to time.Time, opts *Options) QueryMetadata

NewQueryMetadata creates QueryMetadata from Options and profile data.

type RenderFormat added in v0.12.0

type RenderFormat string

RenderFormat specifies the output format for rendering.

const (
	RenderFormatMarkdown RenderFormat = "markdown"
	RenderFormatHTML     RenderFormat = "html"
	RenderFormatText     RenderFormat = "text"
)

type RenderOptions added in v0.12.0

type RenderOptions struct {
	Format           RenderFormat
	Title            string
	ShowMonthDetails bool
	ShowDataSource   bool
	DataSourceURL    string
	RawDataFiles     []string
	RegenerateCmd    string
}

RenderOptions configures report rendering.

func DefaultRenderOptions added in v0.12.0

func DefaultRenderOptions() RenderOptions

DefaultRenderOptions returns default render options.

type RepoCommitCount

type RepoCommitCount struct {
	Repo    string
	Commits int
}

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 ReportMetadata added in v0.12.0

type ReportMetadata struct {
	Username    string    `json:"username"`
	Visibility  string    `json:"visibility"`
	GeneratedAt time.Time `json:"generatedAt"`
	DataRange   DateRange `json:"dataRange"`
}

ReportMetadata contains information about the report generation.

type StatsReport added in v0.12.0

type StatsReport struct {
	Metadata ReportMetadata `json:"metadata"`
	Years    []YearStats    `json:"years"`
}

StatsReport is the top-level structure for aggregated statistics. It organizes data hierarchically: years -> quarters -> months.

func BuildStatsReport added in v0.12.0

func BuildStatsReport(files []MonthlyOutputFile) (*StatsReport, error)

BuildStatsReport builds a StatsReport from monthly files.

func LoadStatsReport added in v0.12.0

func LoadStatsReport(path string) (*StatsReport, error)

LoadStatsReport loads a StatsReport from a JSON file.

func (*StatsReport) GetLatestQuarter added in v0.12.0

func (r *StatsReport) GetLatestQuarter() *QuarterStats

GetLatestQuarter returns the most recent quarter in the report.

func (*StatsReport) GetQuarter added in v0.12.0

func (r *StatsReport) GetQuarter(year, quarter int) *QuarterStats

GetQuarter returns a specific quarter's stats.

func (*StatsReport) GetYear added in v0.12.0

func (r *StatsReport) GetYear(year int) *YearStats

GetYear returns a specific year's stats.

func (*StatsReport) TotalStats added in v0.12.0

func (r *StatsReport) TotalStats() AggregateStats

TotalStats returns the total stats across all years.

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.

type YearStats added in v0.12.0

type YearStats struct {
	Year     int            `json:"year"`
	Stats    AggregateStats `json:"stats"`
	Quarters []QuarterStats `json:"quarters"`
}

YearStats contains statistics for a single year.

Directories

Path Synopsis
Package readme generates GitHub profile README files from user profile data.
Package readme generates GitHub profile README files from user profile data.
svg
Package svg provides SVG stats card generation for GitHub profiles.
Package svg provides SVG stats card generation for GitHub profiles.
chart
Package chart provides generic SVG chart generation.
Package chart provides generic SVG chart generation.

Jump to

Keyboard shortcuts

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