Skip to content

Conversation

@naaa760
Copy link
Contributor

@naaa760 naaa760 commented Dec 24, 2025

Fixed repository analysis and PR creation issues

Repository Analysis Problem:

  • Analysis returned same generic rules for all repos too quickly
  • Root cause: Improper caching shared results between different repos/auth contexts
  • Failed analyses cached generic rules instead of forcing fresh attempts

Repository Analysis Solution:

  • Cache keys now include authentication context to separate different users
  • Analysis fails completely when GitHub data unavailable (no more generic fallbacks)
  • Failed analyses clear cache to ensure fresh retry attempts

PR Creation Problem:

  • PR creation showed success but redirected to 404 pages
  • Invalid/malformed URLs returned despite successful API responses

PR Creation Solution:

  • Multi-layer URL validation ensures proper GitHub PR format
  • Validates PR numbers and URL patterns before returning success
  • Only valid, working GitHub URLs prevent 404 redirects

Result:

  • Repository-specific rule recommendations based on actual GitHub data
  • Bulletproof PR creation with guaranteed valid URLs

Testing: All tests pass, fixes ensure proper analysis and 404-free PR creation.

…tion

- Cache key now includes authentication context to prevent different users/installations from sharing cached results
- Repository analysis now fails completely when it can't access GitHub data, instead of returning generic rules
- Failed analyses clear their cache entries to ensure fresh attempts
- Added validation to ensure repository language is determined before generating rules
- ADDED BULLETPROOF PR URL VALIDATION:
  * Validates PR URL is proper GitHub format (https://github.com/owner/repo/pull/number)
  * Validates PR number is a positive integer
  * Validates URL matches expected pattern before returning success
  * NO MORE 404 REDIRECTS - only returns valid, working GitHub PR URLs
@naaa760 naaa760 requested a review from dkargatzis as a code owner December 24, 2025 14:12
@gemini-code-assist
Copy link

Summary of Changes

Hello @naaa760, 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 addresses critical issues in both repository analysis and pull request creation workflows. It refines the caching mechanism for repository analysis to ensure that recommendations are always specific to the authenticated user and the repository, preventing the premature return of generic rules. Concurrently, it fortifies the PR creation process by introducing comprehensive URL and PR number validation, guaranteeing that users are redirected to valid GitHub pull request pages after creation. These changes collectively enhance the reliability and accuracy of the system's interactions with GitHub.

Highlights

  • Repository Analysis Caching: Cache keys now incorporate authentication context (installation ID or user token) to prevent sharing generic results across different users and ensure repository-specific recommendations are always generated.
  • Robust Repository Analysis: Analysis now explicitly fails if core GitHub data (like repository language) is unavailable, and failed analyses automatically clear the cache to force fresh retries, eliminating generic fallbacks and ensuring data integrity.
  • Enhanced PR Creation Validation: Implemented multi-layer validation for newly created PR URLs and numbers, ensuring they conform to GitHub's expected format and preventing users from being redirected to 404 pages after a successful API call.
  • Improved Recommendation Logic: The system now considers contributing guidelines and the presence of CI/CD workflows when generating rule recommendations, leading to more tailored and confident suggestions for repository best practices.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 20.75472% with 42 lines in your changes missing coverage. Please review.

❌ Your patch status has failed because the patch coverage (20.7%) is below the target coverage (80.0%). You can increase the patch coverage or adjust the target coverage.
❌ Your project status has failed because the head coverage (32.9%) is below the target coverage (80.0%). You can increase the head coverage or adjust the target coverage.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@           Coverage Diff           @@
##            main     #34     +/-   ##
=======================================
- Coverage   32.9%   32.9%   -0.1%     
=======================================
  Files         85      85             
  Lines       5122    5163     +41     
=======================================
+ Hits        1689    1699     +10     
- Misses      3433    3464     +31     

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 513b5bd...f769dbf. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@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 effectively addresses the reported issues with repository analysis caching and pull request creation. The introduction of authentication context into cache keys and robust URL validation for PRs are excellent fixes. I've identified one critical issue where the cache-clearing mechanism on failure is not working as intended due to a bug in how ttl=0 is handled, which could prevent fresh analysis on retries. Additionally, I have a couple of medium-severity suggestions to improve code style and remove redundancy. Overall, these are great improvements to the system's reliability.

error=result.message,
)
# Clear any cached results for this repository to ensure fresh analysis on retry
await set_cache(cache_key, None, ttl=0)

Choose a reason for hiding this comment

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

critical

There's a critical issue with this cache clearing attempt. The set_cache function checks if ttl:, which evaluates to False for ttl=0. Consequently, this call caches a None value for the default duration (1 hour) instead of clearing the entry, preventing fresh analysis on retries. A proper fix would be in set_cache to check if ttl is not None:. As a workaround within this file, you can use a very small positive TTL to ensure near-immediate expiration.

Suggested change
await set_cache(cache_key, None, ttl=0)
await set_cache(cache_key, None, ttl=1)

Copy link
Member

Choose a reason for hiding this comment

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

@naaa760 any thougths?

Currently, validators like `author_team_is` and `file_patterns` operate independently.
"""
import logging

Choose a reason for hiding this comment

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

medium

According to PEP 8 style guidelines, imports should be placed at the top of the file. Please move import logging to the top level of the module to improve readability and adhere to standard Python conventions.

Copy link
Member

Choose a reason for hiding this comment

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

@naaa760 import should on top

Comment on lines +318 to +319
final_pr_url = pr.get("html_url", "")
final_pr_number = pr.get("number")

Choose a reason for hiding this comment

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

medium

These variables final_pr_url and final_pr_number are redundant. The variables pr_url and pr_number were already assigned from the same source on lines 276-277 and have been validated. You can remove these lines and use pr_url and pr_number in the subsequent logic (lines 322-333, 342-343, and 347) to avoid duplication and improve clarity.

Copy link
Member

Choose a reason for hiding this comment

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

@naaa760 here too...

@dkargatzis
Copy link
Member

Also, invalid rules schema still exists here

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.

3 participants