Skip to content

Conversation

publinchi
Copy link

Extends repository ingestion capabilities with two major improvements:

  • Branch selection: allows specifying a branch when cloning and retrieving file contents, enabling analysis of specific codebase versions beyond the default branch.

  • Azure repository support: adds platform selection for Azure repositories and updates URL parsing logic to correctly identify repository owners.

These enhancements improve flexibility, precision, and compatibility when working with diverse repositories.

Extends platform selection to include Azure repositories.

Updates URL parsing logic to correctly identify Azure repository
owners.
Extends repository ingestion capabilities to support specifying a branch, allowing users to target specific branches for cloning and file content retrieval.

This enables users to work with specific versions of codebases without relying solely on the default branch. It improves the flexibility and precision of repository analysis.
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.

Summary of Changes

Hello @publinchi, 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 expands the system's ability to ingest and process code repositories. It introduces the functionality to target specific branches for both cloning and file content retrieval, and integrates support for Azure DevOps, broadening the range of compatible code hosting platforms. These changes provide users with greater flexibility and precision in managing and analyzing diverse codebases.

Highlights

  • Branch Selection Capability: The system now supports specifying a branch when cloning repositories and retrieving file contents, allowing for analysis of specific codebase versions beyond the default branch.
  • Azure Repository Support: Added support for Azure DevOps repositories, including platform selection and updated URL parsing logic to correctly identify repository owners for Azure URLs.
  • Enhanced File Content Retrieval: Functions responsible for fetching file content from GitHub, GitLab, and Bitbucket have been updated to accept a branch parameter, ensuring more precise data retrieval.
  • Improved Repository Management: The internal database manager now incorporates branch information into repository naming and storage paths, preventing conflicts and improving organization when dealing with multiple branches of the same repository.
  • User Interface Updates: The frontend now includes a new input field for specifying the branch and updated platform selection options to include Azure, enhancing user control and experience.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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.

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 successfully extends repository ingestion capabilities by adding support for branch selection and Azure repositories. The changes are well-implemented across both the Python backend and the TypeScript frontend. My review focuses on a few opportunities to refactor the code for better maintainability by reducing duplication and removing some redundant logic. Overall, these are solid enhancements that improve the flexibility of the tool.

Comment on lines +538 to +557
ref_to_use = branch
if not ref_to_use:
# Try to get the default branch from the project info
try:
project_info_url = f"{gitlab_domain}/api/v4/projects/{encoded_project_path}"
project_headers = {}
if access_token:
project_headers["PRIVATE-TOKEN"] = access_token

project_response = requests.get(project_info_url, headers=project_headers)
if project_response.status_code == 200:
project_data = project_response.json()
ref_to_use = project_data.get('default_branch', 'main')
logger.info(f"Found default branch: {ref_to_use}")
else:
logger.warning(f"Could not fetch project info, using 'main' as default branch")
ref_to_use = 'main'
except Exception as e:
logger.warning(f"Error fetching project info: {e}, using 'main' as default branch")
ref_to_use = 'main'
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This block for determining the branch to use can be slightly refactored to improve readability and reduce repetition. By using a temporary variable for the default branch and assigning it to ref_to_use only once at the end of the block, you can make the logic cleaner and easier to maintain.

Suggested change
ref_to_use = branch
if not ref_to_use:
# Try to get the default branch from the project info
try:
project_info_url = f"{gitlab_domain}/api/v4/projects/{encoded_project_path}"
project_headers = {}
if access_token:
project_headers["PRIVATE-TOKEN"] = access_token
project_response = requests.get(project_info_url, headers=project_headers)
if project_response.status_code == 200:
project_data = project_response.json()
ref_to_use = project_data.get('default_branch', 'main')
logger.info(f"Found default branch: {ref_to_use}")
else:
logger.warning(f"Could not fetch project info, using 'main' as default branch")
ref_to_use = 'main'
except Exception as e:
logger.warning(f"Error fetching project info: {e}, using 'main' as default branch")
ref_to_use = 'main'
ref_to_use = branch
if not ref_to_use:
default_branch_to_set = 'main'
# Try to get the default branch from the project info
try:
project_info_url = f"{gitlab_domain}/api/v4/projects/{encoded_project_path}"
project_headers = {}
if access_token:
project_headers["PRIVATE-TOKEN"] = access_token
project_response = requests.get(project_info_url, headers=project_headers)
if project_response.status_code == 200:
project_data = project_response.json()
default_branch_to_set = project_data.get('default_branch', 'main')
logger.info(f"Found default branch: {default_branch_to_set}")
else:
logger.warning(f"Could not fetch project info, using 'main' as default branch")
except Exception as e:
logger.warning(f"Error fetching project info: {e}, using 'main' as default branch")
ref_to_use = default_branch_to_set

