Skip to content

{owner} placeholder in gh api calls do not respect origin set via gh set-default #7595

@whi-tw

Description

@whi-tw

Describe the bug

When using the {owner} placeholder in gh api, the chosen remote is whichever comes first when sort.Sort() is called on the remotes array.

❯ gh --version
gh version 2.30.0 (2023-05-30)
https://github.com/cli/cli/releases/tag/v2.30.0

Steps to reproduce the behavior

❯ cat .git/config
...
[remote "origin"]
	url = git@github.com:whi-tw/dnscontrol.git
	fetch = +refs/heads/*:refs/remotes/origin/*
	gh-resolved = base
[remote "upstream"]
	url = git@github.com:StackExchange/dnscontrol.git
	fetch = +refs/heads/*:refs/remotes/upstream/*
  1. gh api "repos/{owner}/{repo}" -q '.full_name'

Expected vs actual behavior

Expected

'whi-tw/dnscontrol'

Actual

'StackExchange/dnscontrol'

Logs

❯ GH_DEBUG=api gh api "repos/{owner}/{repo}" -q '.full_name'
[git remote -v]
[git config --get-regexp ^remote\..*\.gh-resolved$]
[git remote -v]
[git config --get-regexp ^remote\..*\.gh-resolved$]
* Request at 2023-06-19 14:25:57.345605 +0100 BST m=+0.088005710
* Request to https://api.github.com/repos/StackExchange/dnscontrol

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIhelp wantedContributions welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions