From 6b8381ff71316a8ef6e84dba0a3e529178f48d50 Mon Sep 17 00:00:00 2001 From: Andrei Pop Date: Wed, 27 Aug 2025 11:58:24 -0400 Subject: [PATCH 1/2] Enhance commit tracking and API performance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add total lifetime commits display using GitHub Search API - Replace misleading "Total Commits" count (was showing 5) with actual lifetime commits - Increase API pagination from 30 to 100 commits per repository (GitHub's maximum) - Increase total commit cap from 150 to 500 for comprehensive data collection - Add fetchTotalCommitCount() function for accurate total commit statistics - Improve All Commits view data completeness for better user insights 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- GitStreak/ContentView.swift | 2 +- GitStreak/Models/GitStreakData.swift | 36 ++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/GitStreak/ContentView.swift b/GitStreak/ContentView.swift index 6defb88..787dc1c 100644 --- a/GitStreak/ContentView.swift +++ b/GitStreak/ContentView.swift @@ -262,7 +262,7 @@ struct StatsView: View { // Invisible spacer card to maintain alignment StatCardView( title: "Total Commits", - value: "\(dataModel.recentCommits.count)", + value: "\(dataModel.totalLifetimeCommits)", color: .orange ) } diff --git a/GitStreak/Models/GitStreakData.swift b/GitStreak/Models/GitStreakData.swift index de3c06c..58bf929 100644 --- a/GitStreak/Models/GitStreakData.swift +++ b/GitStreak/Models/GitStreakData.swift @@ -196,7 +196,7 @@ class GitHubService: ObservableObject { return date1 > date2 } - return Array(allCommits.prefix(150)) // Allow more commits since we're filtering by date + return Array(allCommits.prefix(500)) // Allow more commits since we're filtering by date } private func fetchRepositoryCommits(owner: String, repo: String) async throws -> [GitHubCommit]? { @@ -206,7 +206,7 @@ class GitHubService: ObservableObject { let thirtyDaysAgo = Calendar.current.date(byAdding: .day, value: -30, to: Date()) ?? Date() let sinceDate = ISO8601DateFormatter().string(from: thirtyDaysAgo) - guard let url = URL(string: "\(baseURL)/repos/\(owner)/\(repo)/commits?since=\(sinceDate)&per_page=30") else { + guard let url = URL(string: "\(baseURL)/repos/\(owner)/\(repo)/commits?since=\(sinceDate)&per_page=100") else { return nil } @@ -409,6 +409,34 @@ class GitHubService: ObservableObject { ) } + func fetchTotalCommitCount() async throws -> Int { + guard let token = accessToken, let username = username else { + throw GitHubError.notAuthenticated + } + + guard let url = URL(string: "\(baseURL)/search/commits?q=author:\(username)") else { + throw GitHubError.invalidURL + } + + var request = URLRequest(url: url) + request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") + request.setValue("application/vnd.github.v3+json", forHTTPHeaderField: "Accept") + + let (data, response) = try await URLSession.shared.data(for: request) + + guard let httpResponse = response as? HTTPURLResponse, + httpResponse.statusCode == 200 else { + throw GitHubError.requestFailed((response as? HTTPURLResponse)?.statusCode ?? 0) + } + + struct SearchResponse: Codable { + let total_count: Int + } + + let searchResponse = try JSONDecoder().decode(SearchResponse.self, from: data) + return searchResponse.total_count + } + private func calculateCurrentStreak(commits: [GitHubCommit]) -> Int { guard !commits.isEmpty else { return 0 } @@ -708,6 +736,7 @@ class GitStreakDataModel: ObservableObject { @Published var progress: Double = 0.0 @Published var xpToNext: Int = 100 @Published var totalCommitsThisWeek: Int = 0 + @Published var totalLifetimeCommits: Int = 0 @Published var isLoading = false @Published var errorMessage: String? @@ -811,12 +840,14 @@ class GitStreakDataModel: ObservableObject { do { let stats = try await gitHubService.fetchContributionStats() + let totalCommits = try await gitHubService.fetchTotalCommitCount() await MainActor.run { self.currentStreak = stats.currentStreak self.bestStreak = stats.bestStreak self.recentCommits = Array(stats.recentCommits) self.monthlyCommits = stats.monthlyCommits + self.totalLifetimeCommits = totalCommits self.updateWeeklyData(from: stats.weeklyCommits) self.calculateLevel() self.updateAchievements() @@ -842,6 +873,7 @@ class GitStreakDataModel: ObservableObject { progress = 0.85 xpToNext = 353 totalCommitsThisWeek = 21 + totalLifetimeCommits = 1247 recentCommits = [ CommitData(repo: "my-portfolio", message: "Update homepage design", time: "2h ago", commits: 3), From d9e3260cd00cc75dea1702a7133df2dbbadd81bb Mon Sep 17 00:00:00 2001 From: Andrei Pop Date: Wed, 27 Aug 2025 12:36:02 -0400 Subject: [PATCH 2/2] Refactor HomeView and AwardsTabView for improved UI - Remove unused notification button from HomeView for a cleaner layout. - Adjust padding and background properties in AwardsTabView to enhance visual appeal. - Add shadow effect to the AwardsTabView for better depth perception. These changes streamline the user interface and improve overall aesthetics. --- GitStreak/ContentView.swift | 6 ------ GitStreak/Views/AwardsTabView.swift | 6 ++++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/GitStreak/ContentView.swift b/GitStreak/ContentView.swift index 787dc1c..996d66c 100644 --- a/GitStreak/ContentView.swift +++ b/GitStreak/ContentView.swift @@ -47,12 +47,6 @@ struct HomeView: View { Spacer() HStack(spacing: 12) { - Button(action: {}) { - Image(systemName: "bell") - .font(.title3) - .foregroundColor(.gray) - } - Button(action: { showSettings = true }) { diff --git a/GitStreak/Views/AwardsTabView.swift b/GitStreak/Views/AwardsTabView.swift index f973433..91d1629 100644 --- a/GitStreak/Views/AwardsTabView.swift +++ b/GitStreak/Views/AwardsTabView.swift @@ -62,8 +62,6 @@ struct AwardsTabView: View { Spacer() } .padding(16) - .background(Color(.systemBackground)) - .cornerRadius(12) // Recent Achievement Cards (matching expanded category structure) VStack(spacing: 8) { @@ -72,7 +70,11 @@ struct AwardsTabView: View { } } .padding(.top, 8) + .padding(.horizontal, 16) } + .background(Color(.systemBackground)) + .cornerRadius(12) + .shadow(color: .black.opacity(0.1), radius: 5, x: 0, y: 2) } } .padding(.horizontal, 24)