Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update api to include commits only for 2024 #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/pages/api/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ const MONTH_NAMES = [
"December",
] as const;

// Constants for the Git Wrapped year
const WRAPPED_YEAR = 2024;
const WRAPPED_START = `${WRAPPED_YEAR}-01-01T00:00:00Z`;
const WRAPPED_END = `${WRAPPED_YEAR}-12-31T23:59:59Z`;

/**
* GitHub Stats API endpoint
* Fetches and processes a user's GitHub statistics including:
Expand Down Expand Up @@ -103,7 +108,7 @@ export default async function GET(request: Request): Promise<NextResponse> {
const query = `
query($username: String!) {
user(login: $username) {
contributionsCollection {
contributionsCollection(from: "${WRAPPED_START}", to: "${WRAPPED_END}") {
contributionCalendar {
totalContributions
weeks {
Expand Down Expand Up @@ -133,8 +138,7 @@ export default async function GET(request: Request): Promise<NextResponse> {
// Process contribution data for the current year
const contributionDays =
userData.contributionsCollection.contributionCalendar.weeks
.flatMap((week: any) => week.contributionDays)
.filter((day: any) => new Date(day.date) >= new Date("2024-01-01"));
.flatMap((week: any) => week.contributionDays);

// Calculate monthly contribution statistics
const monthlyCommits: Record<string, number> = {};
Expand Down