Skip to content

Commit 71de976

Browse files
committed
feat: update environment configuration for feedback repository and enhance GitHub API debugging with detailed logging
1 parent 7bc0474 commit 71de976

File tree

5 files changed

+76
-19
lines changed

5 files changed

+76
-19
lines changed

SortVision/.env.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
# Required scopes: public_repo (for public repositories)
44
VITE_GITHUB_TOKEN=your_github_personal_access_token_here
55

6-
# Repository Configuration
6+
# Main Repository Configuration (for stars, contributors, etc.)
77
VITE_GITHUB_REPO_OWNER=alienx5499
88
VITE_GITHUB_REPO_NAME=SortVision
99

10+
# Feedback Repository Configuration (for bug reports, suggestions)
11+
VITE_FEEDBACK_REPO_OWNER=hariOmArmy
12+
VITE_FEEDBACK_REPO_NAME=SortVision-FeedBack
13+
1014
# API Configuration
1115
VITE_API_BASE_URL=https://api.github.com
1216
VITE_API_USER_AGENT=SortVision-App

SortVision/src/components/feedback/githubService.js

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* Handles creating issues in the GitHub repository
44
*/
55

6-
const GITHUB_API_BASE = import.meta.env.VITE_API_BASE_URL || 'https://api.github.com';
7-
const REPO_OWNER = import.meta.env.VITE_GITHUB_REPO_OWNER || 'alienx5499';
8-
const REPO_NAME = 'SortVision-FeedBack'; // Private feedback repository
9-
const USER_AGENT = import.meta.env.VITE_API_USER_AGENT || 'SortVision-App';
6+
const GITHUB_API_BASE = import.meta.env.VITE_API_BASE_URL;
7+
const REPO_OWNER = import.meta.env.VITE_FEEDBACK_REPO_OWNER;
8+
const REPO_NAME = import.meta.env.VITE_FEEDBACK_REPO_NAME;
9+
const USER_AGENT = import.meta.env.VITE_API_USER_AGENT;
1010
const DEV_MODE = import.meta.env.VITE_DEV_MODE === 'true';
11-
const ENABLE_API_LOGGING = import.meta.env.VITE_ENABLE_API_LOGGING === 'true';
11+
const ENABLE_API_LOGGING = import.meta.env.VITE_ENABLE_API_LOGGING === 'true' || DEV_MODE;
1212

