Skip to content

ListPullRequestsWithCommit has incorrect option type #2815

@bennesp

Description

@bennesp

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.

Metadata

Metadata

Labels

Breaking API ChangePR will require a bump to the major version num in next release. Look here to see the change(s).buggood first issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions