octocrab
octocrab copied to clipboard
Filtering pull requests by head and all states does not work
I am attempting to write some code which, given a branch name, determines which (if any) PR numbers are associated with it. This is possible in the Github CLI:
~/Documents/Projects/counter-rs$ gh pr list --state all --head index
Showing 1 of 1 pull request in coriolinus/counter-rs that matches your search
#9 Implement `Index` and `IndexMut` like `c... qryxip:index about 2 years ago
However, doing this via Octocat does not work:
async fn get_pr_page(
octocrab: impl Deref<Target = Octocrab>,
owner: &str,
repo_name: &str,
branch_name: &str,
limit: impl Into<Option<u8>>,
) -> Result<Page<PullRequest>, Error> {
let limit = limit.into().unwrap_or(100);
octocrab
.pulls(owner, repo_name)
.list()
.head(branch_name)
.state(State::All)
.per_page(limit)
.send()
.await
.context("get pull requests for a branch")
}
#[tokio::test]
async fn get_prs_by_branch_name() {
let octocrab = octocrab::instance();
let page = get_pr_page(octocrab, "coriolinus", "counter-rs", "index", 2)
.await
.unwrap();
let count = page.total_count.unwrap_or_else(|| page.items.len() as _);
assert_eq!(count, 1);
// more stuff here, irrelevant because the assertion fails
}
---- tests::get_prs_by_branch_name stdout ----
thread 'tests::get_prs_by_branch_name' panicked at 'assertion failed: `(left == right)`
left: `2`,
right: `1`', src/lib.rs:159:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Note that the two pull requests returned in that test are the two most recent in the repository, not filtered by the selected head at all.
Thank you for your issue! I don't have time to investigate this at the moment, a PR is always welcome 🙂
Based on github docs, the REST API query only support user:ref-name
or organization:ref-name
format head.
Filter pulls by head user or head organization and branch name in the format of user:ref-name or organization:ref-name. For example: github:new-script-format or octocat:test-branch.
While Github CLI is based on GraphQL. link here.