Skip to content

Fix issue labeling: solved opened and updated issues #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Vikas4245
Copy link

@Vikas4245 Vikas4245 commented Aug 10, 2025

📝 Summary of Changes

Fixes #227


📝 Summary of Changes

Fix issue labeling: Distinguish between opened and updated issues

Problem

Issues were always labeled as "Opened Issue" regardless of whether they were created or just updated during the selected date range, causing user confusion.

Solution

  • Added logic to determine if an issue was created or updated in the selected date range
  • Issues created in date range → "Opened Issue"
  • Issues updated but not created in date range → "Updated Issue"
  • Mirrors existing PR logic that distinguishes "Made PR" vs "Existing PR"

Testing

  • Tested with various scenarios including newly created, updated existing, and closed issues
  • All edge cases work correctly with different date selection modes

Fixes the confusion where users couldn't differentiate between newly created issues and existing issues that were just updated during the selected period.

✅ Checklist

  • [✅]I’ve tested my changes locally
  • [✅ ] I’ve added tests (if applicable)
  • I’ve updated documentation (if applicable)
  • [✅ ] My code follows the project’s code style guidelines

Summary by Sourcery

Distinguish between newly opened and updated issues when generating issue labels by checking the issue creation date against the selected date range and updating all issue templates to use the correct label.

Bug Fixes:

  • Label issues as "Updated Issue" if they were modified but not created within the selected date range.
  • Calculate dynamic date filters for yesterday, a custom range, or default last 7 days to determine issue recency.

- 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.
Copy link
Contributor

sourcery-ai bot commented Aug 10, 2025

Reviewer's Guide

Updates the issue labeling in scrumHelper.js by introducing date range filters and a new isNewIssue flag to dynamically label issues as opened or updated within the selected period.

File-Level Changes

Change Details Files
Distinguish opened vs updated issues based on creation date
  • Compute startDateFilter and endDateFilter for yesterday, user-defined range, or default last 7 days
  • Determine isNewIssue by comparing item.created_at against these filters
  • Set issueAction to 'Opened Issue' or 'Updated Issue' accordingly
  • Replace all hard-coded 'Opened Issue' labels with the dynamic issueAction variable
  • Add debug logging for issueAction, created_at, updated_at, and isNewIssue
src/scripts/scrumHelper.js

Assessment against linked issues

Issue Objective Addressed Explanation
#227 Display 'Opened Issue' label only for issues created in the selected date range.
#227 Display 'Updated Issue' label for issues that were updated (but not created) in the selected date range, including closed issues.
#227 Ensure the labeling logic works correctly with different date selection modes (e.g., yesterday, custom range, default last 7 days).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added javascript Pull requests that update javascript code core labels Aug 10, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Vikas4245 - I've reviewed your changes - here's some feedback:

  • Consider extracting the date range calculation into a reusable helper to reduce duplication and improve readability.
  • When labeling 'Updated Issue', also verify that the issue’s updated_at timestamp falls within the selected range to avoid tagging stale issues as updated.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the date range calculation into a reusable helper to reduce duplication and improve readability.
- When labeling 'Updated Issue', also verify that the issue’s updated_at timestamp falls within the selected range to avoid tagging stale issues as updated.

## Individual Comments

### Comment 1
<location> `src/scripts/scrumHelper.js:1518` </location>
<code_context>
+                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');
</code_context>

<issue_to_address>
Date construction using string manipulation may introduce timezone inconsistencies.

This approach may cause bugs when local dates cross midnight or during daylight saving changes. Use UTC-based methods or a date library for consistent results.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
                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');
                }
=======
                if (yesterdayContribution) {
                    const now = new Date();
                    // Get UTC date parts for today and yesterday
                    const todayUTC = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
                    const yesterdayUTC = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 1));
                    startDateFilter = new Date(Date.UTC(yesterdayUTC.getUTCFullYear(), yesterdayUTC.getUTCMonth(), yesterdayUTC.getUTCDate(), 0, 0, 0));
                    endDateFilter = new Date(Date.UTC(todayUTC.getUTCFullYear(), todayUTC.getUTCMonth(), todayUTC.getUTCDate(), 23, 59, 59));
                } else if (startingDate && endingDate) {
                    // Parse startingDate and endingDate as UTC
                    const [startYear, startMonth, startDay] = startingDate.split('-').map(Number);
                    const [endYear, endMonth, endDay] = endingDate.split('-').map(Number);
                    startDateFilter = new Date(Date.UTC(startYear, startMonth - 1, startDay, 0, 0, 0));
                    endDateFilter = new Date(Date.UTC(endYear, endMonth - 1, endDay, 23, 59, 59));
                } else {
                    // Default to last 7 days if no date range is set
                    const now = new Date();
                    const todayUTC = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
                    const lastWeekUTC = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 7));
                    startDateFilter = new Date(Date.UTC(lastWeekUTC.getUTCFullYear(), lastWeekUTC.getUTCMonth(), lastWeekUTC.getUTCDate(), 0, 0, 0));
                    endDateFilter = new Date(Date.UTC(todayUTC.getUTCFullYear(), todayUTC.getUTCMonth(), todayUTC.getUTCDate(), 23, 59, 59));
                }
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `src/scripts/scrumHelper.js:1526` </location>
<code_context>
+                } 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');
</code_context>

<issue_to_address>
Subtracting days using Date constructor can yield unexpected results at month boundaries.

Date arithmetic using the Date constructor can fail at month boundaries. Use getTime() subtraction for consistent results.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
                    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 lastWeek = new Date(today.getTime() - 7 * 24 * 60 * 60 * 1000);
                    startDateFilter = new Date(lastWeek.toISOString().split('T')[0] + 'T00:00:00Z');
                    endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z');
>>>>>>> REPLACE

</suggested_fix>

### Comment 3
<location> `src/scripts/scrumHelper.js:1534` </location>
<code_context>
+                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') {
</code_context>

<issue_to_address>
Consider removing or gating debug logging for production environments.

Debug logs in production can expose sensitive data and create unnecessary noise. If these logs are only needed for development, use a conditional or appropriate logging level to prevent them from appearing in production.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
                log(`[ISSUE DEBUG] Issue #${number} - isNewIssue: ${isNewIssue}, issueAction: ${issueAction}, state: ${item.state}, created: ${item.created_at}, updated: ${item.updated_at}`);
=======
                if (process.env.NODE_ENV !== 'production') {
                    log(`[ISSUE DEBUG] Issue #${number} - isNewIssue: ${isNewIssue}, issueAction: ${issueAction}, state: ${item.state}, created: ${item.created_at}, updated: ${item.updated_at}`);
                }
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 1515 to 1529
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');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Date construction using string manipulation may introduce timezone inconsistencies.

This approach may cause bugs when local dates cross midnight or during daylight saving changes. Use UTC-based methods or a date library for consistent results.

Suggested change
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');
}
if (yesterdayContribution) {
const now = new Date();
// Get UTC date parts for today and yesterday
const todayUTC = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
const yesterdayUTC = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 1));
startDateFilter = new Date(Date.UTC(yesterdayUTC.getUTCFullYear(), yesterdayUTC.getUTCMonth(), yesterdayUTC.getUTCDate(), 0, 0, 0));
endDateFilter = new Date(Date.UTC(todayUTC.getUTCFullYear(), todayUTC.getUTCMonth(), todayUTC.getUTCDate(), 23, 59, 59));
} else if (startingDate && endingDate) {
// Parse startingDate and endingDate as UTC
const [startYear, startMonth, startDay] = startingDate.split('-').map(Number);
const [endYear, endMonth, endDay] = endingDate.split('-').map(Number);
startDateFilter = new Date(Date.UTC(startYear, startMonth - 1, startDay, 0, 0, 0));
endDateFilter = new Date(Date.UTC(endYear, endMonth - 1, endDay, 23, 59, 59));
} else {
// Default to last 7 days if no date range is set
const now = new Date();
const todayUTC = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
const lastWeekUTC = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 7));
startDateFilter = new Date(Date.UTC(lastWeekUTC.getUTCFullYear(), lastWeekUTC.getUTCMonth(), lastWeekUTC.getUTCDate(), 0, 0, 0));
endDateFilter = new Date(Date.UTC(todayUTC.getUTCFullYear(), todayUTC.getUTCMonth(), todayUTC.getUTCDate(), 23, 59, 59));
}

Comment on lines 1526 to 1528
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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Subtracting days using Date constructor can yield unexpected results at month boundaries.

Date arithmetic using the Date constructor can fail at month boundaries. Use getTime() subtraction for consistent results.

Suggested change
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 lastWeek = new Date(today.getTime() - 7 * 24 * 60 * 60 * 1000);
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}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider removing or gating debug logging for production environments.

Debug logs in production can expose sensitive data and create unnecessary noise. If these logs are only needed for development, use a conditional or appropriate logging level to prevent them from appearing in production.

Suggested change
log(`[ISSUE DEBUG] Issue #${number} - isNewIssue: ${isNewIssue}, issueAction: ${issueAction}, state: ${item.state}, created: ${item.created_at}, updated: ${item.updated_at}`);
if (process.env.NODE_ENV !== 'production') {
log(`[ISSUE DEBUG] Issue #${number} - isNewIssue: ${isNewIssue}, issueAction: ${issueAction}, state: ${item.state}, created: ${item.created_at}, updated: ${item.updated_at}`);
}

- 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>
@Vikas4245
Copy link
Author

@sourcery-ai Thank you for the excellent feedback! I've addressed all the suggestions:

Changes Made:

✅ Extracted date range calculation into a reusable "getDateRangeFilters()" helper function to eliminate duplication and improve readability

✅ Enhanced `updated_at "validation - "Updated Issue" label now requires the issue's "updated_at" timestamp to fall within the selected range, preventing stale issues from being incorrectly labeled

✅ Fixed timezone and date arithmetic issues by:

  • Using UTC-based date construction instead of string manipulation
  • Implementing time-based arithmetic to avoid month boundary bugs
  • Adding precise timestamp boundaries .

✅ Gated debug logging with "if (DEBUG)"conditionals to prevent production noise

Additional Improvements:

  • Applied the same helper function to PR processing logic for consistency
  • Added comprehensive test coverage including edge cases
  • Enhanced documentation with proper JSDoc comments

The solution now handles all edge cases correctly, including issues that were created outside the date range but never updated within it (fallback to "Opened Issue").

All feedback has been implemented and tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core javascript Pull requests that update javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change "Opened Issues" to "Updated Issues" When Issue State Changes
1 participant