Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scrum_helper
Submodule scrum_helper added at 518de0
144 changes: 65 additions & 79 deletions src/scripts/scrumHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ ${userReason}`;
let pr_arr = githubPrsReviewDataProcessed[repo][pr];
let prText = '';
prText +=
"<a href='" + pr_arr.html_url + "' target='_blank'>#" + pr_arr.number + '</a> (' + pr_arr.title + ') ';
"<a href='" + pr_arr.html_url + "' target='_blank'>#" + pr_arr.number + '</a> (' + pr_arr.title +
if (showOpenLabel && pr_arr.state === 'open') prText += issue_opened_button;
// Do not show closed label for reviewed PRs
prText += '&nbsp;&nbsp;';
Expand Down Expand Up @@ -1232,6 +1232,7 @@ ${userReason}`;
}

for (let i = 0; i < items.length; i++) {

let item = items[i];
log('[SCRUM-DEBUG] Processing item:', item);
// For GitLab, treat all items in the MRs array as MRs
Expand Down Expand Up @@ -1259,91 +1260,76 @@ ${userReason}`;
const endDate = new Date(endingDate + 'T23:59:59');
const isNewPR = prCreatedDate >= startDate && prCreatedDate <= endDate;

if (platform === 'github') {
if (!isNewPR) {
// Only show existing PRs if they are open and have commits in the date range
if (item.state !== 'open') {
continue; // Skip closed/merged existing PRs
}
const hasCommitsInRange = showCommits && item._allCommits && item._allCommits.length > 0;
if (!hasCommitsInRange) {
continue; // Skip existing PRs without commits in date range
}
}
prAction = isNewPR ? 'Made PR' : 'Existing PR';
} else if (platform === 'gitlab') {
prAction = isNewPR ? 'Made Merge Request' : 'Existing Merge Request';
}



if (isDraft) {
if (item.pull_request) {
const prCreatedDate = new Date(item.created_at);
const startDate = new Date(startingDate);
const endDate = new Date(endingDate + 'T23:59:59');
const isNewPR = prCreatedDate >= startDate && prCreatedDate <= endDate;
if (!isNewPR) {
const hasCommitsInRange = showCommits && item._allCommits && item._allCommits.length > 0;
if (!hasCommitsInRange) {
continue; // Skip PRs created outside the date range with no commits
}
}

li = `<li><i>(${project})</i> - Made PR (#${number}) - <a href='${html_url}'>${title}</a>${showOpenLabel ? ' ' + pr_draft_button : ''}</li>`;
} else if (item.state === 'open' || item.state === 'opened') {
li = `<li><i>(${project})</i> - ${prAction} (#${number}) - <a href='${html_url}'>${title}</a>${showOpenLabel ? ' ' + pr_open_button : ''}`;
const prAction = isNewPR ? 'Made PR' : 'Existing PR';

// 🟤 Draft PR
if (isDraft) {
li = `<li><i>(${project})</i> - ${prAction} (#${number}) - <a href='${html_url}'>${title}</a> ${pr_draft_button}</li>`;

// 🟢 Open PR
} else if (item.state === 'open') {
li = `<li><i>(${project})</i> - ${prAction} (#${number}) - <a href='${html_url}'>${title}</a> ${pr_open_button}`;
if (showCommits && item._allCommits && item._allCommits.length && !isNewPR) {
log(`[PR DEBUG] Rendering commits for existing PR #${number}:`, item._allCommits);
item._allCommits.forEach(commit => {
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>`;
});
}
li += `</li>`;

if (showCommits && item._allCommits && item._allCommits.length && !isNewPR) {
log(`[PR DEBUG] Rendering commits for existing PR #${number}:`, item._allCommits);
item._allCommits.forEach(commit => {
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>`;
});
}
li += `</li>`;
} else if (platform === 'gitlab' && item.state === 'closed') {
// For GitLab, show closed label for closed MRs only if showOpenLabel is enabled
li = `<li><i>(${project})</i> - ${prAction} (#${number}) - <a href='${html_url}'>${title}</a>${showOpenLabel ? ' ' + pr_closed_button : ''}</li>`;
} else {
// GitHub: check merged status if possible
let merged = null;
if ((githubToken || (useMergedStatus && !fallbackToSimple)) && mergedStatusResults) {
let repoParts = repository_url.split('/');
let owner = repoParts[repoParts.length - 2];
let repo = repoParts[repoParts.length - 1];
merged = mergedStatusResults[`${owner}/${repo}#${number}`];
}
if (merged === true) {
// 🔴 Closed PR (check if merged or not)
} else if (item.state === 'closed') {
const isMerged = item.merged_at !== null && item.merged_at !== undefined;

li = `<li><i>(${project})</i> - ${prAction} (#${number}) - <a href='${html_url}'>${title}</a>${showOpenLabel ? ' ' + pr_merged_button : ''}</li>`;
} else {
// Always show closed label for merged === false or merged === null/undefined
li = `<li><i>(${project})</i> - ${prAction} (#${number}) - <a href='${html_url}'>${title}</a>${showOpenLabel ? ' ' + pr_closed_button : ''}</li>`;
}
}
log('[SCRUM-DEBUG] Added PR/MR to lastWeekArray:', li, item);
lastWeekArray.push(li);
continue; // Prevent issue logic from overwriting PR li
if (isMerged) {
// Merged PR: no label shown
li = `<li><i>(${project})</i> - ${prAction} (#${number}) - <a href='${html_url}'>${title}</a></li>`;
} else {
// Only process as issue if not a PR
if (item.state === 'open' && item.body?.toUpperCase().indexOf('YES') > 0) {
let li2 =
'<li><i>(' +
project +
')</i> - Work on Issue(#' +
number +
") - <a href='" +
html_url +
"' target='_blank'>" +
title +
'</a>' + (showOpenLabel ? ' ' + issue_opened_button : '') +
'&nbsp;&nbsp;</li>';
nextWeekArray.push(li2);
}
// Closed but not merged: no label either
li = `<li><i>(${project})</i> - ${prAction} (#${number}) - <a href='${html_url}'>${title}</a></li>`;
}
}

if (item.state === 'open') {
li = `<li><i>(${project})</i> - Opened Issue(#${number}) - <a href='${html_url}'>${title}</a>${showOpenLabel ? ' ' + issue_opened_button : ''}</li>`;
lastWeekArray.push(li);
continue;

} else if (item.state === 'closed') {
// Always show closed label for closed issues
li = `<li><i>(${project})</i> - Opened Issue(#${number}) - <a href='${html_url}'>${title}</a>${showOpenLabel ? ' ' + issue_closed_button : ''}</li>`;
} else {
// Fallback for unexpected state
li = `<li><i>(${project})</i> - Opened Issue(#${number}) - <a href='${html_url}'>${title}</a></li>`;
}
} else {
// 📌 It's an Issue
if (item.state === 'open' && item.body?.toUpperCase().indexOf('YES') > 0) {
let li2 =
`<li><i>(${project})</i> - Work on Issue(#${number}) - <a href='${html_url}' target='_blank'>${title}</a> ${issue_opened_button}</li>`;
nextWeekArray.push(li2);
}

log('[SCRUM-DEBUG] Added issue to lastWeekArray:', li, item);
lastWeekArray.push(li);
}
if (item.state === 'open') {
li = `<li><i>(${project})</i> - Opened Issue(#${number}) - <a href='${html_url}'>${title}</a> ${issue_opened_button}</li>`;
} else if (item.state === 'closed') {
li = `<li><i>(${project})</i> - Opened Issue(#${number}) - <a href='${html_url}'>${title}</a> </li>`;
} else {
li = `<li><i>(${project})</i> - Opened Issue(#${number}) - <a href='${html_url}' target='_blank'>${title}</a></li>`;
}

lastWeekArray.push(li);
}
}
issuesDataProcessed = true;
if (outputTarget === 'email') {
triggerScrumGeneration();
}
log('[SCRUM-DEBUG] Final lastWeekArray:', lastWeekArray);
issuesDataProcessed = true;
Expand Down