GH CLI Extension Auth

It’s cool that the GH CLI allows extensions. And if what I wanted could be done by invoking the core GH CLI methods with --json flags, that might be all I need. But if I need to call the GitHub API and I potentially want to do things that require authorization, I don’t see any way for the GH CLI to share any kind of authorization with the GH CLI extension.

I was looking at creating a GH CLI extension to display information about workflow usage, and there’s some API calls that I could use for that, but if I want to get information on a private repo, that requires auth. Sure, I could bake in my own personal token, but that doesn’t make the extension useful for anyone else.

Is there something I’m missing here?

Ah – I can use gh api, which will let me get what I want.

I was considering building the GH extension in Golang to match some of the other extensions I’ve looked at, but then I have authorization problems unless I have the Go program invoke the gh cli, which, if I’m going to do that, why bother with Go?

Whereas if I build the extension in bash with gh api, I don’t have auth problems, but … then I have to interact with a JSON API in bash, which doesn’t sound like much fun either. Hm. There are options, but I can’t say I’m fond of the available choices.

Is there any other way to get auth information passed into the extension so that I could write the extension in a way that doesn’t wrap the GH CLI?

Ok – this path definitely works (GitHub - geoffreywiseman/gh-actuse: GitHub CLI Extension to display Github Actions Usage), but I can see already that it’s a bit slow, orchestrating a series of HTTP REST calls using Bash and gh. I will check out some of the other extensions to see if anyone else’s extensions have a clever way of making use of the auth from gh. I see it’s possible to do gh auth status -t, which might be one way of doing it, although … still somewhat clumsy. I guess I’ll check out the environment as well, just in case there’s something being passed through.

For what it’s worth, there’s a more complete answer in the GitHub Discussions for the gh cli: