Repository navigation
{owner} placeholder in gh api calls do not respect origin set via gh set-default #7595
Description
Activity
@whi-tw I don't think I would consider this a bug but rather a feature request that the
apicommand respectsrepo set-default. I think it makes sense to add to theapicommand 👍- addedenhancementa request to improve CLIa request to improve CLIhelp wantedContributions welcomeContributions welcomeand removedbugSomething isn't workingSomething isn't workingneeds-triageneeds to be reviewedneeds to be reviewed
on Jun 20, 2023 @samcoe Ah, for sure - it seemed like a bug, because it was behaviour that seemed odd and doesn't seem to match up with the usage text:
... will get replaced with values from the repository of the current directory.
I can't easily get around this in my use case (a
sync-forkalias), as I want to make the API call against 'my' remote (origin). I think the issue is likely that my username is alphabetically sorted afterStackExchange.aliases: sync-fork: |- ! set -euo pipefail gh api "repos/{owner}/{repo}/merge-upstream" -F branch='{branch}' git pull
There's no way to specify which origin is selected by
BaseRepoFunc()as far as I can tell.Perhaps another feature could be a
NamedRepoFunc()with the ability to specify a remote by name via an envar$GH_REMOTE, failing over toBaseRepoFunc()if the envar is not set.I have done an implementation in #7594.
Reacted by Sam Coe@whi-tw We have discussed adding some functionality around remotes in the past but have generally dismissed them as being a bit too low level.
Out of curiosity is there a reason why your
sync-forkalias does not use therepo synccommand? That command does take into accountrepo set-defaultand seems like it would fix your use case.That makes sense.
Yeah, I did see
repo sync, just when I was playing with it, it didn't seem to actually do what I wanted. Well, I couldn't be sure that it would actually doing what I wanted from the usage text.I presume that if I set the
defaultorigin to my fork, it'll sync it against the fork's origin?I think maybe it's a language thing - is the source of my fork the 'parent'?
I guess when writing the alias, I was hoping to avoid trying to understand how
repo syncactually worked, and just to use the API endpoint that I know will do what I want. Unfortunately that didn't turn out to be such a quick process as I've ended up down this placeholder yak shave!@whi-tw
repo syncdoes call the/merge-upstreamAPI endpoint underneath the covers. You are correct, the source of a fork repo is its parent repo. Unfortunately now that I think about the command behavior a bit more, it does require the user to specify any remote repo explicitly. It won't assume a default repo according to what was selected withrepo set-default, as the default behavior is to sync the local repo from its remote parent.
Describe the bug
When using the
{owner}placeholder ingh api, the chosen remote is whichever comes first whensort.Sort()is called on theremotesarray.Steps to reproduce the behavior
gh api "repos/{owner}/{repo}" -q '.full_name'Expected vs actual behavior
Expected
'whi-tw/dnscontrol'Actual
'StackExchange/dnscontrol'Logs