Skip to content

Check box state handling when token not present#384

Open
Mateeb-Haider wants to merge 4 commits intofossasia:mainfrom
Mateeb-Haider:feat/require-token-for-show-commits
Open

Check box state handling when token not present#384
Mateeb-Haider wants to merge 4 commits intofossasia:mainfrom
Mateeb-Haider:feat/require-token-for-show-commits

Conversation

@Mateeb-Haider
Copy link
Contributor

@Mateeb-Haider Mateeb-Haider commented Feb 19, 2026

📌 Fixes

Closes #313


📝 Summary of Changes

  • Added token enforcement for "Show commits on open PRs/draft PRs" so it cannot remain enabled without a GitHub token.
  • Added warning UI when users try enabling "Show commits" without a token, matching existing "Enable filtering" behavior.
  • Added validation during popup initialization and token input updates to auto-correct invalid stored states.
  • Added English i18n key for the new warning message.

Related issue: #313


📸 Screenshots / Demo (if UI-related)

Screencast.from.2026-02-19.23-55-42.webm

✅ Checklist

  • I’ve tested my changes locally
  • My code follows the project’s code style guidelines

👀 Reviewer Notes

  • UI/UX consistency fix only; no API contract changes.
  • Behavior now aligns with existing token-gated filtering flow.

Summary by Sourcery

Enforce GitHub token requirements for the "Show commits" option in the popup and align its UX with existing token-gated behaviors.

Bug Fixes:

  • Prevent the "Show commits" checkbox from remaining enabled when no GitHub token is configured, including on initialization and settings updates.

Enhancements:

  • Display a contextual warning message and animation when users attempt to enable "Show commits" without a GitHub token, mirroring the existing filtering warning UX.

Documentation:

  • Add an English i18n message for the new token requirement warning for the "Show commits" option.

Copilot AI review requested due to automatic review settings February 19, 2026 18:58
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 19, 2026

Reviewer's Guide

Enforces that the "Show commits on open/draft PRs" option is disabled when no GitHub token is present, adds matching token-warning UI/behavior, wires that validation into popup initialization and token input changes, and performs a small refactor of a repo filtering callback for readability.

Sequence diagram for token-gated ShowCommits toggle behavior

sequenceDiagram
    actor User
    participant Popup as PopupUI
    participant DOM as DOMElements
    participant Storage as ChromeStorage

    User->>Popup: Open_extension_popup
    Popup->>Storage: get(darkMode, showCommits, githubToken, ...)
    Storage-->>Popup: Settings_state
    Popup->>DOM: initializePopup()
    Popup->>DOM: checkTokenForFilter()
    Popup->>DOM: checkTokenForShowCommits()
    DOM->>DOM: evaluate showCommits.checked and githubTokenInput.value
    alt showCommits enabled and no token
        DOM->>DOM: uncheck showCommits
        DOM->>Storage: set({showCommits: false})
        DOM->>DOM: hide tokenWarningForShowCommits
    else showCommits disabled or has token
        DOM->>DOM: toggle tokenWarningForShowCommits(hidden)
    end

    User->>DOM: type_in_githubTokenInput
    DOM->>DOM: checkTokenForFilter()
    DOM->>DOM: checkTokenForShowCommits()
    DOM->>DOM: recompute hasToken and warning_visibility

    User->>DOM: click showCommitsCheckbox(change)
    DOM->>DOM: hasToken = githubTokenInput.value.trim() !== ''
    alt checkbox checked and no token
        DOM->>DOM: uncheck showCommitsCheckbox
        DOM->>DOM: show tokenWarningForShowCommits
        DOM->>DOM: add shake-animation class
        DOM->>DOM: remove shake-animation after 620ms
        DOM->>DOM: hide tokenWarningForShowCommits after 3000ms
        DOM->>Storage: set({showCommits: false})
    else checkbox state valid
        DOM->>Storage: set({showCommits: showCommitsCheckbox.checked})
    end
Loading

File-Level Changes

Change Details Files
Enforce token requirement for the "Show commits" feature and keep stored state consistent.
  • Introduce checkTokenForShowCommits helper that validates the show-commits checkbox against the presence of a GitHub token, auto-unchecks and persists false when enabled without a token, and controls visibility of the token warning banner with an auto-hide timeout.
  • Invoke checkTokenForShowCommits during popup initialization, on token input changes, and after loading platform settings from storage to correct any invalid pre-existing state.
  • On show-commits checkbox change, block enabling when no token exists, briefly display an animated token warning, and only persist the checked state to storage when valid.
