remove implied org functionality from secret list
This commit is contained in:
parent
2248565839
commit
c036e6699c
2 changed files with 14 additions and 54 deletions
|
|
@ -47,8 +47,7 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
|
|||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVar(&opts.OrgName, "org", "", "List secrets for an organization")
|
||||
cmd.Flags().Lookup("org").NoOptDefVal = "@owner"
|
||||
cmd.Flags().StringVarP(&opts.OrgName, "org", "o", "", "List secrets for an organization")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
@ -60,26 +59,21 @@ func listRun(opts *ListOptions) error {
|
|||
}
|
||||
client := api.NewClientFromHTTP(c)
|
||||
|
||||
orgName := opts.OrgName
|
||||
|
||||
var baseRepo ghrepo.Interface
|
||||
if opts.OrgName == "" || opts.OrgName == "@owner" {
|
||||
if orgName == "" {
|
||||
baseRepo, err = opts.BaseRepo()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not determine base repo: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
orgName := opts.OrgName
|
||||
host := ghinstance.OverridableDefault()
|
||||
if orgName == "@owner" {
|
||||
orgName = baseRepo.RepoOwner()
|
||||
host = baseRepo.RepoHost()
|
||||
}
|
||||
|
||||
var secrets []Secret
|
||||
if orgName != "" {
|
||||
secrets, err = getOrgSecrets(client, host, orgName)
|
||||
} else {
|
||||
if orgName == "" {
|
||||
secrets, err = getRepoSecrets(client, baseRepo)
|
||||
} else {
|
||||
secrets, err = getOrgSecrets(client, orgName)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -131,7 +125,8 @@ func fmtVisibility(s Secret) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func getOrgSecrets(client *api.Client, host, orgName string) ([]Secret, error) {
|
||||
func getOrgSecrets(client *api.Client, orgName string) ([]Secret, error) {
|
||||
host := ghinstance.OverridableDefault()
|
||||
return getSecrets(client, host, fmt.Sprintf("orgs/%s/actions/secrets", orgName))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,15 +31,8 @@ func Test_NewCmdList(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: "implicit org",
|
||||
cli: "--org",
|
||||
wants: ListOptions{
|
||||
OrgName: "@owner",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "explicit org",
|
||||
cli: "--org=UmbrellaCorporation",
|
||||
name: "org",
|
||||
cli: "-oUmbrellaCorporation",
|
||||
wants: ListOptions{
|
||||
OrgName: "UmbrellaCorporation",
|
||||
},
|
||||
|
|
@ -105,7 +98,7 @@ func Test_listRun(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: "explicit org tty",
|
||||
name: "org tty",
|
||||
tty: true,
|
||||
opts: &ListOptions{
|
||||
OrgName: "UmbrellaCorporation",
|
||||
|
|
@ -117,7 +110,7 @@ func Test_listRun(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: "explicit org not tty",
|
||||
name: "org not tty",
|
||||
tty: false,
|
||||
opts: &ListOptions{
|
||||
OrgName: "UmbrellaCorporation",
|
||||
|
|
@ -128,30 +121,6 @@ func Test_listRun(t *testing.T) {
|
|||
"SECRET_THREE\t1975-11-30\tSELECTED",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "implicit org not tty",
|
||||
tty: false,
|
||||
opts: &ListOptions{
|
||||
OrgName: "@owner",
|
||||
},
|
||||
wantOut: []string{
|
||||
"SECRET_ONE\t1988-10-11\tALL",
|
||||
"SECRET_TWO\t2020-12-04\tPRIVATE",
|
||||
"SECRET_THREE\t1975-11-30\tSELECTED",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "implicit org not tty",
|
||||
tty: true,
|
||||
opts: &ListOptions{
|
||||
OrgName: "@owner",
|
||||
},
|
||||
wantOut: []string{
|
||||
"SECRET_ONE.*Updated 1988-10-11.*Visible to all repositories",
|
||||
"SECRET_TWO.*Updated 2020-12-04.*Visible to private repositories",
|
||||
"SECRET_THREE.*Updated 1975-11-30.*Visible to selected repositories",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
@ -195,11 +164,7 @@ func Test_listRun(t *testing.T) {
|
|||
Visibility: shared.VisSelected,
|
||||
},
|
||||
}
|
||||
if tt.opts.OrgName == "@owner" {
|
||||
path = "orgs/owner/actions/secrets"
|
||||
} else {
|
||||
path = fmt.Sprintf("orgs/%s/actions/secrets", tt.opts.OrgName)
|
||||
}
|
||||
path = fmt.Sprintf("orgs/%s/actions/secrets", tt.opts.OrgName)
|
||||
}
|
||||
|
||||
reg.Register(httpmock.REST("GET", path), httpmock.JSONResponse(payload))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue