Repository navigation
Add support for gh env list #10502
Description
Activity
- added a parent issue
on Feb 25, 2025 - addedenhancementa request to improve CLIa request to improve CLIhelp wantedContributions welcomeContributions welcomeand removedneeds-triageneeds to be reviewedneeds to be reviewed
on Feb 25, 2025 - linked a pull request that will close this issue[gh env] Introduce `gh env list` subcommand #10423
on Feb 25, 2025 @RyanHecht: Thank you for creating this sub-issue! 👍
Here are a few things that need to be updated better alignment with the API and the GitHub UI/UX:
-
The term "protection rules" seems to be more appropriate w.r.t. API/UI instead of "protections".
-
Regarding
JSON FIELDS id, name, protections, variables, secretsthe List API response returns these:
JSON FIELDS canAdminBypass, createdAt, customBranchPolicies, htmlUrl, id, name, nodeId, protectedBranches, protectionRules, updatedAt, urlFor protection rules, there may be another sub command under
envmain command e.g.protection-rulewhere all the related options may be grouped together using REST API endpoints for protection rules APIs.Not sure about
variablesandsecretsJSON fields.
Those are different APIs that need to be hit just to get their count.
For variables and secrets, there aregh secretandgh variablecommands available.- The TTY output
gh env list prod 1 secret 2 variables 1 protection testing 0 secrets 0 variables 0 protectionsis not aligned with the existing command outputs e.g.
gh repo list,gh issue list,gh pr list, etc.References:
Please take a look at the description of #10423 for all the test cases for the comparison.
The TODOs I see here are:
- Add support for
-w / --webflag. - Add
IDfield in the TTY table output.
-
Regarding
ID, the relevant API endpoints useenvironment_name, notID.
Endpoint:/repos/{owner}/{repo}/environments/{environment_name}
See https://docs.github.com/en/rest/deployments/environments.
TheIDfield will be redundant info here and can be skipped.Hey @iamazeem, sorry I lost this notification! I'll admit that I rote-copied the old AC into the new format without thinking too critically -- you're right, what you have in your PR is much more closely aligned with our UX expectations. I changed the JSON fields to match what you have, changed the table formatting, and removed the "ID" from the TTY output
Reacted by AzeemReacted by Azeem
This issue is to implement the command necessary to list repository environments as discussed in #5149 and described in this comment using our old AC format
This should follow similar form as existing GitHub CLI commands as well as necessary tests.
Acceptance Criteria
Note
Successful commands should return
0exit code whereas errors should return1unless otherwise stated.When I run
gh env list --helpThen I see an informative help usage containing descriptive command information:
gh env list [flags]listcommands typically allowlsalias-q, --jq expression Filter JSON output using a jq expression --json fields Output JSON with the specified fields -t, --template string Format JSON output using a Go template; see "gh help formatting" -L, --limit int Maximum number of environments fo fetch (default 30) -w, --web List repositoy environments in the web browserInherited flags:
INHERITED FLAGS --help Show help for command -R, --repo [HOST/]OWNER/REPO Select another repository using the [HOST/]OWNER/REPO formatJSON fields:
Given I don't have the
readrole on the repositoryWhen I run
gh env listThen I see an informative error
error getting environments: HTTP 404: Repository not found. (https://api.github.com/repos/{owner}/{repo}/environments)Given I have the
readrole (or higher) on the repositoryAnd Given I have a local repository cloned from GitHub
And Given STDOUT is connected to a TTY
When I run
gh env listThen I see a message and table of repository environments including:
Message about environments found
If environment are not found:
If environments are found:
Table containing information if environments are found containing:
Name(TTY-only information)
Protections(count of protections as int)Secrets(count of secrets as int)Variables(count of variables as int)Given I have the
readrole (or higher) on the repositoryAnd Given I have a local repository cloned from GitHub
And Given STDOUT is not connected to a TTY
When I run
gh env listThen I see a message and table of repository environments including:
Message about environments found
If environment are not found:
If environments are found:
Table containing information if environments are found containing:
Nameprotections/secrets/variables should be omitted if not running from a TTY
TTY
non-TTY