mona-actions / gh-repo-stats

GH CLI extension to pull statistics on repository metadata used in GitHub migrations
MIT License
195 stars 97 forks source link

Enhance extension to leverage `gh auth` session #26

Open andyfeller opened 2 years ago

andyfeller commented 2 years ago

Problem

One of the helpful aspects of GitHub CLI extensions is their ability to delegate authorization issues to be handled by gh auth. This allows interpreted and precompiled extensions to delegate this responsibility, focusing on the core functionality.

With initially running the gh-repo-stats extension, it prompted and required a personal access token (PAT) when this was already setup via standard GH CLI methods.

$ gh repo-stats --org $(whoami) 

######################################################
######################################################
############# GitHub repo list and sizer #############
######################################################
######################################################

------------------------------------------------------
Please create a GitHub Personal Access Token used to gather
information from your Organization, with a scope of 'repo',
followed by [ENTER]:
(note: your input will NOT be displayed)

Request

It would be nice if the extension was enhanced in a way where it did not need my PAT explicitly. Looking at the underlying interpreted script, I think this might be doable if all of the curl calls were instead leveraging gh api or other gh subcommands itself.

Chocrates commented 2 years ago

Strangely that didn't happen to me. I wonder if it was using my GITHUB_TOKEN that is in my environment? Anyhow, could gh auth allow this to use a github app for authentication so we get 15k requests per hour? Is the gh tool even the right spot to make that request?

andyfeller commented 2 years ago

@Chocrates : 🤔 that is a really good question, essentially:

Can gh auth leverage a GitHub App private key and installation information to authenticate for a one-time token?

That aside, gh would pick up on your GITHUB_TOKEN as explained in https://cli.github.com/manual/gh_help_environment

3nassale7 commented 1 month ago

iam here

vagabond2522 commented 1 month ago

Problem

One of the helpful aspects of GitHub CLI extensions is their ability to delegate authorization issues to be handled by gh auth. This allows interpreted and precompiled extensions to delegate this responsibility, focusing on the core functionality.

With initially running the gh-repo-stats extension, it prompted and required a personal access token (PAT) when this was already setup via standard GH CLI methods.

$ gh repo-stats --org $(whoami) 

######################################################
######################################################
############# GitHub repo list and sizer #############
######################################################
######################################################

------------------------------------------------------
Please create a GitHub Personal Access Token used to gather
information from your Organization, with a scope of 'repo',
followed by [ENTER]:
(note: your input will NOT be displayed)

Request

It would be nice if the extension was enhanced in a way where it did not need my PAT explicitly. Looking at the underlying interpreted script, I think this might be doable if all of the curl calls were instead leveraging gh api or other gh subcommands itself.

ljuanto commented 1 week ago

![Uploading Screenshot_20241015-184734.jpg…]()