Skip to content

Commit 3226c3b

Browse files
committed
removed commits input, using date scope for displaying commits
Signed-off-by: Vedansh Saini <[email protected]>
1 parent 22f3c16 commit 3226c3b

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

src/popup.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ <h4>Your Github Token</h4>
176176
<div class="col s12 my-4 ">
177177
<div class="flex items-center gap-2">
178178
<input type="checkbox" id="showCommits" checked class="form-checkbox h-4 w-4 text-blue-600 ">
179-
<label id="showCommitsLabel" for="showCommits" class="text-gray-700 font-medium text-sm flex items-center gap-1 ">Show last
180-
<input type="number" id="numCommits" min="1" max="30" value="5" class="form-input w-14 mx-1 px-1 py-0.5 text-center border border-gray-300 rounded" style="margin: 2px; width: 40px; height: 22px; text-align: center;">
181-
commits in Open PRs</label> <span class="tooltip-container">
179+
<label id="showCommitsLabel" for="showCommits" class="text-gray-700 font-medium text-sm flex items-center gap-1 ">Show commits made within date range in Open PRs</label> <span class="tooltip-container">
182180
<i class="fa fa-question-circle question-icon"></i>
183181
<span class="tooltip-bubble">
184182
Github Token required.

src/scripts/main.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ let endingDateElement = document.getElementById('endingDate');
1010
let showOpenLabelElement = document.getElementById('showOpenLabel');
1111
let userReasonElement = document.getElementById('userReason');
1212
let showCommitsElement = document.getElementById('showCommits');
13-
let numCommitsElement = document.getElementById('numCommits');
1413

1514
function handleBodyOnLoad() {
1615
chrome.storage.local.get(
@@ -27,7 +26,6 @@ function handleBodyOnLoad() {
2726
'cacheInput',
2827
'githubToken',
2928
'showCommits',
30-
'numCommits',
3129
],
3230
(items) => {
3331
if (items.githubUsername) {
@@ -87,9 +85,6 @@ function handleBodyOnLoad() {
8785
showCommitsElement.checked = false;
8886
handleShowCommitsChange();
8987
}
90-
if (items.numCommits) {
91-
numCommitsElement.value = items.numCommits;
92-
}
9388
},
9489
);
9590
}
@@ -259,21 +254,12 @@ function handleShowCommitsChange() {
259254
let value = showCommitsElement.checked;
260255
chrome.storage.local.set({ showCommits: value });
261256
}
262-
function handleNumCommitsChange() {
263-
let value = numCommitsElement.value;
264-
chrome.storage.local.set({ numCommits: value });
265-
if(window.generateScrumReport) {
266-
window.generateScrumReport();
267-
} else if(typeof allIncluded === 'function') {
268-
allIncluded('popup');
269-
}
270-
}
257+
271258
enableToggleElement.addEventListener('change', handleEnableChange);
272259
githubUsernameElement.addEventListener('keyup', handleGithubUsernameChange);
273260
githubTokenElement.addEventListener('keyup', handleGithubTokenChange);
274261
cacheInputElement.addEventListener('keyup', handleCacheInputChange);
275262
projectNameElement.addEventListener('keyup', handleProjectNameChange);
276-
numCommitsElement.addEventListener('change', handleNumCommitsChange);
277263
startingDateElement.addEventListener('change', handleStartingDateChange);
278264
showCommitsElement.addEventListener('change', handleShowCommitsChange);
279265
endingDateElement.addEventListener('change', handleEndingDateChange);

src/scripts/scrumHelper.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ function allIncluded(outputTarget = 'email') {
4343
let prsReviewDataProcessed = false;
4444
let showOpenLabel = true;
4545
let showCommits = false;
46-
let numCommits = 5; //default
4746
let userReason = '';
4847

4948
let pr_open_button =
@@ -78,7 +77,6 @@ function allIncluded(outputTarget = 'email') {
7877
'yesterdayContribution',
7978
'userReason',
8079
'showCommits',
81-
'numCommits',
8280
'githubCache',
8381
'cacheInput',
8482
'orgName'
@@ -179,9 +177,6 @@ function allIncluded(outputTarget = 'email') {
179177
if (items.orgName) {
180178
orgName = items.orgName;
181179
}
182-
if(items.numCommits) {
183-
numCommits = items.numCommits;
184-
}
185180
},
186181
);
187182
}
@@ -445,11 +440,11 @@ function allIncluded(outputTarget = 'email') {
445440
);
446441
// Fetch commits for open PRs (batch)
447442
if (openPRs.length && githubToken) {
448-
const commitMap = await fetchCommitsForOpenPRs(openPRs, githubToken, numCommits);
443+
const commitMap = await fetchCommitsForOpenPRs(openPRs, githubToken, startingDate, endingDate);
449444
// Attach commits to PR objects
450445
openPRs.forEach(pr => {
451446
pr._allCommits = commitMap[pr.number] || [];
452-
pr._lastCommits = pr._allCommits.slice(0, numCommits);
447+
pr._lastCommits = pr._allCommits;
453448
});
454449
}
455450
}
@@ -496,16 +491,18 @@ function allIncluded(outputTarget = 'email') {
496491
}
497492
}
498493

