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 ;
1010const 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 ( ) ;
0 commit comments