🎨 Palette: Add progress bar for fetching existing rules#156
🎨 Palette: Add progress bar for fetching existing rules#156
Conversation
- Added progress bar to `get_all_existing_rules` for better UX during long syncs. - Removed duplicate `render_progress_bar` definition in `main.py`. - Added test case for the new progress bar logic. - Managed stderr clearing to prevent log interference with the progress bar. Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Merging to
|
Summary of ChangesHello @abhimehro, 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 significantly enhances the user experience by introducing a dynamic progress bar for the Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Pull request overview
This PR enhances user experience by adding a visual progress indicator when fetching existing rules from multiple folders, replacing a static wait screen with real-time feedback. It also removes a duplicate function definition discovered during refactoring.
Changes:
- Added progress bar rendering during parallel folder rule fetching with proper line clearing to avoid interference with logging
- Removed duplicate
render_progress_barfunction definition from lines 162-179 - Added test coverage for the new progress bar functionality in
get_all_existing_rules
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| main.py | Integrated progress bar into get_all_existing_rules with proper line clearing for concurrent logging; removed duplicate function definition |
| test_main.py | Added test to verify progress bar rendering during rule fetching |
| .jules/palette.md | Documented learnings about progress bars in concurrent contexts and duplicate function definitions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| writes = [args[0] for args, _ in mock_stderr.write.call_args_list] | ||
| combined = "".join(writes) | ||
|
|
||
| assert "Fetching existing rules" in combined |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| combined = "".join(writes) | ||
|
|
||
| assert "Fetching existing rules" in combined | ||
| assert "🔍" in combined |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
test_main.py
Outdated
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
test_main.py
Outdated
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
| mock_resp.json.return_value = {"body": {"rules": []}} | ||
| return mock_resp | ||
| monkeypatch.setattr(m, "_api_get", side_effect) | ||
|
|
Check warning
Code scanning / Pylint (reported by Codacy)
Missing function docstring Warning test
test_main.py
Outdated
Check notice
Code scanning / Pylint (reported by Codacy)
Unused argument 'client' Note test
| ) | ||
|
|
||
| if USE_COLORS: | ||
| sys.stderr.write(f"\r\033[K") |
Check warning
Code scanning / Prospector (reported by Codacy)
Using an f-string that does not have any interpolated variables (f-string-without-interpolation) Warning
test_main.py
Outdated
Check warning
Code scanning / Prospector (reported by Codacy)
Unused argument 'client' (unused-argument) Warning test
test_main.py
Outdated
Check warning
Code scanning / Prospector (reported by Codacy)
Unused argument 'url' (unused-argument) Warning test
| mock_resp.json.return_value = {"body": {"rules": []}} | ||
| return mock_resp | ||
| monkeypatch.setattr(m, "_api_get", side_effect) | ||
|
|
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Missing function or method docstring Warning test
| ) | ||
|
|
||
| if USE_COLORS: | ||
| sys.stderr.write(f"\r\033[K") |
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Using an f-string that does not have any interpolated variables Note
test_main.py
Outdated
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Unused argument 'url' Note test
There was a problem hiding this comment.
Code Review
This pull request introduces a user experience improvement by adding a progress bar to the rule fetching process, which is particularly helpful when dealing with many folders. The removal of a duplicate function definition is also a good cleanup. The implementation is solid, and the new test case effectively validates the change. I've added one suggestion to make the progress bar handling more robust against interruptions.
| with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: | ||
| future_to_folder = { | ||
| executor.submit(_fetch_folder_rules, folder_id): folder_id | ||
| for folder_name, folder_id in folders.items() | ||
| } | ||
|
|
||
| for future in concurrent.futures.as_completed(future_to_folder): | ||
| completed_folders += 1 | ||
| try: | ||
| result = future.result() | ||
| if result: | ||
| all_rules.update(result) | ||
| except Exception as e: | ||
| if USE_COLORS: | ||
| # Clear line to print warning cleanly | ||
| sys.stderr.write("\r\033[K") | ||
| sys.stderr.flush() | ||
|
|
||
| folder_id = future_to_folder[future] | ||
| log.warning(f"Failed to fetch rules for folder ID {folder_id}: {e}") | ||
|
|
||
| render_progress_bar( | ||
| completed_folders, total_folders, "Fetching existing rules", prefix="🔍" | ||
| ) | ||
|
|
||
| if USE_COLORS: | ||
| sys.stderr.write(f"\r\033[K") | ||
| sys.stderr.flush() |
There was a problem hiding this comment.
To ensure the progress bar line is always cleared, even if an error occurs during the fetching process (like a KeyboardInterrupt), it's more robust to use a try...finally block. This guarantees that the cleanup code for the progress bar is executed regardless of whether the operation completes successfully or is interrupted.
try:
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
future_to_folder = {
executor.submit(_fetch_folder_rules, folder_id): folder_id
for folder_name, folder_id in folders.items()
}
for future in concurrent.futures.as_completed(future_to_folder):
completed_folders += 1
try:
result = future.result()
if result:
all_rules.update(result)
except Exception as e:
if USE_COLORS:
# Clear line to print warning cleanly
sys.stderr.write("\r\033[K")
sys.stderr.flush()
folder_id = future_to_folder[future]
log.warning(f"Failed to fetch rules for folder ID {folder_id}: {e}")
render_progress_bar(
completed_folders, total_folders, "Fetching existing rules", prefix="🔍"
)
finally:
if USE_COLORS:
sys.stderr.write(f"\r\033[K")
sys.stderr.flush()…itization, add dry-run plan details Incorporates the best changes from 36 Jules PRs, addressing review feedback: Bolt (Performance) - from PR #173: - Pre-compile PROFILE_ID_PATTERN and RULE_PATTERN at module level - Use compiled patterns in is_valid_profile_id_format, validate_profile_id, and is_valid_rule - Supersedes PRs: #140, #143, #152, #155, #158, #161, #167, #170, #173 Sentinel (Security) - from PR #172 with review feedback: - Enhance sanitize_for_log to redact Basic Auth credentials in URLs - Redact sensitive query parameters (token, key, secret, password, etc.) - Handle fragment separators (#) per Gemini Code Assist review - Use [^&#\s]* pattern per Copilot reviewer suggestion - Update docstring per reviewer suggestion - Supersedes PRs: #142, #145, #148, #151, #154, #157, #160, #169, #172 Palette (UX) - from PR #174 with lint fixes: - Add print_plan_details function for dry-run visibility - Fix duplicate render_progress_bar definition bug - Supersedes PRs: #139, #141, #144, #147, #150, #153, #156, #159, #162, #165, #168, #171, #174 Also: #146, #149, #164 (parallel folder deletion) and #166 (auto-fix .env perms) are independent features not consolidated here. Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
…itization, add dry-run plan details Incorporates the best changes from 36 Jules PRs, addressing review feedback: Bolt (Performance) - from PR #173: - Pre-compile PROFILE_ID_PATTERN and RULE_PATTERN at module level - Use compiled patterns in is_valid_profile_id_format, validate_profile_id, and is_valid_rule - Supersedes PRs: #140, #143, #152, #155, #158, #161, #167, #170, #173 Sentinel (Security) - from PR #172 with review feedback: - Enhance sanitize_for_log to redact Basic Auth credentials in URLs - Redact sensitive query parameters (token, key, secret, password, etc.) - Handle fragment separators (#) per Gemini Code Assist review - Use [^&#\s]* pattern per Copilot reviewer suggestion - Update docstring per reviewer suggestion - Supersedes PRs: #142, #145, #148, #151, #154, #157, #160, #169, #172 Palette (UX) - from PR #174 with lint fixes: - Add print_plan_details function for dry-run visibility - Fix duplicate render_progress_bar definition bug - Supersedes PRs: #139, #141, #144, #147, #150, #153, #156, #159, #162, #165, #168, #171, #174 Also: #146, #149, #164 (parallel folder deletion) and #166 (auto-fix .env perms) are independent features not consolidated here. Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
🎨 Palette: Add progress bar for fetching existing rules
💡 What: Added a progress bar to the
get_all_existing_rulesfunction and removed a duplicate function definition.🎯 Why: Fetching rules from many folders can take time. Users were left with a static screen and no feedback. The progress bar improves perceived performance and provides reassurance.
📸 Before/After:
Before:
After:
♿ Accessibility: Uses standard terminal output, compatible with screen readers that handle dynamic updates (though mainly visual). Added line clearing to ensure clean output.
PR created automatically by Jules for task 2834881192475199462 started by @abhimehro