Files
tiennm99 90171c1080 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.
2026-04-18 22:01:26 +07:00

126 lines
3.3 KiB
Go

package github
// profileQuery pulls everything needed for the profile, stats and languages
// cards in one round trip. Fork/private filtering is done client-side so one
// query handles all combinations of -include-forks / -include-private.
const profileQuery = `
query($login: String!, $after: String) {
user(login: $login) {
id
login
name
bio
avatarUrl
company
location
websiteUrl
createdAt
followers { totalCount }
following { totalCount }
pullRequests { totalCount }
issues { totalCount }
repositoriesContributedTo(
first: 1
contributionTypes: [COMMIT, PULL_REQUEST, ISSUE, PULL_REQUEST_REVIEW]
) { totalCount }
contributionsCollection {
contributionYears
totalCommitContributions
totalIssueContributions
totalPullRequestContributions
totalPullRequestReviewContributions
totalRepositoryContributions
restrictedContributionsCount
contributionCalendar {
totalContributions
weeks {
contributionDays {
contributionCount
date
}
}
}
}
repositories(
first: 100
after: $after
ownerAffiliations: OWNER
orderBy: { field: STARGAZERS, direction: DESC }
) {
totalCount
pageInfo { hasNextPage endCursor }
nodes {
name
isPrivate
isFork
stargazerCount
forkCount
primaryLanguage { name color }
languages(first: 20, orderBy: { field: SIZE, direction: DESC }) {
edges {
size
node { name color }
}
}
}
}
}
}`
// commitHistoryQuery fetches commit timestamps in the default branch of one
// repo, filtered to commits authored by the target user. Used to build the
// productive-time heatmap. Owner is a variable because seed repos may belong
// to other users (e.g. forks the user has contributed to).
const commitHistoryQuery = `
query($owner: String!, $repo: String!, $userId: ID!, $after: String) {
repository(owner: $owner, name: $repo) {
defaultBranchRef {
target {
... on Commit {
history(first: 100, after: $after, author: { id: $userId }) {
pageInfo { hasNextPage endCursor }
nodes { committedDate }
}
}
}
}
}
}`
// contributionYearQuery fetches one year's contribution calendar plus the
// repos the user actually committed in that year. The calendar feeds the
// all-time area chart; commitContributionsByRepository feeds the seed list
// that drives commit-history probing.
const contributionYearQuery = `
query($login: String!, $from: DateTime!, $to: DateTime!) {
user(login: $login) {
contributionsCollection(from: $from, to: $to) {
totalCommitContributions
contributionCalendar {
weeks {
contributionDays {
contributionCount
date
}
}
}
commitContributionsByRepository(maxRepositories: 100) {
contributions { totalCount }
repository {
name
owner { login }
isPrivate
isFork
primaryLanguage { name color }
languages(first: 20, orderBy: { field: SIZE, direction: DESC }) {
edges {
size
node { name color }
}
}
}
}
}
}
}`