Skip to content

Add support for gh env list #10502

Description

@RyanHecht

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 0 exit code whereas errors should return 1 unless otherwise stated.

When I run gh env list --help
Then I see an informative help usage containing descriptive command information:

  1. Long description explaining command purpose
  2. Usage: gh env list [flags]
  3. Aliases: list commands typically allow ls alias
  4. Flags:
     -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 browser
  1. Inherited flags:

    INHERITED FLAGS
          --help                     Show help for command
      -R, --repo [HOST/]OWNER/REPO   Select another repository using the [HOST/]OWNER/REPO format
  2. JSON fields:

JSON FIELDS
  canAdminBypass, createdAt, customBranchPolicies, htmlUrl, id, name, nodeId,
  protectedBranches, protectionRules, updatedAt, url

Given I don't have the read role on the repository
When I run gh env list
Then 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 read role (or higher) on the repository
And Given I have a local repository cloned from GitHub
And Given STDOUT is connected to a TTY
When I run gh env list
Then I see a message and table of repository environments including:

  1. Message about environments found

    • If environment are not found:

      no environments found
      
    • If environments are found:

      Showing X environments in <owner>/<repo>
      
  2. 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 read role (or higher) on the repository
And Given I have a local repository cloned from GitHub
And Given STDOUT is not connected to a TTY
When I run gh env list
Then I see a message and table of repository environments including:

  1. Message about environments found

    • If environment are not found:

      no environments found
      
    • If environments are found:

      Showing X environments in <owner>/<repo>
      
  2. Table containing information if environments are found containing:

    • Name

protections/secrets/variables should be omitted if not running from a TTY

TTY

NAME          PROTECTION RULES  SECRETS  VARIABLES
prod           1                 2        1
testing  0                0        0

non-TTY

gh env list | cat
prod
testing

Activity

  1. added
    enhancementa request to improve CLI
    and removed on Feb 25, 2025
  2. self-assigned this
    on Feb 25, 2025
  3. linked a pull request that will close this issue[gh env] Introduce `gh env list` subcommand #10423on Feb 25, 2025
  4. iamazeem commented on Feb 26, 2025

    @iamazeem
    Contributor

    @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, secrets
    

    the List API response returns these:

    JSON FIELDS
      canAdminBypass, createdAt, customBranchPolicies, htmlUrl, id, name, nodeId,
      protectedBranches, protectionRules, updatedAt, url
    

    For protection rules, there may be another sub command under env main command e.g. protection-rule where all the related options may be grouped together using REST API endpoints for protection rules APIs.

    Not sure about variables and secrets JSON fields.
    Those are different APIs that need to be hit just to get their count.
    For variables and secrets, there are gh secret and gh variable commands available.

    • The TTY output
    gh env list
    prod      1 secret    2 variables 1 protection
    testing   0 secrets 0 variables 0 protections
    

    is 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 / --web flag.
    • Add ID field in the TTY table output.
  5. iamazeem commented on Mar 1, 2025

    @iamazeem
    Contributor

    Regarding ID, the relevant API endpoints use environment_name, not ID.
    Endpoint: /repos/{owner}/{repo}/environments/{environment_name}
    See https://docs.github.com/en/rest/deployments/environments.
    The ID field will be redundant info here and can be skipped.

  6. RyanHecht commented on Mar 7, 2025

    @RyanHecht
    Author

    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

  7. removed their assignment
    on Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions