@@ -10,6 +10,7 @@ function allIncluded(outputTarget = 'email') {
10
10
let startingDate = '' ;
11
11
let endingDate = '' ;
12
12
let githubUsername = '' ;
13
+ let githubToken = '' ;
13
14
let projectName = '' ;
14
15
let lastWeekArray = [ ] ;
15
16
let nextWeekArray = [ ] ;
@@ -40,6 +41,7 @@ function allIncluded(outputTarget = 'email') {
40
41
chrome . storage . local . get (
41
42
[
42
43
'githubUsername' ,
44
+ 'githubToken' ,
43
45
'projectName' ,
44
46
'enableToggle' ,
45
47
'startingDate' ,
@@ -100,6 +102,9 @@ function allIncluded(outputTarget = 'email') {
100
102
if ( items . projectName ) {
101
103
projectName = items . projectName ;
102
104
}
105
+ if ( items . githubToken ) {
106
+ githubToken = items . githubToken ;
107
+ }
103
108
if ( items . cacheInput ) {
104
109
cacheInput = items . cacheInput ;
105
110
}
@@ -334,6 +339,18 @@ function allIncluded(outputTarget = 'email') {
334
339
githubCache . fetching = true ;
335
340
githubCache . cacheKey = cacheKey ;
336
341
342
+ const headers = {
343
+ 'Accept' : 'application/vnd.github.v3+json' ,
344
+ } ;
345
+
346
+ if ( githubToken ) {
347
+ log ( 'Making authenticated requests.' ) ;
348
+ headers [ 'Authorization' ] = `token ${ githubToken } ` ;
349
+
350
+ } else {
351
+ log ( 'Making public requests' ) ;
352
+ }
353
+
337
354
let issueUrl = `https://api.github.com/search/issues?q=author%3A${ githubUsername } +org%3Afossasia+created%3A${ startingDate } ..${ endingDate } &per_page=100` ;
338
355
let prUrl = `https://api.github.com/search/issues?q=commenter%3A${ githubUsername } +org%3Afossasia+updated%3A${ startingDate } ..${ endingDate } &per_page=100` ;
339
356
let userUrl = `https://api.github.com/users/${ githubUsername } ` ;
@@ -343,11 +360,17 @@ function allIncluded(outputTarget = 'email') {
343
360
await new Promise ( res => setTimeout ( res , 500 ) ) ;
344
361
345
362
const [ issuesRes , prRes , userRes ] = await Promise . all ( [
346
- fetch ( issueUrl ) ,
347
- fetch ( prUrl ) ,
348
- fetch ( userUrl ) ,
363
+ fetch ( issueUrl , { headers } ) ,
364
+ fetch ( prUrl , { headers } ) ,
365
+ fetch ( userUrl , { headers } ) ,
349
366
] ) ;
350
367
368
+ if ( issuesRes . status === 401 || prRes . status === 401 || userRes . status === 401 ||
369
+ issuesRes . status === 403 || prRes . status === 403 || userRes . status === 403 ) {
370
+ showInvalidTokenMessage ( ) ;
371
+ return ;
372
+ }
373
+
351
374
if ( ! issuesRes . ok ) throw new Error ( `Error fetching Github issues: ${ issuesRes . status } ${ issuesRes . statusText } ` ) ;
352
375
if ( ! prRes . ok ) throw new Error ( `Error fetching Github PR review data: ${ prRes . status } ${ prRes . statusText } ` ) ;
353
376
if ( ! userRes . ok ) throw new Error ( `Error fetching Github userdata: ${ userRes . status } ${ userRes . statusText } ` ) ;
@@ -372,6 +395,14 @@ function allIncluded(outputTarget = 'email') {
372
395
githubCache . queue . forEach ( ( { reject } ) => reject ( err ) ) ;
373
396
githubCache . queue = [ ] ;
374
397
githubCache . fetching = false ;
398
+
399
+ if ( outputTarget === 'popup' ) {
400
+ const generateBtn = document . getElementById ( 'generateReport' ) ;
401
+ if ( generateBtn ) {
402
+ generateBtn . innerHTML = '<i class="fa fa-refresh"></i> Generate Report' ;
403
+ generateBtn . disabled = false ;
404
+ }
405
+ }
375
406
throw err ;
376
407
} finally {
377
408
githubCache . fetching = false ;
@@ -399,7 +430,21 @@ function allIncluded(outputTarget = 'email') {
399
430
}
400
431
verifyCacheStatus ( ) ;
401
432
402
-
433
+ function showInvalidTokenMessage ( ) {
434
+ if ( outputTarget === 'popup' ) {
435
+ const reportDiv = document . getElementById ( 'scrumReport' ) ;
436
+ if ( reportDiv ) {
437
+ reportDiv . innerHTML = '<div class="error-message" style="color: #dc2626; font-weight: bold; padding: 10px;">Invalid or expired GitHub token. Please check your token in the settings and try again.</div>' ;
438
+ const generateBtn = document . getElementById ( 'generateReport' ) ;
439
+ if ( generateBtn ) {
440
+ generateBtn . innerHTML = '<i class="fa fa-refresh"></i> Generate Report' ;
441
+ generateBtn . disabled = false ;
442
+ }
443
+ } else {
444
+ alert ( 'Invalid or expired GitHub token. Please check your token in the extension popup and try again.' ) ;
445
+ }
446
+ }
447
+ }
403
448
404
449
function processGithubData ( data ) {
405
450
log ( 'Processing Github data' ) ;
0 commit comments