@@ -2,8 +2,14 @@ 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
+ }
12
+ scrumGenerationInProgress = true ;
7
13
console . log ( 'allIncluded called with outputTarget:' , outputTarget ) ;
8
14
console . log ( 'Current window context:' , window . location . href ) ;
9
15
let scrumBody = null ;
@@ -25,7 +31,6 @@ function allIncluded(outputTarget = 'email') {
25
31
let issuesDataProcessed = false ;
26
32
let prsReviewDataProcessed = false ;
27
33
let showOpenLabel = true ;
28
- let showClosedLabel = true ;
29
34
let userReason = '' ;
30
35
31
36
let pr_merged_button =
@@ -50,7 +55,6 @@ function allIncluded(outputTarget = 'email') {
50
55
'startingDate' ,
51
56
'endingDate' ,
52
57
'showOpenLabel' ,
53
- 'showClosedLabel' ,
54
58
'lastWeekContribution' ,
55
59
'yesterdayContribution' ,
56
60
'userReason' ,
@@ -61,73 +65,82 @@ function allIncluded(outputTarget = 'email') {
61
65
( items ) => {
62
66
console . log ( "Storage items received:" , items ) ;
63
67
64
- if ( items . lastWeekContribution ) {
65
- lastWeekContribution = true ;
66
- handleLastWeekContributionChange ( ) ;
67
- }
68
- if ( items . yesterdayContribution ) {
69
- yesterdayContribution = true ;
70
- handleYesterdayContributionChange ( ) ;
71
- }
68
+ if ( outputTarget === 'popup' ) {
69
+ const usernameFromDOM = document . getElementById ( 'githubUsername' ) ?. value ;
70
+ const projectFromDOM = document . getElementById ( 'projectName' ) ?. value ;
71
+ const reasonFromDOM = document . getElementById ( 'userReason' ) ?. value ;
72
+ const tokenFromDOM = document . getElementById ( 'githubToken' ) ?. value ;
73
+
74
+ items . githubUsername = usernameFromDOM || items . githubUsername ;
75
+ items . projectName = projectFromDOM || items . projectName ;
76
+ items . userReason = reasonFromDOM || items . userReason ;
77
+ items . githubToken = tokenFromDOM || items . githubToken ;
78
+
79
+ chrome . storage . local . set ( {
80
+ githubUsername : items . githubUsername ,
81
+ projectName : items . projectName ,
82
+ userReason : items . userReason ,
83
+ githubToken : items . githubToken
84
+ } ) ;
85
+ }
86
+
87
+ githubUsername = items . githubUsername ;
88
+ projectName = items . projectName ;
89
+ userReason = items . userReason || 'No Blocker at the moment' ;
90
+ githubToken = items . githubToken ;
91
+ lastWeekContribution = items . lastWeekContribution ;
92
+ yesterdayContribution = items . yesterdayContribution ;
93
+
72
94
if ( ! items . enableToggle ) {
73
95
enableToggle = items . enableToggle ;
74
96
}
75
- if ( items . endingDate && ! lastWeekContribution ) {
76
- endingDate = items . endingDate ;
97
+ if ( ! items . showOpenLabel ) {
98
+ showOpenLabel = false ;
99
+ pr_unmerged_button = '' ;
100
+ issue_opened_button = '' ;
101
+ pr_merged_button = '' ;
102
+ issue_closed_button = '' ;
77
103
}
78
- if ( items . startingDate && ! lastWeekContribution ) {
104
+ if ( items . lastWeekContribution ) {
105
+ handleLastWeekContributionChange ( ) ;
106
+ } else if ( items . yesterdayContribution ) {
107
+ handleYesterdayContributionChange ( ) ;
108
+ } else if ( items . startDate && items . endingDate ) {
79
109
startingDate = items . startingDate ;
80
- }
81
- if ( items . endingDate && ! yesterdayContribution ) {
82
110
endingDate = items . endingDate ;
111
+ } else {
112
+ handleLastWeekContributionChange ( ) ; //when no date is stored, i.e on fresh unpack - default to last week.
113
+ if ( outputTarget === 'popup' ) {
114
+ chrome . storage . local . set ( { lastWeekContribution : true , yesterdayContribution : false } ) ;
115
+ }
83
116
}
84
- if ( items . startingDate && ! yesterdayContribution ) {
85
- startingDate = items . startingDate ;
86
- }
87
- if ( items . githubUsername ) {
88
- githubUsername = items . githubUsername ;
117
+
118
+ if ( githubUsername ) {
89
119
console . log ( "About to fetch GitHub data for:" , githubUsername ) ;
90
120
fetchGithubData ( ) ;
91
121
} else {
92
122
if ( outputTarget === 'popup' ) {
93
123
console . log ( "No username found - popup context" ) ;
94
124
// Show error in popup
125
+ const scrumReport = document . getElementById ( 'scrumReport' ) ;
95
126
const generateBtn = document . getElementById ( 'generateReport' ) ;
127
+ if ( scrumReport ) {
128
+ scrumReport . innerHTML = '<div class="error-message" style="color: #dc2626; font-weight: bold; padding: 10px;">Please enter your GitHub username to generate a report.</div>' ;
129
+ }
96
130
if ( generateBtn ) {
97
131
generateBtn . innerHTML = '<i class="fa fa-refresh"></i> Generate Report' ;
98
132
generateBtn . disabled = false ;
99
133
}
100
- Materialize . toast ( 'Please enter your GitHub username' , 3000 ) ;
134
+ scrumGenerationInProgress = false ;
101
135
} else {
102
- console . log ( "No username found - email context" ) ;
103
136
console . warn ( 'No GitHub username found in storage' ) ;
137
+ scrumGenerationInProgress = false ;
104
138
}
105
- }
106
- if ( items . projectName ) {
107
- projectName = items . projectName ;
108
- }
109
- if ( items . githubToken ) {
110
- githubToken = items . githubToken ;
139
+ return ;
111
140
}
112
141
if ( items . cacheInput ) {
113
142
cacheInput = items . cacheInput ;
114
143
}
115
- if ( ! items . showOpenLabel ) {
116
- showOpenLabel = false ;
117
- pr_unmerged_button = '' ;
118
- issue_opened_button = '' ;
119
- }
120
- if ( ! items . showClosedLabel ) {
121
- showClosedLabel = false ;
122
- pr_merged_button = '' ;
123
- issue_closed_button = '' ;
124
- }
125
- if ( items . userReason ) {
126
- userReason = items . userReason ;
127
- }
128
- if ( ! items . userReason ) {
129
- userReason = 'No Blocker at the moment' ;
130
- }
131
144
if ( items . githubCache ) {
132
145
githubCache . data = items . githubCache . data ;
133
146
githubCache . cacheKey = items . githubCache . cacheKey ;
@@ -193,8 +206,7 @@ function allIncluded(outputTarget = 'email') {
193
206
return WeekDisplayPadded ;
194
207
}
195
208
196
-
197
- const DEBUG = true ;
209
+ const DEBUG = false ;
198
210
function log ( ...args ) {
199
211
if ( DEBUG ) {
200
212
console . log ( `[SCRUM-HELPER]:` , ...args ) ;
@@ -413,11 +425,23 @@ function allIncluded(outputTarget = 'email') {
413
425
414
426
if ( outputTarget === 'popup' ) {
415
427
const generateBtn = document . getElementById ( 'generateReport' ) ;
428
+ if ( scrumReport ) {
429
+ let errorMsg = 'An error occurred while generating the report.' ;
430
+ if ( err ) {
431
+ if ( typeof err === 'string' ) errorMsg = err ;
432
+ else if ( err . message ) errorMsg = err . message ;
433
+ else errorMsg = JSON . stringify ( err )
434
+ }
435
+ scrumReport . innerHTML = `<div class="error-message" style="color: #dc2626; font-weight: bold; padding: 10px;">${ err . message || 'An error occurred while generating the report.' } </div>` ;
436
+ generateBtn . innerHTML = '<i class="fa fa-refresh"></i> Generate Report' ;
437
+ generateBtn . disabled = false ;
438
+ }
416
439
if ( generateBtn ) {
417
440
generateBtn . innerHTML = '<i class="fa fa-refresh"></i> Generate Report' ;
418
441
generateBtn . disabled = false ;
419
442
}
420
443
}
444
+ scrumGenerationInProgress = false ;
421
445
throw err ;
422
446
} finally {
423
447
githubCache . fetching = false ;
@@ -551,8 +575,10 @@ ${userReason}`;
551
575
generateBtn . innerHTML = '<i class="fa fa-refresh"></i> Generate Report' ;
552
576
generateBtn . disabled = false ;
553
577
}
578
+ scrumGenerationInProgress = false ;
554
579
} else {
555
580
logError ( 'Scrum report div not found' ) ;
581
+ scrumGenerationInProgress = false ;
556
582
}
557
583
} else {
558
584
const elements = window . emailClientAdapter . getEditorElements ( ) ;
@@ -562,6 +588,7 @@ ${userReason}`;
562
588
}
563
589
window . emailClientAdapter . injectContent ( elements . body , content , elements . eventTypes . contentChange ) ;
564
590
hasInjectedContent = true ;
591
+ scrumGenerationInProgress = false ;
565
592
}
566
593
} , 500 ) ;
567
594
}
@@ -844,11 +871,14 @@ ${userReason}`;
844
871
}
845
872
}
846
873
847
- allIncluded ( 'email' ) ;
874
+ // allIncluded('email');
848
875
849
- $ ( 'button>span:contains(New conversation)' ) . parent ( 'button' ) . click ( ( ) => {
850
- allIncluded ( ) ;
851
- } ) ;
876
+ if ( window . location . protocol . startsWith ( 'http' ) ) {
877
+ allIncluded ( 'email' ) ;
878
+ $ ( 'button>span:contains(New conversation)' ) . parent ( 'button' ) . click ( ( ) => {
879
+ allIncluded ( ) ;
880
+ } ) ;
881
+ }
852
882
853
883
window . generateScrumReport = function ( ) {
854
884
allIncluded ( 'popup' ) ;
0 commit comments