Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 4 additions & 7 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ const config: Config = {

markdown: {
mermaid: true,
hooks: {
onBrokenMarkdownLinks: "warn",
},
},
Comment on lines 265 to 270
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new markdown.hooks.onBrokenMarkdownLinks config is likely not a recognized Docusaurus option (Docusaurus 3.x supports onBrokenMarkdownLinks as a top-level config). As written, this may be ignored and broken markdown links will use the default behavior instead of warn. Consider moving this to onBrokenMarkdownLinks: "warn" at the top level and removing the markdown.hooks nesting.

Copilot uses AI. Check for mistakes.

// Migrated legacy setting to markdown.hooks.onBrokenMarkdownLinks
Expand All @@ -267,18 +270,12 @@ const config: Config = {
],
],

// ✅ Add this customFields object to expose the token to the client-side
customFields: {
gitToken: process.env.DOCUSAURUS_GIT_TOKEN,
// Shopify credentials for merch store
SHOPIFY_STORE_DOMAIN:
process.env.SHOPIFY_STORE_DOMAIN || "junh9v-gw.myshopify.com",
SHOPIFY_STOREFRONT_ACCESS_TOKEN:
process.env.SHOPIFY_STOREFRONT_ACCESS_TOKEN ||
"2503dfbf93132b42e627e7d53b3ba3e9",
hooks: {
onBrokenMarkdownLinks: "warn",
},
process.env.SHOPIFY_STOREFRONT_ACCESS_TOKEN,
},
};

Expand Down
17 changes: 1 addition & 16 deletions src/lib/statsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import React, {
type ReactNode,
} from "react";
import { githubService, type GitHubOrgStats } from "../services/githubService";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";

