Skip to content

Add support for getting commits from a PR and getting a PR by a commit hash #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2025

Conversation

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.

Hello @auroq, 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!

Summary of Changes

This pull request introduces new functionalities to the Bitbucket API client. Specifically, it adds support for retrieving pull requests associated with a given commit hash and for fetching the commits associated with a specific pull request. This is achieved by adding a Commit field to the PullRequestsOptions struct and implementing the GetByCommit and GetCommits methods on the PullRequests type.

Highlights

  • New Feature: Get Pull Requests by Commit: The GetByCommit method allows users to retrieve pull requests associated with a specific commit hash.
  • New Feature: Get Commits for a Pull Request: The GetCommits method enables users to fetch all commits associated with a specific pull request.
  • Configuration: The PullRequestsOptions struct is extended with a Commit field to support the GetByCommit functionality.

Changelog

  • bitbucket.go
    • Added the Commit field to the PullRequestsOptions struct at line 318.
  • pullrequests.go
    • Implemented the GetByCommit method at lines 30-33 to retrieve pull requests by commit hash.
    • Implemented the GetCommits method at lines 35-38 to retrieve commits associated with a 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 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 is currently in preview and 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 to provide feedback.

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.


A commit's tale,
A pull request's journey,
Code merges flow free.

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

@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 new functionality to retrieve pull requests by commit hash and to get commits associated with a specific pull request. The changes seem well-structured and align with the provided API documentation. However, there are a few areas that could be improved for clarity and maintainability.

Summary of Findings

  • Missing Error Handling: The new functions GetByCommit and GetCommits lack explicit error handling for the executePaginated function call. It's crucial to handle potential errors to prevent unexpected behavior.
  • Inconsistent Naming: The naming of the Commit field in PullRequestsOptions and its usage in GetByCommit could be more descriptive to improve readability.

Merge Readiness

The pull request introduces valuable new features. However, the missing error handling in the newly added functions is a concern that should be addressed before merging. Addressing the naming inconsistency would also improve the code's clarity. I am unable to directly approve the pull request, and other reviewers should also review this code before merging.

Comment on lines +31 to +33
urlStr := p.c.GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/commit/" + po.Commit + "/pullrequests/"
return p.c.executePaginated("GET", urlStr, "", nil)
}

Choose a reason for hiding this comment

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

high

It's important to handle the error returned by executePaginated. Add error handling to ensure that any errors during the API call are properly managed and propagated. This will prevent unexpected behavior if the API call fails.

Suggested change
urlStr := p.c.GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/commit/" + po.Commit + "/pullrequests/"
return p.c.executePaginated("GET", urlStr, "", nil)
}
urlStr := p.c.GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/commit/" + po.Commit + "/pullrequests/"
res, err := p.c.executePaginated("GET", urlStr, "", nil)
if err != nil {
return nil, err // Or handle the error as appropriate for your application
}
return res, nil

Comment on lines +36 to +38
urlStr := p.c.GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/pullrequests/" + po.ID + "/commits/"
return p.c.executePaginated("GET", urlStr, "", nil)
}

Choose a reason for hiding this comment

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

high

Similar to GetByCommit, error handling is missing here as well. Add error handling to ensure that any errors during the API call are properly managed and propagated. This will prevent unexpected behavior if the API call fails.

Suggested change
urlStr := p.c.GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/pullrequests/" + po.ID + "/commits/"
return p.c.executePaginated("GET", urlStr, "", nil)
}
urlStr := p.c.GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/pullrequests/" + po.ID + "/commits/"
res, err := p.c.executePaginated("GET", urlStr, "", nil)
if err != nil {
return nil, err // Or handle the error as appropriate for your application
}
return res, nil

@@ -315,6 +315,7 @@ type PullRequestsOptions struct {
Query string `json:"query"`
Sort string `json:"sort"`
Draft bool `json:"draft"`
Commit string `json:"commit"`

Choose a reason for hiding this comment

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

medium

Consider renaming this field to CommitHash for better clarity, as it represents the hash of a commit rather than the commit object itself.

Suggested change
Commit string `json:"commit"`
CommitHash string `json:"commit"`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to rename this if that is the repo owner's preference. However, I used commit to follow the precedence of Bitbucket's actual API docs (see links in the PR details).

Copy link
Owner

@ktrysmt ktrysmt left a comment

Choose a reason for hiding this comment

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

LGTM

@ktrysmt ktrysmt merged commit 30a0351 into ktrysmt:master May 5, 2025
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