You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gh pr list: no support for --head <owner>:<branch> syntax #10945
--head "typos" finds two closed PRs in latex3/latex repository.
$ GH_PAGER="" gh -R latex3/latex3 pr list --state all --head "typos"
Showing 2 of 2 pull requests in latex3/latex3 that match your search
ID TITLE BRANCH CREATED AT
#1610 fix small typos mbertucci47:typos about 6 months ago
#392 Typos in the intro to the l3tl documentation EvanAad:typos about 7 years ago
But when specific owner name is provided (`--head ":typos"), no PR is found.
$ GH_PAGER="" gh -R latex3/latex3 pr list --state all --head "mbertucci47:typos"
no pull requests match your search in latex3/latex3
$ GH_PAGER="" gh -R latex3/latex3 pr list --state all --head "EvanAad:typos"
no pull requests match your search in latex3/latex3
Logs
Adding GH_DEBUG=api, it seems the only useful info is that the <owner>:<branch> was correctly passed on to GraphQL variables
$ GH_DEBUG=api GH_PAGER="" gh -R latex3/latex3 pr list --state all --head "mbertucci47:typos"
[...]
GraphQL variables: {"headBranch":"mbertucci47:typos","limit":30,"owner":"latex3","repo":"latex3","state":["OPEN","CLOSED","MERGED"]}
[...]
changed the title [-]`gh pr list`: `--head` doesn't support the `<owner>:<branch>` syntax[/-][+]`gh pr list`: no support for `--head <owner>:<branch>` syntax[/+]on May 7, 2025
This seems like a limit/restriction in our GraphQL API. Please note that pr create uses the createPullRequest mutation, while pr list uses the repository object's pullRequests fields. So, they're two different things. Both of these support a headRefName argument, but the behaviour is different (i.e. one supports <owner>:<branch> and one doesn't).
As you pointed out gh pass the headRefName argument with the provided --head option, if any. Anyway, I attached the query for pr list at the end, in case you wanted to investigate it more.
That said, filtering of <owner> can be done at the gh side after retrieving the PRs (i.e. stripping the <owner>: part, if any, calling the GQL API, and then applying a filter on the results). However, IMHO, gh shouldn't be involved in such a niche data processings, because, for one the GQL API could change in the future and support <owner>:<branch> format for filtering PRs. Also, as a client, gh behaviour should not be very different from the GH API.
The combination of --json and --jq is a powerful tool for such scenarios. For example, this command will find the URL of the PR corresponding to one a specific user:
@muzimuzhi, do you think the --json/--jq approach could help with your situation?
GQL query
Below is the query gh uses to fetch the list of pull requests (variables are populated based on your case). You can try this GQL query in the Explorer.
However, I'm not sure about including this explicitly in the docs, mostly because it's not either stated in the API docs. I mean, what if it changes in the future?
But adding another example in the --help docs seems like a good idea. This at least shows how the --head option can be used:
EXAMPLES
...
# List PRs with a specific head branch name
$ gh pr list --head "typo"
I'll now close this issue as it seems completed, and create a new one for adding the --head usage example.
@muzimuzhi After discussing this with @williammartin, we decided there's value in your request. So, I reopened this.
What's needed
To recap, pr list needs to do client side filtering when the provided --head value is of the form <owner>:<branch> (aka a qualifed ref).
The change could be a bit complex due to the way pr list works. That is, pr list uses one of two queries (repository.pullRequests and search) based on the provided options. For example, if the --author option is assigned, then a search takes place. Therefore, the support for --head <owner>:<branch> should be covered in both queries.
Acceptance Criteria
Normal listing
Given I have a cross-repository PR whose head branch is on my fork When I run gh pr list -R <base-repo> --head <my-login>:<branch> Then the PR is listed
Search listing
Given I have a cross-repository PR whose head branch is on my fork When I run gh pr list -R <base-repo> --head <my-login>:<branch> --author <my-login> Then the PR is listed
Note
The --author option is to force pr list to do a search query. So any other option that only works with the search should lead to the same result.
Docs
--head usage
When I run gh pr list --help Then the usage of the --head option mentions both <branch> and <owner>:<branch> syntaxes are supported.
Example
When I run gh pr list --help Then there are example usages for both --head <user>:<branch> and --head <branch> syntax.
Note
The example for --head <branch> is going to be added by #10957.
Activity
[-]`gh pr list`: `--head` doesn't support the `<owner>:<branch>` syntax[/-][+]`gh pr list`: no support for `--head <owner>:<branch>` syntax[/+]babakks commentedon May 8, 2025
Thanks for submitting this issue, @muzimuzhi! 🙏
This seems like a limit/restriction in our GraphQL API. Please note that
pr createuses thecreatePullRequestmutation, whilepr listuses therepositoryobject'spullRequestsfields. So, they're two different things. Both of these support aheadRefNameargument, but the behaviour is different (i.e. one supports<owner>:<branch>and one doesn't).As you pointed out
ghpass theheadRefNameargument with the provided--headoption, if any. Anyway, I attached the query forpr listat the end, in case you wanted to investigate it more.That said, filtering of
<owner>can be done at theghside after retrieving the PRs (i.e. stripping the<owner>:part, if any, calling the GQL API, and then applying a filter on the results). However, IMHO,ghshouldn't be involved in such a niche data processings, because, for one the GQL API could change in the future and support<owner>:<branch>format for filtering PRs. Also, as a client,ghbehaviour should not be very different from the GH API.The combination of
--jsonand--jqis a powerful tool for such scenarios. For example, this command will find the URL of the PR corresponding to one a specific user:@muzimuzhi, do you think the
--json/--jqapproach could help with your situation?GQL query
Below is the query
ghuses to fetch the list of pull requests (variables are populated based on your case). You can try this GQL query in the Explorer.Variables:
{ "headBranch": "typos", "limit": 30, "owner": "latex3", "repo": "latex3", "state": [ "OPEN", "CLOSED", "MERGED" ] }muzimuzhi commentedon May 9, 2025
Yes, that would be enough.
Perhaps the doc of
gh pr listcould be more explicit on the supported syntax of--headvalue.babakks commentedon May 9, 2025
Great!
However, I'm not sure about including this explicitly in the docs, mostly because it's not either stated in the API docs. I mean, what if it changes in the future?
But adding another example in the
--helpdocs seems like a good idea. This at least shows how the--headoption can be used:I'll now close this issue as it seems completed, and create a new one for adding the
--headusage example.babakks commentedon May 9, 2025
@muzimuzhi After discussing this with @williammartin, we decided there's value in your request. So, I reopened this.
What's needed
To recap,
pr listneeds to do client side filtering when the provided--headvalue is of the form<owner>:<branch>(aka a qualifed ref).The change could be a bit complex due to the way
pr listworks. That is,pr listuses one of two queries (repository.pullRequestsandsearch) based on the provided options. For example, if the--authoroption is assigned, then asearchtakes place. Therefore, the support for--head <owner>:<branch>should be covered in both queries.Acceptance Criteria
Normal listing
Given I have a cross-repository PR whose head branch is on my fork
When I run
gh pr list -R <base-repo> --head <my-login>:<branch>Then the PR is listed
Search listing
Given I have a cross-repository PR whose head branch is on my fork
When I run
gh pr list -R <base-repo> --head <my-login>:<branch> --author <my-login>Then the PR is listed
Note
The
--authoroption is to forcepr listto do asearchquery. So any other option that only works with thesearchshould lead to the same result.Docs
--headusageWhen I run
gh pr list --helpThen the usage of the
--headoption mentions both<branch>and<owner>:<branch>syntaxes are supported.Example
When I run
gh pr list --helpThen there are example usages for both
--head <user>:<branch>and--head <branch>syntax.Note
The example for
--head <branch>is going to be added by #10957.