@@ -64,6 +64,8 @@ class GitHubService {
6464 private readonly CACHE_KEY = "github_org_stats" ;
6565 private readonly CACHE_DURATION = 30 * 60 * 1000 ; // 30 minutes in milliseconds
6666 private readonly BASE_URL = "https://api.github.com" ;
67+ private readonly DISCUSSIONS_UNAVAILABLE_MESSAGE =
68+ "GitHub Discussions are disabled until a server-side GitHub proxy is configured." ;
6769
6870 // === ADDED: include anonymous contributors configurable (default false)
6971 private includeAnonymousContributors = false ;
@@ -76,6 +78,10 @@ class GitHubService {
7678 } ;
7779 }
7880
81+ private canUseGitHubGraphQL ( ) : boolean {
82+ return typeof window === "undefined" ;
83+ }
84+
7985 // === ADDED: setter to toggle anonymous contributors inclusion
8086 setIncludeAnonymousContributors ( value : boolean ) {
8187 this . includeAnonymousContributors = value ;
@@ -267,16 +273,16 @@ class GitHubService {
267273 return totalContributors ;
268274 }
269275
270- // === UPDATED: Get discussions count for a specific repository (default: "Support")
271- // Reason: previous code used an org-wide issues search which returned issues, not discussions.
272- // This function uses GraphQL to read repository.discussions.totalCount (repo-specific).
273- // If you need org-wide discussions count, we should iterate all repos and sum totalCount (heavier).
276+ // GitHub GraphQL requires authentication, so the browser should not call it directly.
274277 private async getDiscussionsCount (
275278 signal ?: AbortSignal ,
276279 repoName : string = "Support" ,
277280 ) : Promise < number > {
281+ if ( ! this . canUseGitHubGraphQL ( ) ) {
282+ return 0 ;
283+ }
284+
278285 try {
279- // GraphQL query to get discussions totalCount for a repository
280286 const query = `
281287 query ($owner: String!, $name: String!) {
282288 repository(owner: $owner, name: $name) {
@@ -343,11 +349,10 @@ class GitHubService {
343349 0 ,
344350 ) ;
345351
346- // Estimate contributors and get discussions count
347- // === UPDATED: getDiscussionsCount now uses GraphQL for a specific repo (default 'Support')
352+ // Estimate contributors and fetch discussion stats when a server-side context is available.
348353 const [ totalContributors , discussionsCount ] = await Promise . all ( [
349354 this . estimateContributors ( activeRepos , signal ) ,
350- this . getDiscussionsCount ( signal ) , // default repoName: "Support" (change if you prefer another repo)
355+ this . getDiscussionsCount ( signal ) ,
351356 ] ) ;
352357
353358 const stats : GitHubOrgStats = {
@@ -402,11 +407,14 @@ class GitHubService {
402407 return { cached : true , age, expiresIn } ;
403408 }
404409
405- // Fetch GitHub Discussions using GraphQL API (existing method kept intact)
406410 async fetchDiscussions (
407411 limit : number = 20 ,
408412 signal ?: AbortSignal ,
409413 ) : Promise < GitHubDiscussion [ ] > {
414+ if ( ! this . canUseGitHubGraphQL ( ) ) {
415+ throw new Error ( this . DISCUSSIONS_UNAVAILABLE_MESSAGE ) ;
416+ }
417+
410418 const query = `
411419 query GetDiscussions($owner: String!, $name: String!, $first: Int!) {
412420 repository(owner: $owner, name: $name) {
@@ -505,9 +513,7 @@ class GitHubService {
505513 ) ;
506514 } catch ( error ) {
507515 console . error ( "Error fetching discussions:" , error ) ;
508-
509- // Return mock data for development/fallback
510- return this . getMockDiscussions ( ) ;
516+ throw error ;
511517 }
512518 }
513519
0 commit comments