-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
I am currently using PullRequests.ListPullRequestsWithCommit
to get a PR starting from a commit hash.
This function accepts a parameter "options" of type PullRequestListOptions
. PullRequestListOptions
has the State
field along with many other fields, but State
does not seem to do anything at all to the results of the function.
Example using commit sha cc8044e (PR #2814, a merged PR from this repository):
func main() {
client := github.NewClient(nil)
sha := "cc8044e88926ef5b8ddb447c9a9fc5b2c8d6df4d"
options := &github.PullRequestListOptions{
State: "open",
}
pull_requests, _, err := client.PullRequests.ListPullRequestsWithCommit(context.TODO(), "google", "go-github", sha, options)
if err != nil {
panic(err)
}
if len(pull_requests) == 0 {
fmt.Println("no pull requests found")
return
}
fmt.Printf("First PR: #%d\n", *pull_requests[0].Number)
}
This will print First PR: #2814
, which seems to me to be incorrect because it is a merged PR, and thus its state is "closed", not "open".
This seems to be because this function uses the REST API "repos/%v/%v/commits/%v/pulls"
under the hood, which, as stated in the documentation, being an API from the Commits API, not from the Pull Request API, it does not have a state
parameter.