Skip to content

Added seperate labels for PR made #165

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 3 commits into
base: master
Choose a base branch
from

Conversation

Preeti9764
Copy link
Contributor

@Preeti9764 Preeti9764 commented Jun 24, 2025

📌 Fixes

Fixes #160


📝 Summary of Changes

  • Added seperate labels for merged and closed prs.
  • 3 types of label:
    1. Open PR
    2. Merged PR
    3. Closed PR

📸 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

These labels are there for users made pr not for their reviewed prs.

Summary by Sourcery

Add separate labels for PRs based on open, merged, or closed status and fetch merged state via GitHub API for accurate labeling.

New Features:

  • Introduce distinct labels for open, merged, and closed pull requests
  • Fetch merged status of PRs from GitHub API to display the correct label

Enhancements:

  • Add getDaysBetween and fetchPrMergedStatus helper functions
  • Convert writeGithubIssuesPrs to async and await interval calls to support API queries
  • Implement fallback logic with a toast notification on API errors or rate limits
  • Use a 14-day threshold to decide when to call the GitHub API for merged status

Copy link
Contributor

sourcery-ai bot commented Jun 24, 2025

Reviewer's Guide

Refactors scrumHelper.js to introduce distinct “merged” and “closed” PR labels and dynamically fetch real merge status from GitHub for PRs made, updating label logic and asynchronous handling accordingly.

Sequence diagram for fetching and displaying PR merged/closed labels

sequenceDiagram
    participant User
    participant scrumHelper
    participant GitHubAPI

    User->>scrumHelper: Trigger PR display (e.g., open popup)
    scrumHelper->>scrumHelper: Determine if PR is closed
    alt PR is closed and within 14 days
        scrumHelper->>GitHubAPI: fetch PR details (merged status)
        GitHubAPI-->>scrumHelper: Return PR merged status
        alt PR is merged
            scrumHelper->>User: Show 'merged' label
        else PR is closed but not merged
            scrumHelper->>User: Show 'closed' label
        end
    else PR is open
        scrumHelper->>User: Show 'open' label
    end
Loading

Class diagram for updated PR label logic in scrumHelper.js

classDiagram
    class scrumHelper {
        +allIncluded(outputTarget)
        +getChromeData()
        +getDaysBetween(start, end)
        +fetchPrMergedStatus(owner, repo, number, headers)
        +writeGithubIssuesPrs()
    }

    scrumHelper : +pr_merged_true_button
    scrumHelper : +pr_merged_false_button
    scrumHelper : +issue_opened_button
    scrumHelper : +issue_closed_button
    scrumHelper : +pr_unmerged_button

    scrumHelper : +githubIssuesData
    scrumHelper : +githubToken
    scrumHelper : +intervalWriteGithubIssues

    scrumHelper --> fetchPrMergedStatus : uses
    scrumHelper --> getDaysBetween : uses
    scrumHelper --> writeGithubIssuesPrs : uses
Loading

File-Level Changes

Change Details Files
Separate label markup for merged and closed PRs
  • Declared pr_merged_true_button and pr_merged_false_button elements with unique colors
  • Replaced generic merged/closed button usage in PR rendering
  • Removed closed label display for reviewed PRs
src/scripts/scrumHelper.js
Helpers to determine actual merge status
  • Added getDaysBetween to compute date ranges
  • Added fetchPrMergedStatus to call GitHub’s PR API and return merge state
src/scripts/scrumHelper.js
Async PR-listing logic with merge-status fetch and fallback
  • Made writeGithubIssuesPrs async to await API results
  • Conditionally fetch merge status for closed PRs when within 14 days
  • Fallback to original label with a toast on API rate limit or error
src/scripts/scrumHelper.js
Updated interval polling to support async rendering
  • Changed setInterval callback to async
  • Awaited writeGithubIssuesPrs calls in both popup and email flows
src/scripts/scrumHelper.js

Assessment against linked issues

Issue Objective Addressed Explanation

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

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 @Preeti9764 - I've reviewed your changes - here's some feedback:

  • I noticed references to pr_unmerged_button and pr_merged_button in writeGithubIssuesPrs, but only pr_merged_true_button and pr_merged_false_button are defined; please unify your button variable names or define the missing ones to avoid reference errors.
  • Fetching each PR’s merged status sequentially in a loop can trigger rate limits and slow down the report—consider batching these requests (e.g. via the GraphQL API) or caching results to reduce API calls.
  • Since setInterval doesn’t await promises, any errors in your async callback may be unhandled—wrap the interval handler in try/catch or switch to an async-aware scheduling approach.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- I noticed references to pr_unmerged_button and pr_merged_button in writeGithubIssuesPrs, but only pr_merged_true_button and pr_merged_false_button are defined; please unify your button variable names or define the missing ones to avoid reference errors.
- Fetching each PR’s merged status sequentially in a loop can trigger rate limits and slow down the report—consider batching these requests (e.g. via the GraphQL API) or caching results to reduce API calls.
- Since setInterval doesn’t await promises, any errors in your async callback may be unhandled—wrap the interval handler in try/catch or switch to an async-aware scheduling approach.

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 +705 to +709
function getDaysBetween(start, end) {
const d1 = new Date(start);
const d2 = new Date(end);
return Math.ceil((d2 - d1) / (1000 * 60 * 60 * 24));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

Comment on lines 712 to 722
async function fetchPrMergedStatus(owner, repo, number, headers) {
const url = `https://api.github.com/repos/${owner}/${repo}/pulls/${number}`;
try {
const res = await fetch(url, { headers });
if (!res.ok) return null;
const data = await res.json();
return data.merged_at ? true : false;
} catch (e) {
return null;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

const res = await fetch(url, { headers });
if (!res.ok) return null;
const data = await res.json();
return data.merged_at ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Avoid unneeded ternary statements (simplify-ternary)

Suggested change
return data.merged_at ? true : false;
return !!data.merged_at;


ExplanationIt is possible to simplify certain ternary statements into either use of an || or !.
This makes the code easier to read, since there is no conditional logic.

@hpdang
Copy link
Member

hpdang commented Jun 24, 2025

@Preeti9764 I only get the merged label on the generated report screen, but not the compose window in Gmail.

@Preeti9764
Copy link
Contributor Author

Preeti9764 commented Jun 24, 2025

@Preeti9764 I only get the merged label on the generated report screen, but not the compose window in Gmail.

@hpdang let me check this and make other changes too as suggested by sourcery- ai . Thanks for feedback!

@Preeti9764
Copy link
Contributor Author

@hpdang I have made changes and this is my report in gmail inbox
image

@hpdang
Copy link
Member

hpdang commented Jun 24, 2025

@Preeti9764 can we swap the merged and closed color? I think we should follow GitHub standard, purple for merged and red for closed

@hpdang hpdang requested a review from vedansh-5 June 24, 2025 18:27
@mariobehling
Copy link
Member

Please use the colors as in the below table.

In the example please also demonstrate that the draft stage is working as expected.

PR State Label Text Color Example Label UI
Open Open 🟢 Green Open
Merged Merged 🟣 Purple Merged
Closed Closed 🔴 Red Closed
Draft Draft ⚪ Light Gray Draft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Differentiate Between "Closed" and "Merged" Pull Requests
3 participants