Files
ghstats/internal/github/queries.go
T
tiennm99 d0d3862780 feat(card): add contributions area chart card
New 5-contributions.svg renders the last year's contribution calendar
as a monthly smooth-filled area chart. Pure Go SVG; no extra API calls
— one additional contributionCalendar.weeks block in the existing
profile GraphQL query carries the data.

- Y-axis mirrored on both sides with nice ticks.
- X-axis labels in YY/MM format, every other month to avoid overlap.
- Smooth curve via Catmull-Rom interpolation converted to cubic Bezier
  (d3.curveCatmullRom default tension 0.5).
- Missing months between first and last are inserted as zero-count so
  the chart stays time-continuous.
2026-04-18 21:20:52 +07:00

86 lines
2.2 KiB
Go

package github
// profileQuery pulls everything needed for the profile, stats and languages
// cards in one round trip. Repo pagination is handled by the caller if the
// user owns more than 100 repos.
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 {
totalCommitContributions
totalIssueContributions
totalPullRequestContributions
totalPullRequestReviewContributions
totalRepositoryContributions
restrictedContributionsCount
contributionCalendar {
totalContributions
weeks {
contributionDays {
contributionCount
date
}
}
}
}
repositories(
first: 100
after: $after
ownerAffiliations: OWNER
isFork: false
orderBy: { field: STARGAZERS, direction: DESC }
) {
totalCount
pageInfo { hasNextPage endCursor }
nodes {
name
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.
const commitHistoryQuery = `
query($login: String!, $repo: String!, $userId: ID!, $since: GitTimestamp!, $after: String) {
repository(owner: $login, name: $repo) {
defaultBranchRef {
target {
... on Commit {
history(first: 100, after: $after, author: { id: $userId }, since: $since) {
pageInfo { hasNextPage endCursor }
nodes { committedDate }
}
}
}
}
}
}`