From 08d1ff4c2b236d3ebb82169853db2063d4e42cb9 Mon Sep 17 00:00:00 2001 From: Vikas4245 Date: Sun, 10 Aug 2025 17:39:59 +0530 Subject: [PATCH 1/2] Fix issue labeling: Distinguish between opened and updated issues - Add logic to determine if an issue was created or updated in the selected date range - Issues created in date range show 'Opened Issue' - Issues updated but not created in date range show 'Updated Issue' - Mirrors existing PR logic that distinguishes 'Made PR' vs 'Existing PR' - Fixes confusion where all issues were always labeled as 'Opened Issue' Resolves the issue where users couldn't differentiate between newly created issues and existing issues that were just updated during the selected period. --- src/scripts/scrumHelper.js | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/scripts/scrumHelper.js b/src/scripts/scrumHelper.js index 2572cba..9c4e18f 100644 --- a/src/scripts/scrumHelper.js +++ b/src/scripts/scrumHelper.js @@ -1507,25 +1507,51 @@ ${userReason}`; nextWeekArray.push(li2); } + // Determine if issue was created or updated in date range + const issueCreatedDate = new Date(item.created_at); + + // Get the correct date range for filtering + let startDateFilter, endDateFilter; + if (yesterdayContribution) { + const today = new Date(); + const yesterday = new Date(today.getTime() - 24 * 60 * 60 * 1000); + startDateFilter = new Date(yesterday.toISOString().split('T')[0] + 'T00:00:00Z'); + endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z'); + } else if (startingDate && endingDate) { + startDateFilter = new Date(startingDate + 'T00:00:00Z'); + endDateFilter = new Date(endingDate + 'T23:59:59Z'); + } else { + // Default to last 7 days if no date range is set + const today = new Date(); + const lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7); + startDateFilter = new Date(lastWeek.toISOString().split('T')[0] + 'T00:00:00Z'); + endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z'); + } + + const isNewIssue = issueCreatedDate >= startDateFilter && issueCreatedDate <= endDateFilter; + const issueAction = isNewIssue ? 'Opened Issue' : 'Updated Issue'; + + log(`[ISSUE DEBUG] Issue #${number} - isNewIssue: ${isNewIssue}, issueAction: ${issueAction}, state: ${item.state}, created: ${item.created_at}, updated: ${item.updated_at}`); + if (item.state === 'open') { - li = `
  • (${project}) - Opened Issue(#${number}) - ${title}${showOpenLabel ? ' ' + issue_opened_button : ''}
  • `; + li = `
  • (${project}) - ${issueAction}(#${number}) - ${title}${showOpenLabel ? ' ' + issue_opened_button : ''}
  • `; } else if (item.state === 'closed') { // Use state_reason to distinguish closure reason if (item.state_reason === 'completed') { - li = `
  • (${project}) - Opened Issue(#${number}) - ${title} ${issue_closed_completed_button}
  • `; + li = `
  • (${project}) - ${issueAction}(#${number}) - ${title} ${issue_closed_completed_button}
  • `; } else if (item.state_reason === 'not_planned') { - li = `
  • (${project}) - Opened Issue(#${number}) - ${title} ${issue_closed_notplanned_button}
  • `; + li = `
  • (${project}) - ${issueAction}(#${number}) - ${title} ${issue_closed_notplanned_button}
  • `; } else { - li = `
  • (${project}) - Opened Issue(#${number}) - ${title} ${issue_closed_button}
  • `; + li = `
  • (${project}) - ${issueAction}(#${number}) - ${title} ${issue_closed_button}
  • `; } } else { // Fallback for unexpected state - li = `
  • (${project}) - Opened Issue(#${number}) - ${title}
  • `; + li = `
  • (${project}) - ${issueAction}(#${number}) - ${title}
  • `; } log('[SCRUM-DEBUG] Added issue to lastWeekArray:', li, item); From 79930dd4653c32b289efc6758f91368df20838ab Mon Sep 17 00:00:00 2001 From: Vikas4245 Date: Sun, 10 Aug 2025 19:02:42 +0530 Subject: [PATCH 2/2] Address code review feedback: Improve issue labeling implementation - Extract date range calculation into reusable getDateRangeFilters() helper - Add proper updated_at timestamp validation for 'Updated Issue' labeling - Fix timezone issues with UTC-based date handling - Use time-based arithmetic to avoid month boundary bugs - Gate debug logging to prevent production noise - Eliminate code duplication between PR and issue processing - Add comprehensive validation to prevent stale issues being labeled as 'Updated' Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- src/scripts/scrumHelper.js | 101 +++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 39 deletions(-) diff --git a/src/scripts/scrumHelper.js b/src/scripts/scrumHelper.js index 9c4e18f..2e4783d 100644 --- a/src/scripts/scrumHelper.js +++ b/src/scripts/scrumHelper.js @@ -13,6 +13,47 @@ function logError(...args) { } } +/** + * Helper function to get date range filters with proper UTC handling + * @param {boolean} yesterdayContribution - Whether to use yesterday contribution mode + * @param {string} startingDate - Starting date string (YYYY-MM-DD format) + * @param {string} endingDate - Ending date string (YYYY-MM-DD format) + * @returns {Object} Object with startDateFilter and endDateFilter as Date objects + */ +function getDateRangeFilters(yesterdayContribution, startingDate, endingDate) { + let startDateFilter, endDateFilter; + + if (yesterdayContribution) { + const now = new Date(); + // Use time-based arithmetic to avoid timezone issues + const yesterdayTime = now.getTime() - 24 * 60 * 60 * 1000; + const yesterday = new Date(yesterdayTime); + + // Create UTC dates to avoid timezone inconsistencies + const yesterdayStr = yesterday.toISOString().split('T')[0]; + const todayStr = now.toISOString().split('T')[0]; + + startDateFilter = new Date(yesterdayStr + 'T00:00:00.000Z'); + endDateFilter = new Date(todayStr + 'T23:59:59.999Z'); + } else if (startingDate && endingDate) { + startDateFilter = new Date(startingDate + 'T00:00:00.000Z'); + endDateFilter = new Date(endingDate + 'T23:59:59.999Z'); + } else { + // Default to last 7 days - use time arithmetic for consistency + const now = new Date(); + const lastWeekTime = now.getTime() - 7 * 24 * 60 * 60 * 1000; + const lastWeek = new Date(lastWeekTime); + + const lastWeekStr = lastWeek.toISOString().split('T')[0]; + const todayStr = now.toISOString().split('T')[0]; + + startDateFilter = new Date(lastWeekStr + 'T00:00:00.000Z'); + endDateFilter = new Date(todayStr + 'T23:59:59.999Z'); + } + + return { startDateFilter, endDateFilter }; +} + let refreshButton_Placed = false; let enableToggle = true; @@ -1399,33 +1440,21 @@ ${userReason}`; let prAction = ''; const prCreatedDate = new Date(item.created_at); + const prUpdatedDate = new Date(item.updated_at); - // Get the correct date range for filtering - let startDateFilter, endDateFilter; - if (yesterdayContribution) { - const today = new Date(); - const yesterday = new Date(today.getTime() - 24 * 60 * 60 * 1000); - startDateFilter = new Date(yesterday.toISOString().split('T')[0] + 'T00:00:00Z'); - endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z'); // Use yesterday for start and today for end - } else if (startingDate && endingDate) { - startDateFilter = new Date(startingDate + 'T00:00:00Z'); - endDateFilter = new Date(endingDate + 'T23:59:59Z'); - } else { - // Default to last 7 days if no date range is set - const today = new Date(); - const lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7); - startDateFilter = new Date(lastWeek.toISOString().split('T')[0] + 'T00:00:00Z'); - endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z'); - } + // Get date range filters using helper function + const { startDateFilter, endDateFilter } = getDateRangeFilters(yesterdayContribution, startingDate, endingDate); const isNewPR = prCreatedDate >= startDateFilter && prCreatedDate <= endDateFilter; - const prUpdatedDate = new Date(item.updated_at); const isUpdatedInRange = prUpdatedDate >= startDateFilter && prUpdatedDate <= endDateFilter; // Check if PR has commits in the date range const hasCommitsInRange = item._allCommits && item._allCommits.length > 0; - log(`[PR DEBUG] PR #${number} - isNewPR: ${isNewPR}, isUpdatedInRange: ${isUpdatedInRange}, state: ${item.state}, hasCommitsInRange: ${hasCommitsInRange}, created: ${item.created_at}, updated: ${item.updated_at}`); + // Only log in debug mode to avoid production noise + if (DEBUG) { + log(`[PR DEBUG] PR #${number} - isNewPR: ${isNewPR}, isUpdatedInRange: ${isUpdatedInRange}, state: ${item.state}, hasCommitsInRange: ${hasCommitsInRange}, created: ${item.created_at}, updated: ${item.updated_at}`); + } if (platform === 'github') { // For existing PRs (not new), they must be open AND have commits in the date range @@ -1509,29 +1538,23 @@ ${userReason}`; // Determine if issue was created or updated in date range const issueCreatedDate = new Date(item.created_at); + const issueUpdatedDate = new Date(item.updated_at); - // Get the correct date range for filtering - let startDateFilter, endDateFilter; - if (yesterdayContribution) { - const today = new Date(); - const yesterday = new Date(today.getTime() - 24 * 60 * 60 * 1000); - startDateFilter = new Date(yesterday.toISOString().split('T')[0] + 'T00:00:00Z'); - endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z'); - } else if (startingDate && endingDate) { - startDateFilter = new Date(startingDate + 'T00:00:00Z'); - endDateFilter = new Date(endingDate + 'T23:59:59Z'); - } else { - // Default to last 7 days if no date range is set - const today = new Date(); - const lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7); - startDateFilter = new Date(lastWeek.toISOString().split('T')[0] + 'T00:00:00Z'); - endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z'); - } + // Get date range filters using helper function + const { startDateFilter, endDateFilter } = getDateRangeFilters(yesterdayContribution, startingDate, endingDate); const isNewIssue = issueCreatedDate >= startDateFilter && issueCreatedDate <= endDateFilter; - const issueAction = isNewIssue ? 'Opened Issue' : 'Updated Issue'; - - log(`[ISSUE DEBUG] Issue #${number} - isNewIssue: ${isNewIssue}, issueAction: ${issueAction}, state: ${item.state}, created: ${item.created_at}, updated: ${item.updated_at}`); + + // For "Updated Issue" label, verify both: + // 1. Issue was NOT created in the date range + // 2. Issue was actually updated within the date range + const isUpdatedInRange = issueUpdatedDate >= startDateFilter && issueUpdatedDate <= endDateFilter; + const issueAction = isNewIssue ? 'Opened Issue' : (isUpdatedInRange ? 'Updated Issue' : 'Opened Issue'); + + // Only log in debug mode to avoid production noise + if (DEBUG) { + log(`[ISSUE DEBUG] Issue #${number} - isNewIssue: ${isNewIssue}, isUpdatedInRange: ${isUpdatedInRange}, issueAction: ${issueAction}, state: ${item.state}, created: ${item.created_at}, updated: ${item.updated_at}`); + } if (item.state === 'open') { li = `
  • (${project}) - ${issueAction}(#${number}) - ${title}${showOpenLabel ? ' ' + issue_opened_button : ''}
  • `;