@@ -3,6 +3,18 @@ let refreshButton_Placed = false;
3
3
let enableToggle = true ;
4
4
let hasInjectedContent = false ;
5
5
let orgName = 'fossasia' ; // default
6
+
7
+ // Global cache object
8
+ let githubCache = {
9
+ data : null ,
10
+ cacheKey : null ,
11
+ timestamp : null ,
12
+ ttl : null ,
13
+ fetching : false ,
14
+ queue : [ ] ,
15
+ subject : null
16
+ } ;
17
+
6
18
function allIncluded ( outputTarget = 'email' ) {
7
19
console . log ( 'allIncluded called with outputTarget:' , outputTarget ) ;
8
20
console . log ( 'Current window context:' , window . location . href ) ;
@@ -38,7 +50,71 @@ function allIncluded(outputTarget = 'email') {
38
50
let issue_opened_button =
39
51
'<div style="vertical-align:middle;display: inline-block;padding: 0px 4px;font-size:9px;font-weight: 600;color: #fff;text-align: center;background-color: #2cbe4e;border-radius: 3px;line-height: 12px;margin-bottom: 2px;" class="State State--green">open</div>' ;
40
52
41
- // let linkStyle = '';
53
+ /**
54
+ * Resets all report processing flags and state, then optionally regenerates the report
55
+ * @param {boolean } regenerateReport - Whether to regenerate the report after reset
56
+ * @param {string } outputTarget - The output target ('popup' or 'email')
57
+ */
58
+ function resetReportState ( regenerateReport = false , outputTarget = 'popup' ) {
59
+ log ( 'Resetting report state' ) ;
60
+
61
+ // Reset all processing flags
62
+ issuesDataProcessed = false ;
63
+ prsReviewDataProcessed = false ;
64
+ hasInjectedContent = false ;
65
+
66
+ // Reset data arrays
67
+ lastWeekArray = [ ] ;
68
+ nextWeekArray = [ ] ;
69
+ reviewedPrsArray = [ ] ;
70
+ githubPrsReviewDataProcessed = { } ;
71
+
72
+ // Clear cached data
73
+ githubCache . data = null ;
74
+ githubCache . cacheKey = null ;
75
+ githubCache . timestamp = null ;
76
+ githubCache . subject = null ;
77
+
78
+ log ( 'Report state reset complete' ) ;
79
+
80
+ // Regenerate report if requested
81
+ if ( regenerateReport ) {
82
+ log ( 'Regenerating report after reset' ) ;
83
+ if ( outputTarget === 'popup' ) {
84
+ writeGithubIssuesPrs ( ) ;
85
+ writeGithubPrsReviews ( ) ;
86
+ } else {
87
+ // For email context, trigger a fresh data fetch
88
+ fetchGithubData ( ) ;
89
+ }
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Forces a refresh of GitHub data by clearing cache and fetching new data
95
+ * @returns {Promise } Promise that resolves when refresh is complete
96
+ */
97
+ async function forceGithubDataRefresh ( ) {
98
+ log ( 'Force refreshing GitHub data' ) ;
99
+
100
+ // Clear cache from storage
101
+ await new Promise ( resolve => {
102
+ chrome . storage . local . remove ( 'githubCache' , resolve ) ;
103
+ } ) ;
104
+
105
+ // Reset report state
106
+ resetReportState ( false ) ;
107
+
108
+ // Fetch fresh data
109
+ try {
110
+ await fetchGithubData ( ) ;
111
+ return { success : true , message : 'Data refreshed successfully' } ;
112
+ } catch ( error ) {
113
+ logError ( 'Force refresh failed:' , error ) ;
114
+ return { success : false , error : error . message } ;
115
+ }
116
+ }
117
+
42
118
function getChromeData ( ) {
43
119
console . log ( "Getting Chrome data for context:" , outputTarget ) ;
44
120
chrome . storage . local . get (
@@ -205,18 +281,6 @@ function allIncluded(outputTarget = 'email') {
205
281
console . error ( '[SCRUM-HELPER]:' , ...args ) ;
206
282
}
207
283
}
208
- // Global cache object
209
- let githubCache = {
210
- data : null ,
211
- cacheKey : null ,
212
- timestamp : 0 ,
213
- ttl : 10 * 60 * 1000 , // cache valid for 10 mins
214
- fetching : false ,
215
- queue : [ ] ,
216
- errors : { } ,
217
- errorTTL : 60 * 1000 , // 1 min error cache
218
- subject : null ,
219
- } ;
220
284
221
285
async function getCacheTTL ( ) {
222
286
return new Promise ( ( resolve ) => {
@@ -400,12 +464,9 @@ function allIncluded(outputTarget = 'email') {
400
464
401
465
await saveToStorage ( githubCache . data ) ;
402
466
processGithubData ( githubCache . data ) ;
403
-
467
+
404
468
if ( outputTarget === 'popup' ) {
405
- issuesDataProcessed = false ;
406
- prsReviewDataProcessed = false ;
407
- writeGithubIssuesPrs ( ) ;
408
- writeGithubPrsReviews ( ) ;
469
+ resetReportState ( true , 'popup' ) ;
409
470
}
410
471
411
472
// Resolve queued calls
@@ -480,10 +541,8 @@ function allIncluded(outputTarget = 'email') {
480
541
user : githubUserData ?. login
481
542
} ) ;
482
543
483
- lastWeekArray = [ ] ;
484
- nextWeekArray = [ ] ;
485
- reviewedPrsArray = [ ] ;
486
- githubPrsReviewDataProcessed = { } ;
544
+ // Reset data arrays and processing state
545
+ resetReportState ( false ) ;
487
546
488
547
// Update subject
489
548
if ( ! githubCache . subject && scrumSubject ) {
@@ -619,8 +678,11 @@ ${userReason}`;
619
678
logError ( 'No Github PR review data available' ) ;
620
679
return ;
621
680
}
681
+
682
+ // Reset arrays for fresh processing
622
683
reviewedPrsArray = [ ] ;
623
684
githubPrsReviewDataProcessed = { } ;
685
+
624
686
let i ;
625
687
for ( i = 0 ; i < items . length ; i ++ ) {
626
688
let item = items [ i ] ;
@@ -707,8 +769,11 @@ ${userReason}`;
707
769
708
770
function writeGithubIssuesPrs ( ) {
709
771
let items = githubIssuesData . items ;
772
+
773
+ // Reset arrays for fresh processing
710
774
lastWeekArray = [ ] ;
711
775
nextWeekArray = [ ] ;
776
+
712
777
if ( ! items ) {
713
778
logError ( 'No Github issues data available' ) ;
714
779
return ;
@@ -846,7 +911,7 @@ ${userReason}`;
846
911
} , 1000 ) ;
847
912
}
848
913
function handleRefresh ( ) {
849
- hasInjectedContent = false ; // Reset the flag before refresh
914
+ resetReportState ( false , 'email' ) ;
850
915
allIncluded ( ) ;
851
916
}
852
917
}
0 commit comments