499-
async function fetchCommitsForOpenPRs(prs, githubToken, numCommits = 5) {
494+
async function fetchCommitsForOpenPRs(prs, githubToken, startDate, endDate) {
500495
if (!prs.length) return {};
496+
const since = new Date(startDate).toISOString();
497+
const until = new Date(endDate + 'T23:59:59').toISOString();
501498
let queries = prs.map((pr, idx) => {
502499
const repoParts = pr.repository_url.split('/');
503500
const owner = repoParts[repoParts.length - 2];
504501
const repo = repoParts[repoParts.length - 1];
505502
return `
506503
pr${idx}: repository(owner: "${owner}", name: "${repo}") {
507504
pullRequest(number: ${pr.number}) {
508-
commits(last: ${numCommits}) {
505+
commits(first: 100) {
509506
nodes {
510507
commit {
511508
messageHeadline
@@ -537,7 +534,14 @@ function allIncluded(outputTarget = 'email') {
537534
prs.forEach((pr, idx) => {
538535
const prData = data.data && data.data[`pr${idx}`] && data.data[`pr${idx}`].pullRequest;
539536
if (prData && prData.commits && prData.commits.nodes) {
540-
commitMap[pr.number] = prData.commits.nodes.map(n => n.commit);
537+
const allCommits = prData.commits.nodes.map(n => n.commit);
538+
const filteredCommits = allCommits.filter(commit => {
539+
const commitDate = new Date(commit.committedDate);
540+
const sinceDate = new Date(since);
541+
const untilDate = new Date(until);
542+
return commitDate >= sinceDate && commitDate <= untilDate;
543+
});
544+
commitMap[pr.number] = filteredCommits;
541545
}
542546
});
543547
return commitMap;
@@ -935,7 +939,6 @@ ${userReason}`;
935939
} else if (item.state === 'open') {
936940
li = `<li><i>(${project})</i> - Made PR (#${number}) - <a href='${html_url}'>${title}</a> ${pr_open_button}`;
937941
if (showCommits && item._lastCommits && item._lastCommits.length) {
938-
item._lastCommits = item._allCommits.slice(0, numCommits);
939942
item._lastCommits.forEach(commit => {
940943
li += `<li style="list-style: disc; margin: 0 0 0 20px; padding: 0; color: #666;"><span style="color:#2563eb;">${commit.messageHeadline}</span><span style="color:#666; font-size: 11px;"> (${new Date(commit.committedDate).toLocaleString()})</span></li>`;
941944
});

0 commit comments

Comments
 (0)