// Time filter types
export type TimeFilter = "week" | "month" | "year" | "all";
Expand Down Expand Up @@ -160,11 +159,6 @@ const isPRInTimeRange = (mergedAt: string, filter: TimeFilter): boolean => {
export function CommunityStatsProvider({
children,
}: CommunityStatsProviderProps) {
const {
siteConfig: { customFields },
} = useDocusaurusContext();
const token = customFields?.gitToken || "";

const [loading, setLoading] = useState(false); // Start with false to avoid hourglass
const [error, setError] = useState<string | null>(null);
const [githubStarCount, setGithubStarCount] = useState(984); // Placeholder value - updated to match production
Expand Down Expand Up @@ -433,17 +427,8 @@ export function CommunityStatsProvider({

setError(null);

if (!token) {
setError(
"GitHub token not found. Please set customFields.gitToken in docusaurus.config.js.",
);
setLoading(false);
return;
}

try {
const headers: Record<string, string> = {
Authorization: `token ${token}`,
Accept: "application/vnd.github.v3+json",
};

Expand Down Expand Up @@ -497,7 +482,7 @@ export function CommunityStatsProvider({
setLoading(false);
}
},
[token, fetchAllOrgRepos, processBatch, cache],
[fetchAllOrgRepos, processBatch, cache],
);

const clearCache = useCallback(() => {
Expand Down
1 change: 1 addition & 0 deletions src/pages/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const DashboardContent: React.FC = () => {
setDiscussions(discussionsData);
} catch (error) {
console.error("Failed to fetch discussions:", error);
setDiscussions([]);
setDiscussionsError(
error instanceof Error ? error.message : "Failed to load discussions",
);
Expand Down
38 changes: 18 additions & 20 deletions src/services/githubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,22 @@ class GitHubService {
private readonly CACHE_KEY = "github_org_stats";
private readonly CACHE_DURATION = 30 * 60 * 1000; // 30 minutes in milliseconds
private readonly BASE_URL = "https://api.github.com";
private readonly DISCUSSIONS_UNAVAILABLE_MESSAGE =
"GitHub Discussions are disabled until a server-side GitHub proxy is configured.";
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message is thrown both when running in the browser (GraphQL disabled) and when no server-side token is configured. The current wording implies a proxy is required, but the code also supports direct server-side calls via process.env.GITHUB_TOKEN; consider updating the message to reflect the actual requirements (e.g., “available only server-side; configure GITHUB_TOKEN or a proxy”).

Suggested change
"GitHub Discussions are disabled until a server-side GitHub proxy is configured.";
"GitHub Discussions are available only server-side; configure GITHUB_TOKEN or a server-side GitHub proxy.";

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Abhash-Chakraborty , I had a quick question for you . is this gonna work around the discussions also , ATM the discussion in prod are working fine .


// === ADDED: include anonymous contributors configurable (default false)
private includeAnonymousContributors = false;

// Get headers for GitHub API requests
private getHeaders(): Record<string, string> {
const headers: Record<string, string> = {
return {
Accept: "application/vnd.github.v3+json",
"Content-Type": "application/json",
};
}
Comment on lines 47 to 53
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getHeaders() change removes Authorization, but this service makes requests to https://api.github.com/graphql (e.g., discussions count / discussions list). GitHub’s GraphQL API requires authentication, so these calls will now consistently fail (401) and the code will fall back to 0 discussions / mock discussions. Consider moving GraphQL calls behind a server-side endpoint (preferred), or switch to unauthenticated REST endpoints, or gate/disable these GraphQL features when no server-side auth is available.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Abhash-Chakraborty look into this


// Add GitHub token if available in environment
// Note: In production, you might want to use a server-side proxy to avoid exposing tokens
if (typeof window !== "undefined" && (window as any).GITHUB_TOKEN) {
headers["Authorization"] = `token ${(window as any).GITHUB_TOKEN}`;
}

return headers;
private canUseGitHubGraphQL(): boolean {
return typeof window === "undefined";
}

// === ADDED: setter to toggle anonymous contributors inclusion
Expand Down Expand Up @@ -275,16 +273,16 @@ class GitHubService {
return totalContributors;
}

// === UPDATED: Get discussions count for a specific repository (default: "Support")
// Reason: previous code used an org-wide issues search which returned issues, not discussions.
// This function uses GraphQL to read repository.discussions.totalCount (repo-specific).
// If you need org-wide discussions count, we should iterate all repos and sum totalCount (heavier).
// GitHub GraphQL requires authentication, so the browser should not call it directly.
private async getDiscussionsCount(
signal?: AbortSignal,
repoName: string = "Support",
): Promise<number> {
if (!this.canUseGitHubGraphQL()) {
return 0;
}
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDiscussionsCount() returns 0 when GraphQL is unavailable in the browser. That makes downstream UI/reporting treat the value as a real count ("0 discussions") rather than "unavailable", which is misleading. Consider representing this as null/undefined (and updating GitHubOrgStats + UI), or surfacing an explicit "unavailable" flag/message instead of overloading 0.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Abhash-Chakraborty this can be doable


try {
// GraphQL query to get discussions totalCount for a repository
const query = `
query ($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
Expand Down Expand Up @@ -351,11 +349,10 @@ class GitHubService {
0,
);

// Estimate contributors and get discussions count
// === UPDATED: getDiscussionsCount now uses GraphQL for a specific repo (default 'Support')
// Estimate contributors and fetch discussion stats when a server-side context is available.
const [totalContributors, discussionsCount] = await Promise.all([
this.estimateContributors(activeRepos, signal),
this.getDiscussionsCount(signal), // default repoName: "Support" (change if you prefer another repo)
this.getDiscussionsCount(signal),
]);

const stats: GitHubOrgStats = {
Expand Down Expand Up @@ -410,11 +407,14 @@ class GitHubService {
return { cached: true, age, expiresIn };
}

// Fetch GitHub Discussions using GraphQL API (existing method kept intact)
async fetchDiscussions(
limit: number = 20,
signal?: AbortSignal,
): Promise<GitHubDiscussion[]> {
if (!this.canUseGitHubGraphQL()) {
throw new Error(this.DISCUSSIONS_UNAVAILABLE_MESSAGE);
}

Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even when canUseGitHubGraphQL() is true, fetchDiscussions() still calls https://api.github.com/graphql directly without any auth header. If/when this is invoked in a server-side context, it will still fail with 401 unless you route through an authenticated proxy or add server-side auth (e.g., from env). Consider failing fast with a clear configuration error when no server-side token/proxy is available, rather than attempting the call.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const query = `
query GetDiscussions($owner: String!, $name: String!, $first: Int!) {
repository(owner: $owner, name: $name) {
Expand Down Expand Up @@ -513,9 +513,7 @@ class GitHubService {
);
} catch (error) {
console.error("Error fetching discussions:", error);

// Return mock data for development/fallback
return this.getMockDiscussions();
throw error;
}
}

Expand Down
25 changes: 7 additions & 18 deletions wiki/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,13 @@ const isPRInTimeRange = (mergedAt: string, filter: TimeFilter): boolean => {
const prDate = new Date(mergedAt);
return prDate >= filterDate;
};
```

Computed Contributors
This is where React's useMemo shines:
typescriptconst contributors = useMemo(() => {

```typescript
const contributors = useMemo(() => {
if (!allContributors.length) return [];

const filteredContributors = allContributors
Expand Down Expand Up @@ -573,7 +577,7 @@ Response Example:
}
```
#### Authentication
All requests require a GitHub Personal Access Token:
Authenticated requests should be made from a server-side endpoint or serverless function so the token is never shipped to the browser:
```typescript
const headers: Record<string, string> = {
Authorization: `token ${YOUR_GITHUB_TOKEN}`,
Expand All @@ -588,22 +592,7 @@ Select scopes: public_repo, read:org
Copy the token (you won't see it again!)
Comment on lines 592 to 595
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “Select scopes” guidance here omits read:discussion, but .env.example now recommends public_repo, read:org, read:discussion for the token used by /api/github-discussions. Please align these docs so users generate a token with the scopes actually required for the GraphQL discussions query.

Copilot uses AI. Check for mistakes.

#### Storing the Token:
In Docusaurus, we store it in docusaurus.config.js:
```javascript
module.exports = {
customFields: {
gitToken: process.env.GITHUB_TOKEN || '',
},
// ...
};
```
Then access it:
```typescript
const {
siteConfig: { customFields },
} = useDocusaurusContext();
const token = customFields?.gitToken || "";
```
Do not store a GitHub token in `docusaurus.config.js` or any other client-bundled config. Keep it in server-side environment variables and call GitHub from a backend endpoint instead.
Comment thread
sanjay-kv marked this conversation as resolved.
Outdated
#### Error Handling
**Rate Limit Exceeded (403)**

Expand Down
Loading