mirror of
https://github.com/tiennm99/ghstats.git
synced 2026-05-20 14:23:58 +00:00
9ac029dfae
Each commit now contributes a full "vote" partitioned across the repo's
languages proportional to linguist byte counts, instead of crediting only
the primary language. A 60% Go / 40% Python repo adds 0.6 to Go and 0.4
to Python per commit.
- RepoInfo gains []LangEdge capturing the full byte breakdown already
returned by profileQuery.
- FetchProductive distributes each commit via a fixed-point scaleFactor
(int64 preserved, percentages unchanged in the card).
- Fallback to primary language only when linguist reports zero bytes
(empty repo).
Caveat: linguist excludes prose languages (Markdown, AsciiDoc, reST) from
its byte output, so Markdown-heavy repos still skew toward the detected
code fraction. Fixing that case requires per-commit file classification
via REST /commits/{sha} + go-enry — tracked as future work.
92 lines
2.4 KiB
Go
92 lines
2.4 KiB
Go
package github
|
|
|
|
import "time"
|
|
|
|
// Profile is the aggregate of data other packages render into cards.
|
|
type Profile struct {
|
|
ID string
|
|
Login string
|
|
Name string
|
|
Bio string
|
|
AvatarURL string
|
|
Company string
|
|
Location string
|
|
Website string
|
|
CreatedAt time.Time
|
|
|
|
Followers int
|
|
Following int
|
|
PublicRepos int
|
|
|
|
// Totals for the stats card.
|
|
TotalStars int
|
|
TotalForks int
|
|
TotalCommits int
|
|
TotalPRs int
|
|
TotalIssues int
|
|
TotalReviews int
|
|
TotalContributedTo int
|
|
TotalContributions int // lifetime contributions from calendar + restricted
|
|
|
|
// Count of owned repos grouped by primary language, sorted desc by Value.
|
|
ReposByLanguage []LangStat
|
|
|
|
// Count of commits (last year, by this user) attributed to each repo's
|
|
// primary language, sorted desc. Populated by FetchProductive.
|
|
CommitsByLanguage []LangStat
|
|
|
|
// Commit counts grouped by hour-of-day (0-23) in the configured timezone.
|
|
Productive [24]int
|
|
|
|
// TopRepos are owned repos sorted by stargazer count desc. Populated by
|
|
// FetchProfile and consumed by FetchProductive.
|
|
TopRepos []RepoInfo
|
|
}
|
|
|
|
// LangStat is one row in a language breakdown card. Value is repo count or
|
|
// commit count depending on which slice holds it.
|
|
type LangStat struct {
|
|
Name string
|
|
Color string
|
|
Value int64
|
|
}
|
|
|
|
// RepoInfo is the minimal owned-repo summary used for downstream fetches.
|
|
type RepoInfo struct {
|
|
Name string
|
|
PrimaryLanguage string
|
|
PrimaryColor string
|
|
// Languages is the repo's language byte breakdown as reported by GitHub
|
|
// linguist. Used to attribute each commit fractionally across all
|
|
// languages the repo contains, rather than crediting only the primary.
|
|
Languages []LangEdge
|
|
}
|
|
|
|
// LangEdge is a single entry in a repo's language-bytes breakdown.
|
|
type LangEdge struct {
|
|
Name string
|
|
Color string
|
|
Bytes int64
|
|
}
|
|
|
|
// repoNode is the GraphQL shape of one repository node; kept here because
|
|
// it's shared by the profile fetcher and the productive-time fetcher.
|
|
type repoNode struct {
|
|
Name string `json:"name"`
|
|
StargazerCount int `json:"stargazerCount"`
|
|
ForkCount int `json:"forkCount"`
|
|
PrimaryLanguage *struct {
|
|
Name string `json:"name"`
|
|
Color string `json:"color"`
|
|
} `json:"primaryLanguage"`
|
|
Languages struct {
|
|
Edges []struct {
|
|
Size int64 `json:"size"`
|
|
Node struct {
|
|
Name string `json:"name"`
|
|
Color string `json:"color"`
|
|
} `json:"node"`
|
|
} `json:"edges"`
|
|
} `json:"languages"`
|
|
}
|