Skip to content

feat(auth): sort OAuth scopes by service, then access level#413

Open
anshul-garg27 wants to merge 4 commits intogoogleworkspace:mainfrom
anshul-garg27:feat/sort-scopes-by-service
Open

feat(auth): sort OAuth scopes by service, then access level#413
anshul-garg27 wants to merge 4 commits intogoogleworkspace:mainfrom
anshul-garg27:feat/sort-scopes-by-service

Conversation

@anshul-garg27
Copy link
Contributor

Summary

Sort OAuth scopes in the TUI picker by service name first (grouping all Drive scopes together, all Gmail together, etc.), then by access level (read-only before write), then by sensitivity classification.

Problem

The current sort order groups scopes by risk level (restricted → sensitive → non-sensitive), which scatters scopes from the same service across different sections of the list. When a user wants to select specific Drive or Gmail scopes, they have to scan through the entire list.

Solution

Changed the sort key in fetch_scopes_for_apis() from:

classification (desc) → short name (asc)

to:

api_name (asc) → is_readonly (desc, read-only first) → classification (asc, safe first) → short name (asc)

Before: Scopes scattered by risk level
After: All Drive scopes together, all Gmail scopes together, read-only variants listed before write variants

Test plan

  • Added unit test verifying sort groups by service, then read-only first, then classification
  • Existing tests unaffected (sort change only affects display order, not functionality)

Closes #319

@changeset-bot
Copy link

changeset-bot bot commented Mar 11, 2026

🦋 Changeset detected

Latest commit: d01b8fc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the OAuth scope sorting mechanism within the TUI picker to provide a more intuitive and user-friendly experience. Previously, scopes were scattered based on risk level, making selection cumbersome. The new sorting prioritizes grouping by service and access level, streamlining the process for users to identify and choose necessary permissions.

Highlights

  • Improved OAuth Scope Sorting: The sorting logic for OAuth scopes in the TUI picker has been updated to group scopes first by service name, then by access level (read-only before write), and finally by sensitivity classification.
  • Enhanced User Experience: This change significantly improves the usability of the scope selection interface by presenting related scopes together, making it easier for users to find and select specific permissions.
Changelog
  • .changeset/sort-scopes-by-service.md
    • Added a new changeset file to document the updated OAuth scope sorting logic.
  • src/setup.rs
    • Modified the fetch_scopes_for_apis function to implement the new sorting order for OAuth scopes.
    • Added a new unit test to validate that scopes are correctly sorted by service, access level, and classification.
Activity
  • No specific activity (comments, reviews, or progress updates) was found for this pull request.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves the user experience by sorting OAuth scopes more logically in the TUI. The implementation of the new sorting logic is correct. However, I've identified two areas for improvement in the new unit test:

  1. There is code duplication between the test and the production code, which should be refactored to improve maintainability.
  2. The test case is incomplete and doesn't fully validate all aspects of the new sorting criteria.
    Please see my detailed comments for suggestions on how to address these points.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the OAuth scope sorting logic to group scopes by service and then access level, which improves the user experience in the TUI picker. The implementation correctly extracts the sorting logic into a dedicated compare_scopes function and adds a unit test to verify the new behavior. My feedback includes a suggestion to make the new test assertions more robust and maintainable.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

@anshul-garg27 anshul-garg27 force-pushed the feat/sort-scopes-by-service branch from 6f6bdfc to bf99daf Compare March 12, 2026 20:34
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request changes the sorting order of OAuth scopes in the TUI picker. The new logic sorts scopes by service name, then access level, then sensitivity classification. This is achieved by introducing a new compare_scopes function and applying it in fetch_scopes_for_apis. A new unit test is included to verify the correctness of the new sorting logic. The implementation appears to correctly reflect the intended changes.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new sorting logic for OAuth scopes in the TUI picker, grouping them by service, then access level, and finally classification. The implementation is clean, with a dedicated compare_scopes function for the new logic and a comprehensive unit test to verify its correctness. The changes effectively address the issue of scattered scopes and improve the user experience when selecting them. The code is well-structured and the changes are correctly implemented.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a more intuitive sorting order for OAuth scopes in the TUI picker. By grouping scopes first by service name, then by access level (read-only before write), and finally by sensitivity, it significantly improves the user experience when selecting scopes. The implementation is clean, extracting the sorting logic into a new compare_scopes function. The change is also well-tested with a new unit test that verifies the new sorting behavior across different services and scope attributes. The changes are correct and well-implemented.

@anshul-garg27
Copy link
Contributor Author

CI fix pushed — added #[derive(Debug)] to ScopeClassification which was needed for assert_eq! in the test. Ready for re-review. @jpoehnelt

@anshul-garg27 anshul-garg27 requested a review from jpoehnelt March 13, 2026 16:08
Previously scopes were sorted by risk classification first (restricted,
sensitive, non-sensitive), making it hard to find all scopes for a
specific service. Now scopes are grouped by service name (Drive, Gmail,
etc.), then by access level (read-only first), then by classification
(safe before restricted), then alphabetically.

This makes the scope picker much easier to navigate when selecting
scopes for specific services.

Closes googleworkspace#319
Address Gemini review feedback:
- Extract inline sort closure into a reusable compare_scopes function
  to avoid duplicating sort logic between production code and tests
- Add a Sensitive-classified scope to the test to verify all four
  sort criteria (service, access level, classification, name)
Replace brittle index-based assertions with a collected Vec comparison
so the test remains maintainable as scopes change over time.
The CI test job failed because assert_eq! requires Debug on both
operands. Add #[derive(Debug)] to ScopeClassification.
@anshul-garg27 anshul-garg27 force-pushed the feat/sort-scopes-by-service branch from 05b570c to d01b8fc Compare March 13, 2026 20:33
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request changes the sorting logic for OAuth scopes in the TUI picker. The new sort order groups scopes by service name, then by access level (read-only first), and finally by sensitivity classification. This is implemented in a new compare_scopes function. A new unit test has been added to verify that the new sorting logic works as expected. The changes are confined to src/setup.rs and correctly implement the described feature.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth scopes are not properly ordered

3 participants