Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ type PullRequestsOptions struct {
Query string `json:"query"`
Sort string `json:"sort"`
Draft bool `json:"draft"`
Commit string `json:"commit"`
Copy link
Contributor

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

ctx context.Context
}

Expand Down
10 changes: 10 additions & 0 deletions pullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ func (p *PullRequests) Update(po *PullRequestsOptions) (interface{}, error) {
return p.c.execute("PUT", urlStr, data)
}

func (p *PullRequests) GetByCommit(po *PullRequestsOptions) (interface{}, error) {
urlStr := p.c.GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/commit/" + po.Commit + "/pullrequests/"
return p.c.executePaginated("GET", urlStr, "", nil)
}
Comment on lines +31 to +33
Copy link
Contributor

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

func (p *PullRequests) GetCommits(po *PullRequestsOptions) (interface{}, error) {
urlStr := p.c.GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/pullrequests/" + po.ID + "/commits/"
return p.c.executePaginated("GET", urlStr, "", nil)
}
Comment on lines +36 to +38
Copy link
Contributor

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

func (p *PullRequests) Gets(po *PullRequestsOptions) (interface{}, error) {
urlStr := p.c.GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/pullrequests/"

Expand Down