Comment on lines +612 to +631
branch_to_use = branch
if not branch_to_use:
# Try to get the default branch from the repository info
try:
repo_info_url = f"https://api.bitbucket.org/2.0/repositories/{owner}/{repo}"
repo_headers = {}
if access_token:
repo_headers["Authorization"] = f"Bearer {access_token}"

repo_response = requests.get(repo_info_url, headers=repo_headers)
if repo_response.status_code == 200:
repo_data = repo_response.json()
branch_to_use = repo_data.get('mainbranch', {}).get('name', 'main')
logger.info(f"Found default branch: {branch_to_use}")
else:
logger.warning(f"Could not fetch repository info, using 'main' as default branch")
branch_to_use = 'main'
except Exception as e:
logger.warning(f"Error fetching repository info: {e}, using 'main' as default branch")
branch_to_use = 'main'
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the logic in get_gitlab_file_content, this block for determining the branch can be refactored to improve readability. Using a temporary variable for the default branch and assigning it to branch_to_use at the end of the block will make the code cleaner.

Suggested change
branch_to_use = branch
if not branch_to_use:
# Try to get the default branch from the repository info
try:
repo_info_url = f"https://api.bitbucket.org/2.0/repositories/{owner}/{repo}"
repo_headers = {}
if access_token:
repo_headers["Authorization"] = f"Bearer {access_token}"
repo_response = requests.get(repo_info_url, headers=repo_headers)
if repo_response.status_code == 200:
repo_data = repo_response.json()
branch_to_use = repo_data.get('mainbranch', {}).get('name', 'main')
logger.info(f"Found default branch: {branch_to_use}")
else:
logger.warning(f"Could not fetch repository info, using 'main' as default branch")
branch_to_use = 'main'
except Exception as e:
logger.warning(f"Error fetching repository info: {e}, using 'main' as default branch")
branch_to_use = 'main'
branch_to_use = branch
if not branch_to_use:
default_branch_to_set = 'main'
# Try to get the default branch from the repository info
try:
repo_info_url = f"https://api.bitbucket.org/2.0/repositories/{owner}/{repo}"
repo_headers = {}
if access_token:
repo_headers["Authorization"] = f"Bearer {access_token}"
repo_response = requests.get(repo_info_url, headers=repo_headers)
if repo_response.status_code == 200:
repo_data = repo_response.json()
default_branch_to_set = repo_data.get('mainbranch', {}).get('name', 'main')
logger.info(f"Found default branch: {default_branch_to_set}")
else:
logger.warning(f"Could not fetch repository info, using 'main' as default branch")
except Exception as e:
logger.warning(f"Error fetching repository info: {e}, using 'main' as default branch")
branch_to_use = default_branch_to_set

Comment on lines +785 to +787
if branch:
safe_branch = re.sub(r"[^A-Za-z0-9._-]+", "_", branch)
repo_name = f"{repo_name}__{safe_branch}"
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic for creating a branch-specific name is a duplicate of the logic within the _extract_repo_name_from_url method. To improve maintainability and follow the DRY (Don't Repeat Yourself) principle, consider centralizing this logic. You could adjust _extract_repo_name_from_url to also handle local paths, allowing it to be called consistently for both URLs and local paths.

Comment on lines +232 to +234
} else {
owner = parts[parts.length - 2] || '';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This else block is redundant because the owner variable is already assigned the same value on line 227, before this conditional block. You can safely remove this else block to make the code more concise.

@sng-asyncfunc
Copy link
Contributor

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.

2 participants