src/scripts/popup.js
Add dedicated warning UI and i18n text for the token requirement of the "Show commits" option.
  • Add a token warning container under the Show Commits control, styled consistently with existing warnings and using a new i18n message key for the copy.
  • Define the English localization string tokenRequiredShowCommitsWarning for the new warning text.
src/popup.html
src/_locales/en/messages.json
Minor cleanup of repository filtering callback for readability without changing behavior.
  • Refactor the availableRepos.filter callback from a multi-line function expression to a compact arrow function while preserving the selection and query filtering logic.
src/scripts/popup.js

Assessment against linked issues

Issue Objective Addressed Explanation
#313 Prevent the "Show commits on open PRs/draft PRs" checkbox from being enabled or remaining enabled when no GitHub token is set, including correcting any invalid stored state.
#313 Show a warning message when the user tries to enable the "Show commits" checkbox without a GitHub token, following the same UX pattern as the existing "Enable filtering" checkbox (including appropriate i18n text).

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 - I've found 1 issue, and left some high level feedback:

  • The showCommitsCheckbox change handler reimplements most of the logic already in checkTokenForShowCommits; consider routing both the change event and token input updates through the same helper to avoid duplication and inconsistent behavior.
  • Both checkTokenForShowCommits and the checkbox change handler schedule timeouts to hide the warning; it may be cleaner to centralize the show/hide timing in one place and clear any existing timeout to avoid overlapping or flickering UI states.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `showCommitsCheckbox` change handler reimplements most of the logic already in `checkTokenForShowCommits`; consider routing both the change event and token input updates through the same helper to avoid duplication and inconsistent behavior.
- Both `checkTokenForShowCommits` and the checkbox change handler schedule timeouts to hide the warning; it may be cleaner to centralize the show/hide timing in one place and clear any existing timeout to avoid overlapping or flickering UI states.

## Individual Comments

