Skip to content

Commit

Permalink
fix: total commits number (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciNyan authored Feb 27, 2024
1 parent 643f1ee commit ed15694
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions packages/pixel-profile/src/fetchers/stats-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ const GRAPHQL_REPOS_QUERY = `

// eslint-disable-next-line eslint-comments/disable-enable-pair
const GRAPHQL_STATS_QUERY = /* eslint-disable max-len */ `
query userInfo($login: String!, $after: String, $includeMergedPullRequests: Boolean!, $includeDiscussions: Boolean!, $includeDiscussionsAnswers: Boolean!) {
query userInfo($login: String!, $after: String, $includeMergedPullRequests: Boolean!, $includeDiscussions: Boolean!, $includeDiscussionsAnswers: Boolean!, $contributionFrom: DateTime) {
user(login: $login) {
name
login
avatarUrl(size: 280)
bio
contributionsCollection {
totalCommitContributions,
contributionsCollection(from: $contributionFrom) {
totalCommitContributions,
totalPullRequestReviewContributions
}
}
repositoriesContributedTo(first: 1, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) {
totalCount
}
Expand Down Expand Up @@ -99,13 +99,15 @@ type Variables = {
includeMergedPullRequests: boolean
includeDiscussions: boolean
includeDiscussionsAnswers: boolean
contributionFrom: string | null
}

const statsFetcher = async ({
username,
includeMergedPullRequests,
includeDiscussions,
includeDiscussionsAnswers
includeDiscussionsAnswers,
contributionFrom
}: Variables): Promise<AxiosResponse> => {
let stats
let hasNextPage = true
Expand All @@ -117,7 +119,8 @@ const statsFetcher = async ({
after: endCursor,
includeMergedPullRequests,
includeDiscussions,
includeDiscussionsAnswers
includeDiscussionsAnswers,
contributionFrom
}
const res = await retryer(fetcher, variables)
if (res.data.errors) {
Expand Down Expand Up @@ -233,7 +236,8 @@ export async function fetchStats(
username,
includeMergedPullRequests: include_merged_pull_requests,
includeDiscussions: include_discussions,
includeDiscussionsAnswers: include_discussions_answers
includeDiscussionsAnswers: include_discussions_answers,
contributionFrom: include_all_commits ? null : getFirstSecondOfYear().toISOString()
})

// Catch GraphQL errors.
Expand Down Expand Up @@ -301,3 +305,13 @@ export async function fetchStats(

return stats
}

function getFirstSecondOfYear(): Date {
const d = new Date()
d.setFullYear(d.getFullYear())
d.setUTCMonth(0)
d.setUTCDate(1)
d.setUTCHours(0, 0, 0, 0)

return d
}

0 comments on commit ed15694

Please sign in to comment.