@@ -26,6 +26,7 @@ type ListOptions struct {
2626 BaseRepo func () (ghrepo.Interface , error )
2727
2828 OrgName string
29+ EnvName string
2930}
3031
3132func NewCmdList (f * cmdutil.Factory , runF func (* ListOptions ) error ) * cobra.Command {
@@ -38,12 +39,16 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
3839 cmd := & cobra.Command {
3940 Use : "list" ,
4041 Short : "List secrets" ,
41- Long : "List secrets for a repository or organization" ,
42+ Long : "List secrets for a repository, environment, or organization" ,
4243 Args : cobra .NoArgs ,
4344 RunE : func (cmd * cobra.Command , args []string ) error {
4445 // support `-R, --repo` override
4546 opts .BaseRepo = f .BaseRepo
4647
48+ if err := cmdutil .MutuallyExclusive ("specify only one of `--org` or `--env`" , opts .OrgName != "" , opts .EnvName != "" ); err != nil {
49+ return err
50+ }
51+
4752 if runF != nil {
4853 return runF (opts )
4954 }
@@ -53,6 +58,7 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
5358 }
5459
5560 cmd .Flags ().StringVarP (& opts .OrgName , "org" , "o" , "" , "List secrets for an organization" )
61+ cmd .Flags ().StringVarP (& opts .EnvName , "env" , "e" , "" , "List secrets for an environment" )
5662
5763 return cmd
5864}
@@ -64,6 +70,7 @@ func listRun(opts *ListOptions) error {
6470 }
6571
6672 orgName := opts .OrgName
73+ envName := opts .EnvName
6774
6875 var baseRepo ghrepo.Interface
6976 if orgName == "" {
@@ -75,7 +82,11 @@ func listRun(opts *ListOptions) error {
7582
7683 var secrets []* Secret
7784 if orgName == "" {
78- secrets , err = getRepoSecrets (client , baseRepo )
85+ if envName == "" {
86+ secrets , err = getRepoSecrets (client , baseRepo )
87+ } else {
88+ secrets , err = getEnvSecrets (client , baseRepo , envName )
89+ }
7990 } else {
8091 var cfg config.Config
8192 var host string
@@ -171,6 +182,11 @@ func getOrgSecrets(client httpClient, host, orgName string) ([]*Secret, error) {
171182 return secrets , nil
172183}
173184
185+ func getEnvSecrets (client httpClient , repo ghrepo.Interface , envName string ) ([]* Secret , error ) {
186+ path := fmt .Sprintf ("repos/%s/environments/%s/secrets" , ghrepo .FullName (repo ), envName )
187+ return getSecrets (client , repo .RepoHost (), path )
188+ }
189+
174190func getRepoSecrets (client httpClient , repo ghrepo.Interface ) ([]* Secret , error ) {
175191 return getSecrets (client , repo .RepoHost (), fmt .Sprintf ("repos/%s/actions/secrets" ,
176192 ghrepo .FullName (repo )))
0 commit comments