Skip to content

Conversation

@Anshumancanrock
Copy link
Contributor

@Anshumancanrock Anshumancanrock commented Dec 12, 2025

📌 Fixes

Fixes #272


📝 Summary of Changes

Problem

The click event listener for handling links within #scrumReport was defined inside the validateOrgOnBlur() function. Since this function runs every time the organization input field loses focus, the event listener was being re-attached repeatedly, leading to:

Solution

Moved the event listener registration from inside validateOrgOnBlur() to the DOMContentLoaded handler, ensuring it's attached only once when the page loads.

The listener uses event delegation with e.target.closest('a') to handle clicks on any link within #scrumReport, whether the link exists at page load or is dynamically generated later. This pattern is both efficient and works correctly for dynamic content.


📸 Screenshots / Demo (if UI-related)

  • After Fix:
Recording.2025-12-12.152604.mp4

✅ 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

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 12, 2025

Reviewer's Guide

Enables PR numbers and titles in the scrum report to be clickable links that open the corresponding GitHub/GitLab PR in a new tab from the extension popup, including necessary DOM event handling, CSS tweaks, and updated Chrome extension permissions.

Sequence diagram for opening PR links from the scrum report popup

sequenceDiagram
    actor User
    participant PopupDOM as PopupScrumReportDOM
    participant ClickHandler as PopupClickHandler
    participant ChromeTabs as ChromeTabsAPI
    participant Browser as BrowserNewTab
    participant GitHost as GitHubOrGitLab

    User->>PopupDOM: Click PR number or title link
    PopupDOM->>ClickHandler: Capture click event (capturing phase)
    ClickHandler->>ClickHandler: Check closest a inside scrumReport
    alt Valid HTTP link
        ClickHandler-->>PopupDOM: preventDefault and stopPropagation
        ClickHandler->>ChromeTabs: tabs.create url
        ChromeTabs->>Browser: Open new tab with PR URL
        Browser->>GitHost: Request PR page
        GitHost-->>Browser: Return PR HTML
        Browser-->>User: Display PR details in new tab
    else No or non HTTP href
        ClickHandler-->>PopupDOM: Do nothing
    end
Loading

Flow diagram for rendering and interacting with PR links in scrum report

flowchart TD
    A[Fetch PR data from GitHub GitLab] --> B[ScrumHelperJS builds list item HTML]
    B --> C{PR state}
    C -->|draft open closed merged| D[Render PR number as a link<br/>href html_url<br/>target _blank<br/>contenteditable false]
    D --> E[Render PR title as a link<br/>href html_url<br/>target _blank<br/>contenteditable false]
    E --> F[Insert list item into scrumReport container]
    F --> G[CSS sets scrumReport links as read only and unselectable]
    G --> H[User clicks PR number or title]
    H --> I[popup.js click listener on document<br/>filters for links inside scrumReport]
    I --> J{href starts with http}
    J -->|yes| K[Prevent default and stop propagation]
    K --> L[chrome.tabs.create with PR URL]
    L --> M[New browser tab opens PR page]
    J -->|no| N[No special handling]
Loading

File-Level Changes

Change Details Files
Make PR numbers clickable links alongside PR titles across all PR states.
  • Wrap the PR number text in an anchor pointing to the PR URL for draft, open, closed, and merged states.
  • Add target="_blank" to PR number and title links so they open in a new tab.
  • Mark PR number and title links as contenteditable="false" to avoid interference with editable content.
src/scripts/scrumHelper.js
Ensure link clicks inside the scrum report open in new tabs via the Chrome extension API instead of the default popup navigation.
  • Register a capturing click event listener on document that finds anchor clicks within #scrumReport.
  • Prevent default navigation and event propagation for those clicks.
  • Use chrome.tabs.create({ url }) to open valid http(s) links in a new tab.
src/scripts/popup.js
Prevent contentEditable behavior from interfering with links in the scrum report.
  • Add CSS for #scrumReport a to make anchors effectively read-only and avoid user modification/selection issues.
src/index.css
Grant the extension permission to create new tabs when PR links are clicked.
  • Add the "tabs" permission to the Chrome extension manifest, keeping existing permissions intact.
src/manifest.json

Assessment against linked issues

Issue Objective Addressed Explanation
#272 Convert each PR entry in the Scrum report UI into a clickable hyperlink that navigates to the corresponding GitHub/GitLab PR page.
#272 Ensure that clicking a PR entry opens the PR in a new browser tab while preserving the existing UI styling and usability.

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 frontend labels Dec 12, 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 there - I've reviewed your changes and found some issues that need to be addressed.

  • The global document.addEventListener('click', ..., true) with stopImmediatePropagation() may be heavier than needed; consider attaching the handler directly to #scrumReport or its container and avoiding stopImmediatePropagation unless you have a concrete conflict to resolve.
  • Setting user-select: none on #scrumReport a prevents users from copying PR titles/links; consider relaxing this (e.g., only disabling editing via CSS, not text selection) to preserve normal copy behavior.
  • For the new target="_blank" links, consider adding rel="noopener noreferrer" to avoid giving the opened page access to the window.opener object.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The global `document.addEventListener('click', ..., true)` with `stopImmediatePropagation()` may be heavier than needed; consider attaching the handler directly to `#scrumReport` or its container and avoiding `stopImmediatePropagation` unless you have a concrete conflict to resolve.
- Setting `user-select: none` on `#scrumReport a` prevents users from copying PR titles/links; consider relaxing this (e.g., only disabling editing via CSS, not text selection) to preserve normal copy behavior.
- For the new `target="_blank"` links, consider adding `rel="noopener noreferrer"` to avoid giving the opened page access to the `window.opener` object.

## Individual Comments

### Comment 1
<location> `src/scripts/popup.js:1603-1612` </location>
<code_context>
         });
+
+    // Handle clicks on links within scrumReport to open in new tabs
+    document.addEventListener('click', function(e) {
+        const target = e.target.closest('a');
+        if (target && target.closest('#scrumReport')) {
+            e.preventDefault();
+            e.stopPropagation();
+            e.stopImmediatePropagation();
+            const href = target.getAttribute('href');
+            if (href && href.startsWith('http')) {
+                chrome.tabs.create({ url: href });
+            }
+            return false;
+        }
+    }, true); // Use capture phase to handle before contentEditable
 }
\ No newline at end of file
</code_context>

<issue_to_address>
**issue (bug_risk):** Avoid attaching a new document-level click handler every time this code path runs.

Since this listener is defined in this scope, it will be re-registered each time this block runs, causing duplicate click handlers and repeated work. Please move the `addEventListener` to a place that runs once (e.g., module init) or add a guard so it’s only attached a single time.
</issue_to_address>

### Comment 2
<location> `src/scripts/scrumHelper.js:1466-1469` </location>
<code_context>
                 if (isDraft) {

-                    li = `<li><i>(${project})</i> - Made PR (#${number}) - <a href='${html_url}'>${title}</a>${showOpenLabel ? ' ' + pr_draft_button : ''}`;
+                    li = `<li><i>(${project})</i> - Made PR <a href='${html_url}' target='_blank' contenteditable='false'>(#${number})</a> - <a href='${html_url}' target='_blank' contenteditable='false'>${title}</a>${showOpenLabel ? ' ' + pr_draft_button : ''}`;
                     if (showCommits && item._allCommits && item._allCommits.length && !isNewPR) {
                         log(`[PR DEBUG] Rendering commits for existing draft PR #${number}:`, item._allCommits);
</code_context>

<issue_to_address>
**🚨 issue (security):** Opening links with `target="_blank"` without `rel` attributes can introduce a tabnabbing risk.

Please add `rel="noopener noreferrer"` to these `target="_blank"` links so the new tab cannot access `window.opener` and to mitigate reverse tabnabbing, especially since these URLs point to external PR/MR pages.
</issue_to_address>

### Comment 3
<location> `src/index.css:61-64` </location>
<code_context>
     color: #3f51b5;
 }

+#scrumReport a {
+    -webkit-user-modify: read-only;
+    user-select: none;
+}
+
</code_context>

<issue_to_address>
**suggestion:** Using `user-select: none` on links under `#scrumReport` may be unnecessarily restrictive for users.

This prevents users from copying PR titles or URLs from the report, which is likely useful behavior. Since `contenteditable='false'` plus the JS handler already guard against edits, consider removing `user-select: none` here or applying it only to elements where accidental selection is actually a problem.

```suggestion
#scrumReport a {
    -webkit-user-modify: read-only;
}
```
</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.

@Anshumancanrock
Copy link
Contributor Author

@vedansh-5 could you please review this pr ser? Thank

@Anshumancanrock Anshumancanrock changed the title feat: Make PR numbers clickable with links to GitHub feat: Make PRs and PR numbers clickable with links to GitHub Dec 12, 2025
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.

Add Clickable Links to Pull Requests in the Scrum Report.

1 participant