Skip to content

Refactor/utils.js#520

Open
DineshThumma9 wants to merge 6 commits intofossasia:mainfrom
DineshThumma9:refactor/utils.js
Open

Refactor/utils.js#520
DineshThumma9 wants to merge 6 commits intofossasia:mainfrom
DineshThumma9:refactor/utils.js

Conversation

@DineshThumma9
Copy link
Copy Markdown

@DineshThumma9 DineshThumma9 commented Apr 5, 2026

📌 Fixes

Fixes # (Use "Fixes", "Closes", or "Resolves" for automatic closing)

Fixes: #519

📝 Summary of Changes

  • Short description of what was changed
  • Include links to related issues/discussions if any
    Refactor codebase reduce duplication and introduce utils.js for helper/utils functions

📸 Screenshots / Demo (if UI-related)

Add screenshots, video, or link to deployed preview if applicable


✅ 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

👀 Reviewer Notes

Add any special notes for the reviewer here

Summary by Sourcery

Extract shared date/subject formatting and GitLab item mapping logic into a new reusable utils module and update existing scripts to use it.

Enhancements:

  • Introduce a shared utils.js module exposing date helpers, scrum email subject generation, and GitLab item mapping utilities via window.scrumUtils.
  • Refactor scrumHelper, popup, and main scripts to rely on the new utils helpers for date handling, subject construction, and GitLab mapping, reducing duplication.
  • Tidy up code style and formatting in several scripts for consistency.

Copilot AI review requested due to automatic review settings April 5, 2026 14:40
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 5, 2026

Reviewer's Guide

Refactors duplicated date and GitLab mapping logic into a shared utils module (scripts/utils.js), wires it into popup/main/scrum helper flows, and performs minor formatting/consistency cleanups, without changing core behavior.

Sequence diagram for building Scrum subject using scrumUtils

sequenceDiagram
    actor User
    participant Popup as popup_js
    participant scrumUtils
    participant EmailAdapter as emailClientAdapter

    User->>Popup: trigger report generation
    Popup->>Popup: read projectName from input
    Popup->>scrumUtils: buildScrumSubject(projectName)
    scrumUtils-->>Popup: subject
    Popup->>EmailAdapter: sendReport(subject)
    EmailAdapter-->>User: report composed with standardized subject
Loading

Sequence diagram for yesterdayContribution date handling with scrumUtils

sequenceDiagram
    actor User
    participant Popup as popup_js
    participant scrumUtils
    participant Storage as browser_storage

    User->>Popup: select yesterdayContribution timeframe
    Popup->>scrumUtils: getYesterdayDateString()
    scrumUtils-->>Popup: yyyy_mm_dd_yesterday
    Popup->>scrumUtils: getTodayDateString()
    scrumUtils-->>Popup: yyyy_mm_dd_today
    Popup->>Popup: set startDateInput and endDateInput
    Popup->>Popup: set inputs readOnly
    Popup->>Storage: save yesterdayContribution flag
Loading

Class diagram for new scrumUtils module and consumers

classDiagram
    class scrumUtils {
      +getTodayDateString(now)
      +getYesterdayDateString(now)
      +getScrumDateCode(now)
      +buildScrumSubject(projectName, now)
      +mapGitLabItem(item, projects, type)
    }

    class scrumHelper_js {
      +allIncluded(outputTarget)
      +renderErrorMessage(container, key, fallback, args)
      +handleYesterdayContributionChange()
      +processGithubData(mappedData, isGitLab, subjectForEmail)
    }

    class popup_js {
      +buildScrumSubjectFromPopup()
      +toggleRadio(radio)
      +setupButtonTooltips()
      +applyI18n()
    }

    class main_js {
      +handleYesterdayContributionChange()
      +handlePlatformUsernameChange()
    }

    class gitlabHelper_js {
      +fetchGitLabData(username, startingDate, endingDate, gitlabToken)
    }

    scrumHelper_js ..> scrumUtils : uses getTodayDateString
    scrumHelper_js ..> scrumUtils : uses getYesterdayDateString
    scrumHelper_js ..> scrumUtils : uses buildScrumSubject
    scrumHelper_js ..> scrumUtils : uses mapGitLabItem

    popup_js ..> scrumUtils : uses getTodayDateString
    popup_js ..> scrumUtils : uses getYesterdayDateString
    popup_js ..> scrumUtils : uses buildScrumSubject

    main_js ..> scrumUtils : uses getTodayDateString
    main_js ..> scrumUtils : uses getYesterdayDateString

    gitlabHelper_js ..> scrumUtils : no direct use
Loading

File-Level Changes

Change Details Files
Introduce shared scrum utilities module and use it for date handling and scrum subject generation.
  • Add scripts/utils.js exposing scrumUtils with date helpers (today/yesterday/date code), scrum subject builder, and GitLab item mapping.
  • Replace local getToday/getYesterday helpers in scrumHelper.js, popup.js, and main.js with scrumUtils.getTodayDateString/getYesterdayDateString.
  • Replace duplicated subject-building logic in scrumHelper.js and popup.js with scrumUtils.buildScrumSubject.
src/scripts/utils.js
src/scripts/scrumHelper.js
src/scripts/popup.js
src/scripts/main.js
src/popup.html
Centralize GitLab item mapping logic for issues and merge requests.
  • Extract GitLab item mapping into scrumUtils.mapGitLabItem to create normalized items with repository_url/html_url/project/pull_request fields.
  • Update scrumHelper.js GitLab fetch paths to use scrumUtils.mapGitLabItem instead of inline mapGitLabItem definitions.
src/scripts/utils.js
src/scripts/scrumHelper.js
Wire new utilities into popup and improve minor formatting and error-message consistency.
  • Include scripts/utils.js in popup.html before main logic scripts.
  • Adjust popup caching logic and repo filter helpers only stylistically (whitespace, line wrapping) while keeping behavior intact.
  • Reformat various long error messages and logs across scrumHelper.js, popup.js, and gitlabHelper.js for readability without semantic changes.
src/popup.html
src/scripts/popup.js
src/scripts/scrumHelper.js
src/scripts/gitlabHelper.js

Assessment against linked issues

Issue Objective Addressed Explanation
#519 Introduce a shared utils.js module that centralizes helper logic (including date-related helpers for fetching today/yesterday and other common helpers).
#519 Refactor existing duplicated logic (e.g., date handling, GitLab item mapping, scrum subject building) to use the new utilities module, reducing duplication and responsibilities in other files.

Possibly linked issues

  • Reactor and Reduce Duplications #519: PR introduces utils.js with shared GitLab mapping and date/subject helpers, partially modularizing scrumHelper as requested.
  • #(unassigned): PR introduces utils.js and refactors duplicated date and GitLab mapping logic, directly addressing the requested refactor/utilities.

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

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 left some high level feedback:

  • In utils.js, mapGitLabItem hardcodes the GitLab API base URL (https://gitlab.com/api/v4/...), which diverges from the configurable baseUrl used in GitLabHelper; consider wiring mapGitLabItem to use the same base or accept it as a parameter so self‑hosted GitLab instances work consistently.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `utils.js`, `mapGitLabItem` hardcodes the GitLab API base URL (`https://gitlab.com/api/v4/...`), which diverges from the configurable `baseUrl` used in `GitLabHelper`; consider wiring `mapGitLabItem` to use the same base or accept it as a parameter so self‑hosted GitLab instances work consistently.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors common date/subject formatting and GitLab item mapping logic into a shared utils.js, then updates the popup and content-script codepaths to use these shared helpers to reduce duplication (Fixes #519).

Changes:

  • Added src/scripts/utils.js exposing shared helpers under window.scrumUtils.
  • Replaced duplicated “today/yesterday”, scrum subject building, and GitLab item mapping logic in popup.js, main.js, and scrumHelper.js with scrumUtils calls.
  • Ensured utils.js is loaded in popup.html and added to Chrome/Firefox manifest content scripts; minor formatting cleanups in several files.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/scripts/utils.js Introduces shared date/subject helpers and a centralized GitLab item mapping function.
src/scripts/scrumHelper.js Uses scrumUtils for GitLab mapping, subject generation, and date helpers; formatting-only changes in several places.
src/scripts/popup.js Removes local date helpers and uses scrumUtils for “yesterday/today” and subject generation; formatting tweaks.
src/scripts/main.js Uses scrumUtils for “yesterday/today” date values instead of local helper functions.
src/scripts/gitlabHelper.js Line-wrapping/formatting adjustments to thrown error construction.
src/popup.html Loads scripts/utils.js before scripts that reference window.scrumUtils.
src/manifests/chrome.json Adds scripts/utils.js to content script list before scrumHelper.js.
src/manifests/firefox.json Adds scripts/utils.js to content script list before scrumHelper.js.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/scripts/utils.js
Comment thread src/scripts/scrumHelper.js
Copilot AI review requested due to automatic review settings April 11, 2026 11:11
Copy link
Copy Markdown
Member

@mariobehling mariobehling left a comment

Choose a reason for hiding this comment

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

Please address AI reviews or comment if not relevant.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/scripts/utils.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 11, 2026 14:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/scripts/utils.js
@DineshThumma9
Copy link
Copy Markdown
Author

@mariobehling
Initially, I hastily committed a fix that changed formatDateToIsoDay to use local getters (getFullYear/getMonth/getDate) to match getScrumDateCode. Upon again requesting review Copilot then raised a new problem — that those local date strings were being fed into UTC boundaries in scrumHelper.js (e.g., new Date(startDate + 'T00:00:00Z')).

On closer review, I found that the original functions in main.js (getToday, getYesterday) already used toISOString() (UTC), and scrumHelper.js also interprets date strings as UTC boundaries (e.g. new Date(startDate + 'T00:00:00Z')).

So mixing local getters with toISOString() output was actually a pre-existing inconsistency. I've fixed this by moving fully to UTC throughout utils.js:

Before (mixed):

yesterday.setDate(today.getDate() - 1);        // local arithmetic
return yesterday.toISOString().split('T')[0];  // UTC output ← mismatch

After (consistent UTC):


yesterday.setUTCDate(today.getUTCDate() - 1);  // UTC arithmetic
return yesterday.toISOString().split('T')[0];  // UTC output

This also applies to getScrumDateCode, which now uses getUTCFullYear/Month/Date for the same reason.

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

Labels

core extension frontend javascript Pull requests that update javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reactor and Reduce Duplications

3 participants