mirror of
https://github.com/tiennm99/ghstats.git
synced 2026-08-30 18:22:19 +00:00
Split each contribution year into quarterly windows. commitContributionsByRepository caps at 100 repos per query and drops the remainder without signalling it, which a prolific year hits: 2026 returned exactly 100 where the quarterly union returns 108. Warn when a window still comes back at the ceiling instead of reporting a complete list. Add -include-org-repos / include_org_repos so org-owned repos the user administers count toward stars, repo count, repos-per-language and top-starred. Off by default, since enabling it moves those totals for every existing caller. Commit-driven cards already covered org repos through the seed list. Org repos carrying only read or write access are dropped via viewerPermission. Rename Profile.PublicRepos to RepoCount and drop "public" from the card label: the count tracks the fetch filters and includes private repos whenever the token can see them.
131 lines
3.6 KiB
Go
131 lines
3.6 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.
|
|
// $affiliations decides whether org-owned repos are in scope at all; repos the
|
|
// user only has read/write access to are dropped client-side via
|
|
// viewerPermission.
|
|
const profileQuery = `
|
|
query($login: String!, $after: String, $affiliations: [RepositoryAffiliation]) {
|
|
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: $affiliations
|
|
orderBy: { field: STARGAZERS, direction: DESC }
|
|
) {
|
|
totalCount
|
|
pageInfo { hasNextPage endCursor }
|
|
nodes {
|
|
name
|
|
owner { login }
|
|
viewerPermission
|
|
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 }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}`
|