-
Notifications
You must be signed in to change notification settings - Fork 150
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
Conversation
auroq
commented
May 3, 2025
- GetByCommit: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-commit-commit-pullrequests-get
- GetCommits: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-comments-get
Signed-off-by: Aria Vesta <[email protected]>
Signed-off-by: Aria Vesta <[email protected]>
There was a problem hiding this 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 aCommit
field to support theGetByCommit
functionality.
Changelog
- bitbucket.go
- Added the
Commit
field to thePullRequestsOptions
struct at line 318.
- Added the
- 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.
- Implemented the
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
-
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. ↩
There was a problem hiding this 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
andGetCommits
lack explicit error handling for theexecutePaginated
function call. It's crucial to handle potential errors to prevent unexpected behavior. - Inconsistent Naming: The naming of the
Commit
field inPullRequestsOptions
and its usage inGetByCommit
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.
urlStr := p.c.GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/commit/" + po.Commit + "/pullrequests/" | ||
return p.c.executePaginated("GET", urlStr, "", nil) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 |
urlStr := p.c.GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/pullrequests/" + po.ID + "/commits/" | ||
return p.c.executePaginated("GET", urlStr, "", nil) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM