Skip to content

Commit 695840d

Browse files
authored
Merge pull request #153 from vedansh-5/loadBug
Scrum report is now being generated when the extension is freshly unpacked.
2 parents 181be30 + 1080353 commit 695840d

File tree

3 files changed

+84
-62
lines changed

3 files changed

+84
-62
lines changed

src/scripts/main.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function handleBodyOnLoad() {
1919
'startingDate',
2020
'endingDate',
2121
'showOpenLabel',
22-
'showClosedLabel',
2322
'userReason',
2423
'lastWeekContribution',
2524
'yesterdayContribution',
@@ -99,7 +98,7 @@ document.getElementById('refreshCache').addEventListener('click', async (e) => {
9998

10099
Materialize.toast({ html: 'Data refreshed successfully!', classes: 'green' });
101100
} catch (err) {
102-
console.error('Refresh failed:', err);
101+
console.log('Refresh successful',);
103102
} finally {
104103
setTimeout(() => {
105104
button.classList.remove('loading');

src/scripts/popup.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,8 @@ document.addEventListener('DOMContentLoaded', function () {
369369
console.log('[Org Check] Response status for', org, ':', res.status);
370370
if (res.status === 404) {
371371
console.log('[Org Check] Organization not found on GitHub:', org);
372-
// Remove any existing toast with the same id
373372
const oldToast = document.getElementById('invalid-org-toast');
374373
if (oldToast) oldToast.parentNode.removeChild(oldToast);
375-
// Create a new toast div
376374
const toastDiv = document.createElement('div');
377375
toastDiv.id = 'invalid-org-toast';
378376
toastDiv.className = 'toast';
@@ -391,24 +389,20 @@ document.addEventListener('DOMContentLoaded', function () {
391389
setTimeout(() => {
392390
if (toastDiv.parentNode) toastDiv.parentNode.removeChild(toastDiv);
393391
}, 3000);
394-
// Do NOT update storage or fetch data for invalid org
395392
return;
396393
}
397-
// Remove any existing toast with the same id (for valid orgs)
398394
const oldToast = document.getElementById('invalid-org-toast');
399395
if (oldToast) oldToast.parentNode.removeChild(oldToast);
396+
console.log('[Org Check] Organisation exists on GitHub:', org);
400397
console.log('[Org Check] Organization exists on GitHub:', org);
401-
// Valid org: update storage and fetch data
402398
chrome.storage.local.set({ orgName: org }, function () {
403399
if (window.generateScrumReport) window.generateScrumReport();
404400
});
405401
})
406402
.catch((err) => {
407-
console.log('[Org Check] Error validating organization:', org, err);
408-
// Remove any existing toast with the same id
403+
console.log('[Org Check] Error validating organisation:', org, err);
409404
const oldToast = document.getElementById('invalid-org-toast');
410405
if (oldToast) oldToast.parentNode.removeChild(oldToast);
411-
// Create a new toast div
412406
const toastDiv = document.createElement('div');
413407
toastDiv.id = 'invalid-org-toast';
414408
toastDiv.className = 'toast';
@@ -427,7 +421,6 @@ document.addEventListener('DOMContentLoaded', function () {
427421
setTimeout(() => {
428422
if (toastDiv.parentNode) toastDiv.parentNode.removeChild(toastDiv);
429423
}, 3000);
430-
// Do NOT update storage or fetch data for invalid org
431424
});
432425
}, 3000);
433426

@@ -575,7 +568,7 @@ function toggleRadio(radio) {
575568
});
576569
}
577570

578-
const cacheInput = document.getElementById('cacheInput');
571+
let cacheInput = document.getElementById('cacheInput');
579572
if (cacheInput) {
580573
chrome.storage.local.get(['cacheInput'], function (result) {
581574
if (result.cacheInput) {

src/scripts/scrumHelper.js

Lines changed: 80 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ console.log('Script loaded, adapter exists:', !!window.emailClientAdapter);
22
let refreshButton_Placed = false;
33
let enableToggle = true;
44
let hasInjectedContent = false;
5+
let scrumGenerationInProgress = false;
56
let orgName = 'fossasia'; // default
67
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;
713
console.log('allIncluded called with outputTarget:', outputTarget);
814
console.log('Current window context:', window.location.href);
915
let scrumBody = null;
@@ -25,7 +31,6 @@ function allIncluded(outputTarget = 'email') {
2531
let issuesDataProcessed = false;
2632
let prsReviewDataProcessed = false;
2733
let showOpenLabel = true;
28-
let showClosedLabel = true;
2934
let userReason = '';
3035

3136
let pr_merged_button =
@@ -50,7 +55,6 @@ function allIncluded(outputTarget = 'email') {
5055
'startingDate',
5156
'endingDate',
5257
'showOpenLabel',
53-
'showClosedLabel',
5458
'lastWeekContribution',
5559
'yesterdayContribution',
5660
'userReason',
@@ -61,73 +65,82 @@ function allIncluded(outputTarget = 'email') {
6165
(items) => {
6266
console.log("Storage items received:", items);
6367

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+
7294
if (!items.enableToggle) {
7395
enableToggle = items.enableToggle;
7496
}
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 = '';
77103
}
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) {
79109
startingDate = items.startingDate;
80-
}
81-
if (items.endingDate && !yesterdayContribution) {
82110
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+
}
83116
}
84-
if (items.startingDate && !yesterdayContribution) {
85-
startingDate = items.startingDate;
86-
}
87-
if (items.githubUsername) {
88-
githubUsername = items.githubUsername;
117+
118+
if (githubUsername) {
89119
console.log("About to fetch GitHub data for:", githubUsername);
90120
fetchGithubData();
91121
} else {
92122
if (outputTarget === 'popup') {
93123
console.log("No username found - popup context");
94124
// Show error in popup
125+
const scrumReport = document.getElementById('scrumReport');
95126
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+
}
96130
if (generateBtn) {
97131
generateBtn.innerHTML = '<i class="fa fa-refresh"></i> Generate Report';
98132
generateBtn.disabled = false;
99133
}
100-
Materialize.toast('Please enter your GitHub username', 3000);
134+
scrumGenerationInProgress = false;
101135
} else {
102-
console.log("No username found - email context");
103136
console.warn('No GitHub username found in storage');
137+
scrumGenerationInProgress = false;
104138
}
105-
}
106-
if (items.projectName) {
107-
projectName = items.projectName;
108-
}
109-
if (items.githubToken) {
110-
githubToken = items.githubToken;
139+
return;
111140
}
112141
if (items.cacheInput) {
113142
cacheInput = items.cacheInput;
114143
}
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-
}
131144
if (items.githubCache) {
132145
githubCache.data = items.githubCache.data;
133146
githubCache.cacheKey = items.githubCache.cacheKey;
@@ -193,8 +206,7 @@ function allIncluded(outputTarget = 'email') {
193206
return WeekDisplayPadded;
194207
}
195208

196-
197-
const DEBUG = true;
209+
const DEBUG = false;
198210
function log(...args) {
199211
if (DEBUG) {
200212
console.log(`[SCRUM-HELPER]:`, ...args);
@@ -413,11 +425,23 @@ function allIncluded(outputTarget = 'email') {
413425

414426
if (outputTarget === 'popup') {
415427
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+
}
416439
if (generateBtn) {
417440
generateBtn.innerHTML = '<i class="fa fa-refresh"></i> Generate Report';
418441
generateBtn.disabled = false;
419442
}
420443
}
444+
scrumGenerationInProgress = false;
421445
throw err;
422446
} finally {
423447
githubCache.fetching = false;
@@ -551,8 +575,10 @@ ${userReason}`;
551575
generateBtn.innerHTML = '<i class="fa fa-refresh"></i> Generate Report';
552576
generateBtn.disabled = false;
553577
}
578+
scrumGenerationInProgress = false;
554579
} else {
555580
logError('Scrum report div not found');
581+
scrumGenerationInProgress = false;
556582
}
557583
} else {
558584
const elements = window.emailClientAdapter.getEditorElements();
@@ -562,6 +588,7 @@ ${userReason}`;
562588
}
563589
window.emailClientAdapter.injectContent(elements.body, content, elements.eventTypes.contentChange);
564590
hasInjectedContent = true;
591+
scrumGenerationInProgress = false;
565592
}
566593
}, 500);
567594
}
@@ -844,11 +871,14 @@ ${userReason}`;
844871
}
845872
}
846873

847-
allIncluded('email');
874+
// allIncluded('email');
848875

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+
}
852882

853883
window.generateScrumReport = function () {
854884
allIncluded('popup');

0 commit comments

Comments
 (0)