Skip to content

Commit 191ce7a

Browse files
authored
Merge branch 'master' into commits
2 parents 92cea91 + 695840d commit 191ce7a

File tree

3 files changed

+128
-106
lines changed

3 files changed

+128
-106
lines changed

src/scripts/main.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function handleBodyOnLoad() {
2121
'startingDate',
2222
'endingDate',
2323
'showOpenLabel',
24-
'showClosedLabel',
2524
'userReason',
2625
'lastWeekContribution',
2726
'yesterdayContribution',
@@ -112,7 +111,7 @@ document.getElementById('refreshCache').addEventListener('click', async (e) => {
112111

113112
Materialize.toast({ html: 'Data refreshed successfully!', classes: 'green' });
114113
} catch (err) {
115-
console.error('Refresh failed:', err);
114+
console.log('Refresh successful',);
116115
} finally {
117116
setTimeout(() => {
118117
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

@@ -573,7 +566,7 @@ function toggleRadio(radio) {
573566
});
574567
}
575568

576-
const cacheInput = document.getElementById('cacheInput');
569+
let cacheInput = document.getElementById('cacheInput');
577570
if (cacheInput) {
578571
chrome.storage.local.get(['cacheInput'], function (result) {
579572
if (result.cacheInput) {

src/scripts/scrumHelper.js

Lines changed: 124 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ 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+
}
712
console.log('allIncluded called with outputTarget:', outputTarget);
813
console.log('Current window context:', window.location.href);
914
let scrumBody = null;
@@ -25,9 +30,8 @@ function allIncluded(outputTarget = 'email') {
2530
let issuesDataProcessed = false;
2631
let prsReviewDataProcessed = false;
2732
let showOpenLabel = true;
28-
let showClosedLabel = true;
2933
let showCommits = false;
30-
let numCommits = 5; //default
34+
let numCommits = 5; //default
3135
let userReason = '';
3236

3337
let pr_merged_button =
@@ -57,98 +61,108 @@ function allIncluded(outputTarget = 'email') {
5761
'yesterdayContribution',
5862
'userReason',
5963
'showCommits',
60-
'numCommits',
64+
'numCommits',
6165
'githubCache',
6266
'cacheInput',
6367
'orgName'
6468
],
6569
(items) => {
6670
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+
});
7590
}
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+
7699
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+
}
116145
if (items.cacheInput) {
117146
cacheInput = items.cacheInput;
118147
}
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+
129149
if (items.showCommits !== undefined) {
130150
showCommits = items.showCommits;
131151
} else {
132152
showCommits = false; // Default value
133153
}
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+
}
146160
if (items.orgName) {
147161
orgName = items.orgName;
148162
}
149-
if(items.numCommits) {
150-
numCommits = items.numCommits;
151-
}
163+
if(items.numCommits) {
164+
numCommits = items.numCommits;
165+
}
152166
},
153167
);
154168
}
@@ -442,22 +456,34 @@ function allIncluded(outputTarget = 'email') {
442456
// Resolve queued calls
443457
githubCache.queue.forEach(({ resolve }) => resolve());
444458
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;
451465

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 {
461487
githubCache.fetching = false;
462488
}
463489
}
@@ -971,11 +997,15 @@ async function forceGithubDataRefresh() {
971997
return { success: true };
972998
}
973999

974-
allIncluded('email');
9751000

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

9801010
window.generateScrumReport = function () {
9811011
allIncluded('popup');

0 commit comments

Comments
 (0)