### Comment 1
<location> `src/scripts/popup.js:681-698` </location>
<code_context>
 			}
 		}
 		showCommitsCheckbox.addEventListener('change', () => {
+			const hasToken = githubTokenInput.value.trim() !== '';
+
+			if (showCommitsCheckbox.checked && !hasToken) {
+				showCommitsCheckbox.checked = false;
+				const tokenWarning = document.getElementById('tokenWarningForShowCommits');
+				if (tokenWarning) {
+					tokenWarning.classList.remove('hidden');
+					tokenWarning.classList.add('shake-animation');
+					setTimeout(() => tokenWarning.classList.remove('shake-animation'), 620);
+					setTimeout(() => {
+						tokenWarning.classList.add('hidden');
+					}, 3000);
+				}
+			}
+
 			chrome?.storage.local.set({ showCommits: showCommitsCheckbox.checked });
 		});
 		githubTokenInput.addEventListener('input', () => {
</code_context>

<issue_to_address>
**suggestion:** Deduplicate the token warning logic between `checkTokenForShowCommits` and the `showCommitsCheckbox` change handler.

This handler now reimplements similar logic with different timing and animation, which risks inconsistent behavior over time. Consider invoking `checkTokenForShowCommits` here (or extracting a shared helper for warning display, duration, and animation) so the UX is defined in one place and easier to maintain.

```suggestion
		showCommitsCheckbox.addEventListener('change', () => {
			// Delegate token validation and warning display to a single place
			if (showCommitsCheckbox.checked) {
				checkTokenForShowCommits();

				// If token validation failed, checkTokenForShowCommits is responsible
				// for restoring the checkbox state and showing any warnings.
				if (!showCommitsCheckbox.checked) {
					chrome?.storage.local.set({ showCommits: false });
					return;
				}
			}

			chrome?.storage.local.set({ showCommits: showCommitsCheckbox.checked });
		});
```
</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.

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

This pull request implements token enforcement for the "Show commits on open PRs/draft PRs" checkbox to prevent users from enabling the feature without a GitHub token, matching the existing pattern used for the repository filtering feature.

Changes:

  • Added checkTokenForShowCommits() function to validate token availability and auto-disable the feature when no token is present
  • Integrated validation checks at initialization, token input changes, and checkbox toggle events
  • Added warning UI element with appropriate styling and i18n support for user feedback

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/scripts/popup.js Implements checkTokenForShowCommits() function, adds event listeners for validation, and includes unrelated code formatting fix for repository filter logic
src/popup.html Adds warning element tokenWarningForShowCommits with consistent styling below the show commits checkbox
src/_locales/en/messages.json Adds tokenRequiredShowCommitsWarning i18n key for the warning message

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

@Mateeb-Haider Mateeb-Haider changed the title Check Box State handling when token not present Check box state handling when token not present Feb 19, 2026
@Mateeb-Haider
Copy link
Contributor Author

Hi @vedansh-5 @hpdang ,
this PR fixes #313 by enforcing GitHub token requirement for “Show commits on open/draft PRs” and aligns its warning behavior with existing repo filtering. Could you please review when you have a moment? Thank you!

Copy link
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 3 out of 3 changed files in this pull request and generated 3 comments.


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

Comment on lines +176 to +179
"tokenRequiredShowCommitsWarning": {
"message": "A GitHub token is required to show commits on open or draft PRs. Please add one in the settings.",
"description": "Warning message shown when show commits is enabled without a token."
},
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

The new i18n key tokenRequiredShowCommitsWarning has been added only to the English locale. Consider adding translations for other supported locales (de, es, fr, he, hi, id, it, ja, ml, nb, pt, pt_BR, ru, te, uk, vi, zh_CN) to maintain consistency with the existing tokenRequiredWarning key, which exists in all locales. If translations are typically added in separate PRs or by translation contributors, this can be tracked as a follow-up task.

Copilot uses AI. Check for mistakes.
}

const tokenWarning = document.getElementById('tokenWarningForShowCommits');
if (tokenWarning) {
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

When hiding the warning due to token presence or feature being disabled, the existing timeout stored in showCommitsWarningTimeout should be cleared to prevent unnecessary timer execution. Add a check to clear the timeout before hiding the warning, similar to how it's handled in showTokenWarningForShowCommits.

Suggested change
if (tokenWarning) {
if (tokenWarning) {
if (showCommitsWarningTimeout) {
clearTimeout(showCommitsWarningTimeout);
showCommitsWarningTimeout = null;
}

Copilot uses AI. Check for mistakes.
Comment on lines +1261 to +1269
const filtered = availableRepos.filter((repo) => {
if (selectedRepos.includes(repo.fullName)) {
return false;
}
);
if (!query) {
return true;
}
return repo.name.toLowerCase().includes(query) || repo.description?.toLowerCase().includes(query);
});
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

This formatting change appears to be unrelated to the PR's stated purpose of adding token enforcement for the "Show commits" checkbox. While the reformatting improves readability, it would be better to keep unrelated changes in a separate commit or PR to maintain clear change history.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings February 27, 2026 09:55
@Mateeb-Haider Mateeb-Haider force-pushed the feat/require-token-for-show-commits branch from a6424f3 to 2f117cf Compare February 27, 2026 09:55
Copy link
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 3 out of 3 changed files in this pull request and generated 1 comment.


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

animateWarning: true,
warningDurationMs: 3000,
});
chrome?.storage.local.set({ showCommits: showCommitsCheckbox.checked });
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

There's a race condition in this event handler. When the user checks the "Show commits" checkbox without a token, checkTokenForShowCommits() sets showCommits.checked = false and saves to storage. However, line 718 then unconditionally saves showCommitsCheckbox.checked to storage, which could overwrite the corrected value with true depending on timing.

This should follow the same pattern as the useRepoFilter checkbox (lines 942-1065), where storage is only updated after validation passes. The chrome?.storage.local.set() call should be moved inside checkTokenForShowCommits() or only executed when validation passes, similar to how useRepoFilter returns early at line 976 if validation fails.

Suggested change
chrome?.storage.local.set({ showCommits: showCommitsCheckbox.checked });
const checked = showCommitsCheckbox.checked;
chrome?.storage.local.set({ showCommits: checked });

Copilot uses AI. Check for mistakes.
@Mateeb-Haider
Copy link
Contributor Author

@vedansh-5 PTAL

@vedansh-5
Copy link
Member

Please pull in the latest changes.

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

Labels

extension frontend javascript Pull requests that update javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement]: Require GitHub token before enabling "Show commits" checkbox

3 participants