@@ -2,8 +2,13 @@ console.log('Script loaded, adapter exists:', !!window.emailClientAdapter);
2
2
let refreshButton_Placed = false ;
3
3
let enableToggle = true ;
4
4
let hasInjectedContent = false ;
5
+ let scrumGenerationInProgress = false ;
5
6
let orgName = 'fossasia' ; // default
6
7
function allIncluded ( outputTarget = 'email' ) {
8
+ if ( scrumGenerationInProgress ) {
9
+ console . warn ( '[SCRUM-HELPER]: Scrum generation already in progress, aborting new call.' ) ;
10
+ return ;
11
+ }
7
12
console . log ( 'allIncluded called with outputTarget:' , outputTarget ) ;
8
13
console . log ( 'Current window context:' , window . location . href ) ;
9
14
let scrumBody = null ;
@@ -25,9 +30,8 @@ function allIncluded(outputTarget = 'email') {
25
30
let issuesDataProcessed = false ;
26
31
let prsReviewDataProcessed = false ;
27
32
let showOpenLabel = true ;
28
- let showClosedLabel = true ;
29
33
let showCommits = false ;
30
- let numCommits = 5 ; //default
34
+ let numCommits = 5 ; //default
31
35
let userReason = '' ;
32
36
33
37
let pr_merged_button =
@@ -57,98 +61,108 @@ function allIncluded(outputTarget = 'email') {
57
61
'yesterdayContribution' ,
58
62
'userReason' ,
59
63
'showCommits' ,
60
- 'numCommits' ,
64
+ 'numCommits' ,
61
65
'githubCache' ,
62
66
'cacheInput' ,
63
67
'orgName'
64
68
] ,
65
69
( items ) => {
66
70
console . log ( "Storage items received:" , items ) ;
67
-
68
- if ( items . lastWeekContribution ) {
69
- lastWeekContribution = true ;
70
- handleLastWeekContributionChange ( ) ;
71
- }
72
- if ( items . yesterdayContribution ) {
73
- yesterdayContribution = true ;
74
- handleYesterdayContributionChange ( ) ;
71
+
72
+
73
+ if ( outputTarget === 'popup' ) {
74
+ const usernameFromDOM = document . getElementById ( 'githubUsername' ) ?. value ;
75
+ const projectFromDOM = document . getElementById ( 'projectName' ) ?. value ;
76
+ const reasonFromDOM = document . getElementById ( 'userReason' ) ?. value ;
77
+ const tokenFromDOM = document . getElementById ( 'githubToken' ) ?. value ;
78
+
79
+ items . githubUsername = usernameFromDOM || items . githubUsername ;
80
+ items . projectName = projectFromDOM || items . projectName ;
81
+ items . userReason = reasonFromDOM || items . userReason ;
82
+ items . githubToken = tokenFromDOM || items . githubToken ;
83
+
84
+ chrome . storage . local . set ( {
85
+ githubUsername : items . githubUsername ,
86
+ projectName : items . projectName ,
87
+ userReason : items . userReason ,
88
+ githubToken : items . githubToken
89
+ } ) ;
75
90
}
91
+
92
+ githubUsername = items . githubUsername ;
93
+ projectName = items . projectName ;
94
+ userReason = items . userReason || 'No Blocker at the moment' ;
95
+ githubToken = items . githubToken ;
96
+ lastWeekContribution = items . lastWeekContribution ;
97
+ yesterdayContribution = items . yesterdayContribution ;
98
+
76
99
if ( ! items . enableToggle ) {
77
- enableToggle = items . enableToggle ;
78
- }
79
- if ( items . endingDate && ! lastWeekContribution ) {
80
- endingDate = items . endingDate ;
81
- }
82
- if ( items . startingDate && ! lastWeekContribution ) {
83
- startingDate = items . startingDate ;
84
- }
85
- if ( items . endingDate && ! yesterdayContribution ) {
86
- endingDate = items . endingDate ;
87
- }
88
- if ( items . startingDate && ! yesterdayContribution ) {
89
- startingDate = items . startingDate ;
90
- }
91
- if ( items . githubUsername ) {
92
- githubUsername = items . githubUsername ;
93
- console . log ( "About to fetch GitHub data for:" , githubUsername ) ;
94
- fetchGithubData ( ) ;
95
- } else {
96
- if ( outputTarget === 'popup' ) {
97
- console . log ( "No username found - popup context" ) ;
98
- // Show error in popup
99
- const generateBtn = document . getElementById ( 'generateReport' ) ;
100
- if ( generateBtn ) {
101
- generateBtn . innerHTML = '<i class="fa fa-refresh"></i> Generate Report' ;
102
- generateBtn . disabled = false ;
103
- }
104
- Materialize . toast ( 'Please enter your GitHub username' , 3000 ) ;
105
- } else {
106
- console . log ( "No username found - email context" ) ;
107
- console . warn ( 'No GitHub username found in storage' ) ;
108
- }
109
- }
110
- if ( items . projectName ) {
111
- projectName = items . projectName ;
112
- }
113
- if ( items . githubToken ) {
114
- githubToken = items . githubToken ;
115
- }
100
+ enableToggle = items . enableToggle ;
101
+ }
102
+ if ( ! items . showOpenLabel ) {
103
+ showOpenLabel = false ;
104
+ pr_unmerged_button = '' ;
105
+ issue_opened_button = '' ;
106
+ pr_merged_button = '' ;
107
+ issue_closed_button = '' ;
108
+ }
109
+ if ( items . lastWeekContribution ) {
110
+ handleLastWeekContributionChange ( ) ;
111
+ } else if ( items . yesterdayContribution ) {
112
+ handleYesterdayContributionChange ( ) ;
113
+ } else if ( items . startDate && items . endingDate ) {
114
+ startingDate = items . startingDate ;
115
+ endingDate = items . endingDate ;
116
+ } else {
117
+ handleLastWeekContributionChange ( ) ; //when no date is stored, i.e on fresh unpack - default to last week.
118
+ if ( outputTarget === 'popup' ) {
119
+ chrome . storage . local . set ( { lastWeekContribution : true , yesterdayContribution : false } ) ;
120
+ }
121
+ }
122
+ if ( githubUsername ) {
123
+ console . log ( "About to fetch GitHub data for:" , githubUsername ) ;
124
+ fetchGithubData ( ) ;
125
+ } else {
126
+ if ( outputTarget === 'popup' ) {
127
+ console . log ( "No username found - popup context" ) ;
128
+ // Show error in popup
129
+ const scrumReport = document . getElementById ( 'scrumReport' ) ;
130
+ const generateBtn = document . getElementById ( 'generateReport' ) ;
131
+ if ( scrumReport ) {
132
+ scrumReport . innerHTML = '<div class="error-message" style="color: #dc2626; font-weight: bold; padding: 10px;">Please enter your GitHub username to generate a report.</div>' ;
133
+ }
134
+ if ( generateBtn ) {
135
+ generateBtn . innerHTML = '<i class="fa fa-refresh"></i> Generate Report' ;
136
+ generateBtn . disabled = false ;
137
+ }
138
+ scrumGenerationInProgress = false ;
139
+ } else {
140
+ console . warn ( 'No GitHub username found in storage' ) ;
141
+ scrumGenerationInProgress = false ;
142
+ }
143
+ return ;
144
+ }
116
145
if ( items . cacheInput ) {
117
146
cacheInput = items . cacheInput ;
118
147
}
119
- if ( ! items . showOpenLabel ) {
120
- showOpenLabel = false ;
121
- pr_unmerged_button = '' ;
122
- issue_opened_button = '' ;
123
- }
124
- if ( ! items . showClosedLabel ) {
125
- showClosedLabel = false ;
126
- pr_merged_button = '' ;
127
- issue_closed_button = '' ;
128
- }
148
+
129
149
if ( items . showCommits !== undefined ) {
130
150
showCommits = items . showCommits ;
131
151
} else {
132
152
showCommits = false ; // Default value
133
153
}
134
- if ( items . userReason ) {
135
- userReason = items . userReason ;
136
- }
137
- if ( ! items . userReason ) {
138
- userReason = 'No Blocker at the moment' ;
139
- }
140
- if ( items . githubCache ) {
141
- githubCache . data = items . githubCache . data ;
142
- githubCache . cacheKey = items . githubCache . cacheKey ;
143
- githubCache . timestamp = items . githubCache . timestamp ;
144
- log ( 'Restored cache from storage' ) ;
145
- }
154
+ if ( items . githubCache ) {
155
+ githubCache . data = items . githubCache . data ;
156
+ githubCache . cacheKey = items . githubCache . cacheKey ;
157
+ githubCache . timestamp = items . githubCache . timestamp ;
158
+ log ( 'Restored cache from storage' ) ;
159
+ }
146
160
if ( items . orgName ) {
147
161
orgName = items . orgName ;
148
162
}
149
- if ( items . numCommits ) {
150
- numCommits = items . numCommits ;
151
- }
163
+ if ( items . numCommits ) {
164
+ numCommits = items . numCommits ;
165
+ }
152
166
} ,
153
167
) ;
154
168
}
@@ -442,22 +456,34 @@ function allIncluded(outputTarget = 'email') {
442
456
// Resolve queued calls
443
457
githubCache . queue . forEach ( ( { resolve } ) => resolve ( ) ) ;
444
458
githubCache . queue = [ ] ;
445
- } catch ( err ) {
446
- logError ( 'Fetch Failed:' , err ) ;
447
- // Reject queued calls on error
448
- githubCache . queue . forEach ( ( { reject } ) => reject ( err ) ) ;
449
- githubCache . queue = [ ] ;
450
- githubCache . fetching = false ;
459
+ } catch ( err ) {
460
+ logError ( 'Fetch Failed:' , err ) ;
461
+ // Reject queued calls on error
462
+ githubCache . queue . forEach ( ( { reject } ) => reject ( err ) ) ;
463
+ githubCache . queue = [ ] ;
464
+ githubCache . fetching = false ;
451
465
452
- if ( outputTarget === 'popup' ) {
453
- const generateBtn = document . getElementById ( 'generateReport' ) ;
454
- if ( generateBtn ) {
455
- generateBtn . innerHTML = '<i class="fa fa-refresh"></i> Generate Report' ;
456
- generateBtn . disabled = false ;
457
- }
458
- }
459
- throw err ;
460
- } finally {
466
+ if ( outputTarget === 'popup' ) {
467
+ const generateBtn = document . getElementById ( 'generateReport' ) ;
468
+ if ( scrumReport ) {
469
+ let errorMsg = 'An error occurred while generating the report.' ;
470
+ if ( err ) {
471
+ if ( typeof err === 'string' ) errorMsg = err ;
472
+ else if ( err . message ) errorMsg = err . message ;
473
+ else errorMsg = JSON . stringify ( err )
474
+ }
475
+ scrumReport . innerHTML = `<div class="error-message" style="color: #dc2626; font-weight: bold; padding: 10px;">${ err . message || 'An error occurred while generating the report.' } </div>` ;
476
+ generateBtn . innerHTML = '<i class="fa fa-refresh"></i> Generate Report' ;
477
+ generateBtn . disabled = false ;
478
+ }
479
+ if ( generateBtn ) {
480
+ generateBtn . innerHTML = '<i class="fa fa-refresh"></i> Generate Report' ;
481
+ generateBtn . disabled = false ;
482
+ }
483
+ }
484
+ scrumGenerationInProgress = false ;
485
+ throw err ;
486
+ } finally {
461
487
githubCache . fetching = false ;
462
488
}
463
489
}
@@ -971,11 +997,15 @@ async function forceGithubDataRefresh() {
971
997
return { success : true } ;
972
998
}
973
999
974
- allIncluded ( 'email' ) ;
975
1000
976
- $ ( 'button>span:contains(New conversation)' ) . parent ( 'button' ) . click ( ( ) => {
977
- allIncluded ( ) ;
978
- } ) ;
1001
+ // allIncluded('email');
1002
+
1003
+ if ( window . location . protocol . startsWith ( 'http' ) ) {
1004
+ allIncluded ( 'email' ) ;
1005
+ $ ( 'button>span:contains(New conversation)' ) . parent ( 'button' ) . click ( ( ) => {
1006
+ allIncluded ( ) ;
1007
+ } ) ;
1008
+ }
979
1009
980
1010
window . generateScrumReport = function ( ) {
981
1011
allIncluded ( 'popup' ) ;
0 commit comments