Skip to content

Commit 4303dc8

Browse files
committed
taking inputs from user for number of commits
Signed-off-by: Vedansh Saini <[email protected]>
1 parent 499cfc8 commit 4303dc8

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/popup.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,14 @@ <h4>Your Github Token</h4>
171171
</div>
172172
<input id="githubToken" type="password" class="w-full border-2 border-gray-200 bg-gray-200 rounded-xl text-gray-800 p-2 my-2 pr-10" placeholder="Required for making authenticated requests">
173173

174-
<div class="col s12 my-4">
174+
175+
176+
<div class="col s12 my-4 ">
175177
<div class="flex items-center gap-2">
176-
<input type="checkbox" id="showCommits" checked class="form-checkbox h-4 w-4 text-blue-600">
177-
<label id="showCommitsLabel" for="showCommits" class="text-gray-700 font-medium text-sm">Show last 5 commits in Open PRs</label> <span class="tooltip-container">
178+
<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="25" value="5" class="form-input w-14 mx-1 px-1 py-0.5 text-center border border-gray-300 rounded" style="width: 48px; height: 28px; text-align: center;">
181+
commits in Open PRs</label> <span class="tooltip-container">
178182
<i class="fa fa-question-circle question-icon"></i>
179183
<span class="tooltip-bubble">
180184
Github Token required.

src/scripts/main.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ 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');
1314

1415
function handleBodyOnLoad() {
1516
chrome.storage.local.get(
@@ -27,6 +28,7 @@ function handleBodyOnLoad() {
2728
'cacheInput',
2829
'githubToken',
2930
'showCommits',
31+
'numCommits',
3032
],
3133
(items) => {
3234
if (items.githubUsername) {
@@ -86,6 +88,9 @@ function handleBodyOnLoad() {
8688
showCommitsElement.checked = false;
8789
handleShowCommitsChange();
8890
}
91+
if (items.numCommits) {
92+
numCommitsElement.value = items.numCommits;
93+
}
8994
},
9095
);
9196
}
@@ -255,11 +260,16 @@ function handleShowCommitsChange() {
255260
let value = showCommitsElement.checked;
256261
chrome.storage.local.set({ showCommits: value });
257262
}
263+
function handleNumCommitsChange() {
264+
let value = numCommitsElement.value;
265+
chrome.storage.local.set({ numCommits: value });
266+
}
258267
enableToggleElement.addEventListener('change', handleEnableChange);
259268
githubUsernameElement.addEventListener('keyup', handleGithubUsernameChange);
260269
githubTokenElement.addEventListener('keyup', handleGithubTokenChange);
261270
cacheInputElement.addEventListener('keyup', handleCacheInputChange);
262271
projectNameElement.addEventListener('keyup', handleProjectNameChange);
272+
numCommitsElement.addEventListener('change', handleNumCommitsChange);
263273
startingDateElement.addEventListener('change', handleStartingDateChange);
264274
showCommitsElement.addEventListener('change', handleShowCommitsChange);
265275
endingDateElement.addEventListener('change', handleEndingDateChange);

src/scripts/scrumHelper.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function allIncluded(outputTarget = 'email') {
2727
let showOpenLabel = true;
2828
let showClosedLabel = true;
2929
let showCommits = false;
30+
let numCommits = 5; //default
3031
let userReason = '';
3132

3233
let pr_merged_button =
@@ -56,6 +57,7 @@ function allIncluded(outputTarget = 'email') {
5657
'yesterdayContribution',
5758
'userReason',
5859
'showCommits',
60+
'numCommits',
5961
'githubCache',
6062
'cacheInput',
6163
'orgName'
@@ -144,6 +146,9 @@ function allIncluded(outputTarget = 'email') {
144146
if (items.orgName) {
145147
orgName = items.orgName;
146148
}
149+
if(items.numCommits) {
150+
numCommits = items.numCommits;
151+
}
147152
},
148153
);
149154
}
@@ -418,7 +423,7 @@ function allIncluded(outputTarget = 'email') {
418423
);
419424
// Fetch commits for open PRs (batch)
420425
if (openPRs.length && githubToken) {
421-
const commitMap = await fetchCommitsForOpenPRs(openPRs, githubToken);
426+
const commitMap = await fetchCommitsForOpenPRs(openPRs, githubToken, numCommits);
422427
// Attach commits to PR objects
423428
openPRs.forEach(pr => {
424429
pr._lastCommits = commitMap[pr.number] || [];
@@ -456,7 +461,7 @@ function allIncluded(outputTarget = 'email') {
456461
}
457462
}
458463

459-
async function fetchCommitsForOpenPRs(prs, githubToken) {
464+
async function fetchCommitsForOpenPRs(prs, githubToken, numCommits = 5) {
460465
if (!prs.length) return {};
461466
let queries = prs.map((pr, idx) => {
462467
const repoParts = pr.repository_url.split('/');
@@ -465,7 +470,7 @@ function allIncluded(outputTarget = 'email') {
465470
return `
466471
pr${idx}: repository(owner: "${owner}", name: "${repo}") {
467472
pullRequest(number: ${pr.number}) {
468-
commits(last: 5) {
473+
commits(last: ${numCommits}) {
469474
nodes {
470475
commit {
471476
messageHeadline

0 commit comments

Comments
 (0)