feat: seed-based repo scanning + fork/private visibility flags

Replace the top-10-starred sampling with a seed list built from
contributionsCollection.commitContributionsByRepository, unioned across
every active contributionYear. Commit-history probes now land only on
repos where the user actually committed, covering all owned repos plus
forks and repos owned by others when allowed.

New visibility knobs (default off — public-facing READMEs stay
safe):
- -include-forks / include_forks    : include forked repos
- -include-private / include_private: include private repos (requires
                                      PAT with repo scope)

Compatibility:
- -top-repos default changed 10 → 0 (unlimited); still usable as a cap
  for fast local runs.
- commitHistoryQuery now takes $owner so probes can target forks or
  repos outside the user's ownership.
- FetchProfile now accepts FetchOptions; PublicRepos counts only repos
  that pass the visibility filter.

Seed-list approach mirrors github-profile-summary-cards' own repo
sourcing but keeps our byte-weighted commit attribution.
This commit is contained in:
tiennm99 committed 2026-04-18 22:01:26 +07:00
1 parent 0f54d5e885
commit 2943db667c
8 files changed
+179 -57

No files matched your search

+46 -3
View File
@@ -57,10 +57,17 @@ type Profile struct {
// all-time area chart can show history beyond the default 1-year window.
DailyContributionsAllTime []DailyContribution
// TopRepos are owned repos sorted by stargazer count desc. Populated by
// FetchProfile and consumed by FetchProductive.
// TopRepos are owned non-fork repos sorted by stargazer count desc,
// populated by FetchProfile. Used for the profile's stars/forks totals
// and the repos-per-language card.
TopRepos []RepoInfo
// SeedRepos are the repos where the user actually committed, unioned
// across every contribution year via commitContributionsByRepository.
// Used by FetchProductive so commit-history probes land where there is
// signal instead of across the long tail of empty owned repos.
SeedRepos []RepoInfo
// ContributionYears lists every calendar year the user has been active
// on GitHub, newest first. Used by FetchContributionsAllTime to iterate
// per-year contributionsCollection queries.
@@ -86,9 +93,13 @@ type LangStat struct {
Value int64
}
// RepoInfo is the minimal owned-repo summary used for downstream fetches.
// RepoInfo is the minimal repo summary used for downstream fetches. Owner is
// kept so the history query can target forks / repos belonging to other users.
type RepoInfo struct {
Owner string
Name string
IsPrivate bool
IsFork bool
PrimaryLanguage string
PrimaryColor string
// Languages is the repo's language byte breakdown as reported by GitHub
@@ -108,8 +119,13 @@ type LangEdge struct {
// it's shared by the profile fetcher and the productive-time fetcher.
type repoNode struct {
Name string `json:"name"`
IsPrivate bool `json:"isPrivate"`
IsFork bool `json:"isFork"`
StargazerCount int `json:"stargazerCount"`
ForkCount int `json:"forkCount"`
Owner *struct {
Login string `json:"login"`
} `json:"owner"`
PrimaryLanguage *struct {
Name string `json:"name"`
Color string `json:"color"`
@@ -124,3 +140,30 @@ type repoNode struct {
} `json:"edges"`
} `json:"languages"`
}
// toRepoInfo converts the GraphQL shape into our public RepoInfo, defaulting
// owner to the given login if the node omits it (profile query doesn't
// request owner since it's implicit on user.repositories).
func (r repoNode) toRepoInfo(defaultOwner string) RepoInfo {
info := RepoInfo{
Owner: defaultOwner,
Name: r.Name,
IsPrivate: r.IsPrivate,
IsFork: r.IsFork,
}
if r.Owner != nil {
info.Owner = r.Owner.Login
}
if r.PrimaryLanguage != nil {
info.PrimaryLanguage = r.PrimaryLanguage.Name
info.PrimaryColor = r.PrimaryLanguage.Color
}
for _, e := range r.Languages.Edges {
info.Languages = append(info.Languages, LangEdge{
Name: e.Node.Name,
Color: e.Node.Color,
Bytes: e.Size,
})
}
return info
}