1313
/**
1414
* Submit feedback by creating a GitHub issue
@@ -25,13 +25,27 @@ export const submitFeedback = async (feedbackData) => {
2525
const token = import.meta.env.VITE_GITHUB_TOKEN;
2626

2727
if (!token) {
28+
console.error('❌ GitHub token not found. Please set VITE_GITHUB_TOKEN in your environment variables.');
2829
throw new Error('GitHub token not found. Please set VITE_GITHUB_TOKEN in your environment variables.');
2930
}
3031

3132
if (!REPO_OWNER) {
33+
console.error('❌ Repository owner missing. Please set VITE_GITHUB_REPO_OWNER in your environment variables.');
3234
throw new Error('Repository owner missing. Please set VITE_GITHUB_REPO_OWNER in your environment variables.');
3335
}
3436

37+
// Debug logging for API access
38+
if (ENABLE_API_LOGGING) {
39+
console.log('🔍 GitHub API Debug Info:', {
40+
apiBase: GITHUB_API_BASE,
41+
repoOwner: REPO_OWNER,
42+
repoName: REPO_NAME,
43+
tokenPresent: !!token,
44+
tokenPrefix: token ? `${token.substring(0, 8)}...` : 'None',
45+
environment: DEV_MODE ? 'Development' : 'Production'
46+
});
47+
}
48+
3549
// Generate star rating display
3650
const getRatingDisplay = (rating) => {
3751
if (rating === 0) return '⭐ Not rated';
@@ -353,7 +367,18 @@ ${formatErrorHistory(feedbackData.errorHistory)}
353367
}
354368

355369
try {
356-
const response = await fetch(`${GITHUB_API_BASE}/repos/${REPO_OWNER}/${REPO_NAME}/issues`, {
370+
const apiUrl = `${GITHUB_API_BASE}/repos/${REPO_OWNER}/${REPO_NAME}/issues`;
371+
372+
if (ENABLE_API_LOGGING) {
373+
console.log('🚀 Making GitHub API request:', {
374+
url: apiUrl,
375+
method: 'POST',
376+
hasToken: !!token,
377+
tokenLength: token ? token.length : 0
378+
});
379+
}
380+
381+
const response = await fetch(apiUrl, {
357382
method: 'POST',
358383
headers: {
359384
'Authorization': `token ${token}`,
@@ -365,11 +390,34 @@ ${formatErrorHistory(feedbackData.errorHistory)}
365390
});
366391

367392
if (!response.ok) {
368-
const errorData = await response.json();
369-
if (ENABLE_API_LOGGING) {
370-
console.error('GitHub API Error Response:', errorData);
393+
console.error(`❌ GitHub API Error ${response.status}: ${response.statusText}`);
394+
395+
let errorData;
396+
try {
397+
errorData = await response.json();
398+
} catch (parseError) {
399+
errorData = { message: `HTTP ${response.status}: ${response.statusText}` };
400+
}
401+
402+
console.error('📋 Error Details:', {
403+
status: response.status,
404+
statusText: response.statusText,
405+
url: apiUrl,
406+
repoOwner: REPO_OWNER,
407+
repoName: REPO_NAME,
408+
errorData: errorData
409+
});
410+
411+
// Specific error messages for common issues
412+
if (response.status === 404) {
413+
throw new Error(`Repository '${REPO_OWNER}/${REPO_NAME}' not found or token lacks access. Verify: 1) Repository exists 2) Token has 'repo' scope 3) Token has access to private repos`);
414+
} else if (response.status === 401) {
415+
throw new Error('GitHub token is invalid or expired. Please check your VITE_GITHUB_TOKEN.');
416+
} else if (response.status === 403) {
417+
throw new Error('GitHub token lacks required permissions. Ensure token has "repo" and "issues" scopes.');
371418
}
372-
throw new Error(`GitHub API Error: ${errorData.message || 'Failed to create issue'}`);
419+
420+
throw new Error(`GitHub API Error (${response.status}): ${errorData.message || response.statusText}`);
373421
}
374422

375423
const result = await response.json();

SortVision/src/components/panels/ContributionPanel.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ const ContributionPanel = ({ activeTab = 'overview', onTabChange }) => {
3636
// Function to fetch contributors data
3737
// Get configuration from environment variables
3838
const GITHUB_TOKEN = import.meta.env.VITE_GITHUB_TOKEN;
39-
const REPO_OWNER = import.meta.env.VITE_GITHUB_REPO_OWNER || 'alienx5499';
40-
const REPO_NAME = import.meta.env.VITE_GITHUB_REPO_NAME || 'SortVision';
41-
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'https://api.github.com';
42-
const USER_AGENT = import.meta.env.VITE_API_USER_AGENT || 'SortVision-Contribution-Panel';
39+
const REPO_OWNER = import.meta.env.VITE_GITHUB_REPO_OWNER;
40+
const REPO_NAME = import.meta.env.VITE_GITHUB_REPO_NAME;
41+
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
42+
const USER_AGENT = import.meta.env.VITE_API_USER_AGENT;
4343

4444
// Create authenticated fetch function
4545
const authenticatedFetch = useCallback(async (url) => {

SortVision/src/components/panels/contributions/overview/RepositoryHealth.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ const RepositoryHealth = () => {
2727
});
2828

2929
// Get configuration from environment variables
30-
const REPO_OWNER = import.meta.env.VITE_GITHUB_REPO_OWNER || 'alienx5499';
31-
const REPO_NAME = import.meta.env.VITE_GITHUB_REPO_NAME || 'SortVision';
30+
const REPO_OWNER = import.meta.env.VITE_GITHUB_REPO_OWNER;
31+
const REPO_NAME = import.meta.env.VITE_GITHUB_REPO_NAME;
3232
const GITHUB_TOKEN = import.meta.env.VITE_GITHUB_TOKEN;
33-
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'https://api.github.com';
34-
const USER_AGENT = import.meta.env.VITE_API_USER_AGENT || 'SortVision-App';
33+
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
34+
const USER_AGENT = import.meta.env.VITE_API_USER_AGENT;
3535

3636
// Create authenticated fetch function for direct GitHub API calls
3737
const authenticatedFetch = useCallback(async (githubUrl) => {

SortVision/src/main.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const SpeedInsights = lazy(() =>
1717
})
1818
);
1919

20+
// GitHub API debugging enabled in development mode
21+
if (import.meta.env.DEV) {
22+
console.log('🔧 GitHub API debugging enabled. Check console for detailed feedback submission logs.');
23+
}
24+
2025
const Analytics = lazy(() =>
2126
import('@vercel/analytics/react')
2227
.then(module => ({ default: module.Analytics }))

0 commit comments

Comments
 (0)