Skip to content

fix: Add date range validation to prevent invalid date selection (#572)#587

Open
SinghCharanjeet11 wants to merge 7 commits intofossasia:mainfrom
SinghCharanjeet11:fix/date-validation-572
Open

fix: Add date range validation to prevent invalid date selection (#572)#587
SinghCharanjeet11 wants to merge 7 commits intofossasia:mainfrom
SinghCharanjeet11:fix/date-validation-572

Conversation

@SinghCharanjeet11
Copy link
Copy Markdown

@SinghCharanjeet11 SinghCharanjeet11 commented Apr 21, 2026

Description

Fixes #572

This PR adds date range validation to prevent users from selecting invalid date ranges where the start date is after the end date. Previously, when users entered an invalid date range, the system would silently show "No activity to report" instead of displaying a clear validation error.

Changes Made

  • Added validateDateRange() function to check if start date ≤ end date
  • Added showDateValidationError() function to display error messages using Materialize toast
  • Modified Generate Report button handler to validate dates before report generation
  • Added real-time validation to date input change handlers (validates as users type)
  • Added i18n message invalidDateRangeError for localization support
  • Validation only applies to custom date ranges (preset timeframes like "Yesterday" are unaffected)

Testing

  • Extension builds successfully with npm run build
  • Validation triggers when start date > end date
  • Error message displays using Materialize toast
  • Valid date ranges continue to work normally
  • Preset timeframes (Yesterday, etc.) are not affected
  • Real-time validation works as users change dates

Related Issues

Closes #572

Summary by Sourcery

Add date range validation for custom reports and extend GitLab integration to include commit activity in generated scrum reports.

New Features:

  • Add validation to prevent users from generating reports with an invalid custom date range where the start date is after the end date.
  • Include GitLab commit activity alongside issues and merge requests in generated scrum reports.
  • Display user-facing error messages for invalid date ranges using toast notifications with a fallback alert.

Enhancements:

  • Refine GitLab data processing to normalize commit data into the existing reporting format.
  • Improve real-time UX by validating custom date ranges as users edit start and end date fields.

Documentation:

  • Update README to highlight GitLab support, multi-platform capabilities, and the upcoming roadmap.

SinghCharanjeet11 and others added 6 commits March 31, 2026 18:14
- Update biome schema version from 2.3.13 to 2.4.10 to match CLI
- Add GitLab and Gitea support to roadmap in README
- Highlight new multi-platform features in Features section
- Document upcoming SCM analytics and Gitea integration

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add commits fetching from GitLab projects with date filtering
- Map commits to standard format for report generation
- Include commits data in GitLab data processing
- Add project metadata to commits for better tracking
- Support author filtering using author_name parameter

This enables complete feature parity with GitHub support:
Projects fetching
Merge requests fetchingIssues fetching Commits fetching
…upport

feat: complete GitLab support with commits fetching
- Add commits fetching from GitLab projects with date filtering
- Map commits to standard format for report generation
- Include commits data in GitLab data processing
- Add project metadata to commits for better tracking
- Support author filtering using author_name parameter

This enables complete feature parity with GitHub support:
Projects fetching
Merge requests fetchingIssues fetching Commits fetching
…upport

feat: complete GitLab support with commits fetching
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 21, 2026

Reviewer's Guide

Implements front-end date range validation for custom report ranges in the popup, adds user-visible error messaging with i18n support, and extends GitLab integration to fetch/map per-project commits into the existing report generation pipeline along with corresponding README updates.

Sequence diagram for Generate Report flow with date range validation

sequenceDiagram
    actor User
    participant Popup
    participant Validation as validateDateRange
    participant I18n as chrome_i18n
    participant Toast as Materialize_toast
    participant Report as ReportGenerator

    User->>Popup: Click generateBtn
    Popup->>Popup: Read yesterdayContribution radio
    alt Custom date range selected
        Popup->>Popup: Read startingDate and endingDate
        Popup->>Validation: validateDateRange(startDate, endDate)
        Validation-->>Popup: isValid
        alt Date range invalid
            Popup->>I18n: getMessage(invalidDateRangeError)
            I18n-->>Popup: localizedMessage or null
            alt Materialize available
                Popup->>Toast: toast(message, 4000, red)
            else Fallback
                Popup->>User: alert(message)
            end
            Popup-->>User: Stop report generation
        else Date range valid
            Popup->>Report: generateScrumReport()
            Report-->>User: Generated report content
        end
    else Yesterday preset selected
        Popup->>Report: generateScrumReport()
        Report-->>User: Generated report content
    end
Loading

Sequence diagram for GitLab per-project commits integration into report

sequenceDiagram
    participant Popup
    participant Scrum as scrumHelper_allIncluded
    participant GitLab as GitLabHelper
    participant GitLabAPI as GitLab_API
    participant Writer as writeGithubIssuesPrs

    Popup->>Scrum: allIncluded(outputTarget)
    Scrum->>GitLab: getData(username, startDate, endDate)
    GitLab->>GitLabAPI: GET users?username=username
    GitLabAPI-->>GitLab: users
    GitLab->>GitLabAPI: GET projects for user (paginated)
    GitLabAPI-->>GitLab: allProjects
    loop For each project
        GitLab->>GitLabAPI: GET merge requests for project
        GitLabAPI-->>GitLab: project merge requests
        GitLab->>GitLabAPI: GET issues for project
        GitLabAPI-->>GitLab: project issues
        GitLab->>GitLabAPI: GET commits for project (author_name, since, until)
        GitLabAPI-->>GitLab: project commits
        GitLab->>GitLab: Append project metadata to commits
        GitLab->>GitLab: Small delay to avoid rate limiting
    end
    GitLab->>GitLab: Build gitlabData { user, projects, mergeRequests, issues, commits, comments }
    GitLab-->>Scrum: gitlabData

    Scrum->>Scrum: Map issues to githubIssuesData.items
    Scrum->>Scrum: Map mergeRequests to githubPrsReviewData.items
    Scrum->>Scrum: Map commits to gitlabCommits (standard commit format)
    Scrum->>Writer: writeGithubIssuesPrs(githubIssuesData.items)
    Scrum->>Writer: writeGithubIssuesPrs(githubPrsReviewData.items)
    alt gitlabCommits not empty
        Scrum->>Writer: writeGithubIssuesPrs(githubCommitsData)
    end
    Scrum-->>Popup: Scrum body ready
Loading

Sequence diagram for real-time custom date input validation

sequenceDiagram
    actor User
    participant Popup
    participant Validation as validateDateRange
    participant I18n as chrome_i18n
    participant Toast as Materialize_toast

    User->>Popup: Type into startingDate input
    Popup->>Popup: browser.storage.local.set({ startingDate })
    Popup->>Popup: Read yesterdayContribution radio
    alt Custom date range selected
        Popup->>Popup: Read startingDate and endingDate
        alt Both dates present
            Popup->>Validation: validateDateRange(startDate, endDate)
            Validation-->>Popup: isValid
            alt Invalid
                Popup->>I18n: getMessage(invalidDateRangeError)
                I18n-->>Popup: localizedMessage or null
                alt Materialize available
                    Popup->>Toast: toast(message, 4000, red)
                else Fallback
                    Popup->>User: alert(message)
                end
            else Valid
                Popup-->>User: No error shown
            end
        else Only one date present
            Popup-->>User: Wait for other date
        end
    else Yesterday preset selected
        Popup-->>User: No custom date validation
    end

    User->>Popup: Type into endingDate input
    Popup->>Popup: browser.storage.local.set({ endingDate })
    Popup->>Popup: Repeat same validation logic as for startingDate
Loading

Class diagram for GitLab data and commit mapping structures

classDiagram
    class GitLabHelper {
        - baseUrl
        - token
        + fetchUserAndProjectData(username, startDate, endDate)
        + buildGitlabData(users, allProjects, allMergeRequests, allIssues, allCommits)
        + processCachedData(data)
    }

    class GitlabProject {
        + id
        + name
        + web_url
    }

    class GitlabCommitRaw {
        + id
        + message
        + title
        + web_url
        + committed_date
    }

    class GitlabCommitWithProject {
        + id
        + message
        + title
        + web_url
        + committed_date
        + project_id
        + project_name
        + project_url
    }

    class GitlabData {
        + user
        + projects
        + mergeRequests
        + issues
        + commits
        + comments
    }

    class ProcessedGitlabData {
        + mergeRequests
        + issues
        + commits
        + comments
        + user
    }

    class MappedCommitForReport {
        + message
        + html_url
        + sha
        + project
        + author_name
        + author_email
    }

    class ScrumHelper_allIncluded {
        + githubIssuesData
        + githubPrsReviewData
        + githubCommitsData
        + allIncluded(outputTarget)
        + mapGitLabItem(item, projects, type)
    }

    class DateValidation {
        + validateDateRange(startDate, endDate)
        + showDateValidationError(message)
    }

    GitLabHelper "1" --> "*" GitlabProject : uses
    GitLabHelper "1" --> "*" GitlabCommitRaw : fetches
    GitLabHelper "1" --> GitlabData : builds
    GitLabHelper "1" --> ProcessedGitlabData : processes

    GitlabCommitRaw <|-- GitlabCommitWithProject
    GitlabData --> "*" GitlabCommitWithProject : contains
    ProcessedGitlabData --> "*" GitlabCommitWithProject : contains

    ScrumHelper_allIncluded --> GitLabHelper : calls
    ScrumHelper_allIncluded --> "*" MappedCommitForReport : creates
    GitlabCommitWithProject --> MappedCommitForReport : maps to

    ScrumHelper_allIncluded --> DateValidation : uses for date checks
Loading

File-Level Changes

Change Details Files
Add reusable date range validation and error-display helpers, and wire them into report generation and date input change handlers in the popup.
  • Introduce validateDateRange(startDate, endDate) utility that safely compares parsed dates while deferring empty/invalid values to existing validation paths
  • Add showDateValidationError(message) helper that prefers Materialize toast with a red style and falls back to alert
  • Update Generate Report click handler to validate custom date ranges (excluding the Yesterday preset) before starting report generation, using a localized invalidDateRangeError message when available
  • Add real-time validation in starting/ending date input listeners for custom ranges, showing a toast error when the user selects startDate after endDate
src/scripts/popup.js
Extend GitLab support to include per-project commits in fetched data and in the generated scrum report output.
  • Track githubCommitsData alongside existing GitLab issue and MR data in the allIncluded() flow
  • Map GitLab commits into a GitHub-like shape (message, html_url, sha, project, author metadata) for reuse by existing report writers
  • Include mapped GitLab commits when generating the GitLab section of the report via writeGithubIssuesPrs()
  • Fetch commits per GitLab project over the selected date range using the REST API, with author_name filter, pagination params, and a small delay between projects to reduce rate limiting
  • Augment cached/processed GitLab data structures to carry a commits array through to downstream consumers
src/scripts/scrumHelper.js
src/scripts/gitlabHelper.js
Update documentation and localization to reflect GitLab support and expose a new invalid date range error message.
  • Revise README feature list to call out multi-platform support (GitHub and GitLab) and add a roadmap section describing GitLab support and upcoming Gitea/analytics work
  • Add a new invalidDateRangeError i18n string in the English locale for the date validation toast (exact content not shown in diff)
  • Adjust Biome configuration file (details not shown)
README.md
src/_locales/en/messages.json
biome.json

Assessment against linked issues

Issue Objective Addressed Explanation
#572 Add validation to prevent generating a scrum report when the custom start date is after the end date.
#572 Display a clear validation error message (instead of "No activity to report") when the user selects an invalid date range.

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 documentation config labels Apr 21, 2026
Copy link
Copy Markdown
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 - I've found 1 issue, and left some high level feedback:

  • In scrumHelper.js, githubCommitsData is only populated in the non-cached GitLab path; when data is loaded from cache you only pass gitlabCommits via mappedData and never assign githubCommitsData, so the later writeGithubIssuesPrs(githubCommitsData) for GitLab will be skipped—consider aligning the cache and non-cache paths so commits are always written consistently.
  • The real-time date validation in popup.js triggers a toast on every invalid keystroke, which may result in repeated, noisy notifications; consider debouncing this feedback or only showing the toast when the user finishes editing (e.g., on blur) or when the range transitions from valid to invalid.
  • The commit mapping logic for GitLab in scrumHelper.js is duplicated in two branches; extracting a small helper (e.g., mapGitlabCommits(data.commits)) would reduce repetition and make it easier to keep both paths in sync.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `scrumHelper.js`, `githubCommitsData` is only populated in the non-cached GitLab path; when data is loaded from cache you only pass `gitlabCommits` via `mappedData` and never assign `githubCommitsData`, so the later `writeGithubIssuesPrs(githubCommitsData)` for GitLab will be skipped—consider aligning the cache and non-cache paths so commits are always written consistently.
- The real-time date validation in `popup.js` triggers a toast on every invalid keystroke, which may result in repeated, noisy notifications; consider debouncing this feedback or only showing the toast when the user finishes editing (e.g., on blur) or when the range transitions from valid to invalid.
- The commit mapping logic for GitLab in `scrumHelper.js` is duplicated in two branches; extracting a small helper (e.g., `mapGitlabCommits(data.commits)`) would reduce repetition and make it easier to keep both paths in sync.

## Individual Comments

### Comment 1
<location path="src/scripts/gitlabHelper.js" line_range="178" />
<code_context>
+			let allCommits = [];
+			for (const project of allProjects) {
+				try {
+					const projectCommitsUrl = `${this.baseUrl}/projects/${project.id}/repository/commits?author_name=${username}&since=${startDate}T00:00:00Z&until=${endDate}T23:59:59Z&per_page=100&order_by=committed_date&sort=desc`;
+					const projectCommitsRes = await fetch(projectCommitsUrl, { headers });
+					if (projectCommitsRes.ok) {
</code_context>
<issue_to_address>
**issue (bug_risk):** URL-encode query parameters when building the commits URL.

Directly interpolating `username`, `startDate`, and `endDate` into the query can break requests when they contain spaces or special characters. Wrap each in `encodeURIComponent(...)` before building the URL to ensure valid, robust requests.
</issue_to_address>

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 thread src/scripts/gitlabHelper.js
@AyushBurde
Copy link
Copy Markdown

@SinghCharanjeet11 hey!! Great observation but this issue is already considered earlier, you can check here #573

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config core documentation javascript Pull requests that update javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] when start date is greater than end date, scrum report should throw an error

2 participants