Add a rudimentary filter option when listing entities

This change adds the ability to filter the list of entities returned
by the API by entity owner, name or endpoint, depending on the entity
type.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2025-06-17 22:37:18 +00:00
parent 2fd0e720e6
commit 499fbde60c
32 changed files with 879 additions and 73 deletions

View file

@ -28,6 +28,7 @@ import (
var (
enterpriseName string
enterpriseEndpoint string
enterpriseWebhookSecret string
enterpriseCreds string
)
@ -85,6 +86,8 @@ var enterpriseListCmd = &cobra.Command{
}
listEnterprisesReq := apiClientEnterprises.NewListEnterprisesParams()
listEnterprisesReq.Name = &enterpriseName
listEnterprisesReq.Endpoint = &enterpriseEndpoint
response, err := apiCli.Enterprises.ListEnterprises(listEnterprisesReq, authToken)
if err != nil {
return err
@ -185,6 +188,8 @@ func init() {
enterpriseAddCmd.Flags().StringVar(&poolBalancerType, "pool-balancer-type", string(params.PoolBalancerTypeRoundRobin), "The balancing strategy to use when creating runners in pools matching requested labels.")
enterpriseListCmd.Flags().BoolVarP(&long, "long", "l", false, "Include additional info.")
enterpriseListCmd.Flags().StringVarP(&enterpriseName, "name", "n", "", "Exact enterprise name to filter by.")
enterpriseListCmd.Flags().StringVarP(&enterpriseEndpoint, "endpoint", "e", "", "Exact endpoint name to filter by.")
enterpriseAddCmd.MarkFlagRequired("credentials") //nolint
enterpriseAddCmd.MarkFlagRequired("name") //nolint

View file

@ -29,6 +29,7 @@ import (
var (
orgName string
orgEndpoint string
orgWebhookSecret string
orgCreds string
orgRandomWebhookSecret bool
@ -243,6 +244,8 @@ var orgListCmd = &cobra.Command{
}
listOrgsReq := apiClientOrgs.NewListOrgsParams()
listOrgsReq.Name = &orgName
listOrgsReq.Endpoint = &orgEndpoint
response, err := apiCli.Organizations.ListOrgs(listOrgsReq, authToken)
if err != nil {
return err
@ -314,7 +317,10 @@ func init() {
orgAddCmd.Flags().BoolVar(&installOrgWebhook, "install-webhook", false, "Install the webhook as part of the add operation.")
orgAddCmd.MarkFlagsMutuallyExclusive("webhook-secret", "random-webhook-secret")
orgAddCmd.MarkFlagsOneRequired("webhook-secret", "random-webhook-secret")
orgListCmd.Flags().BoolVarP(&long, "long", "l", false, "Include additional info.")
orgListCmd.Flags().StringVarP(&orgName, "name", "n", "", "Exact org name to filter by.")
orgListCmd.Flags().StringVarP(&orgEndpoint, "endpoint", "e", "", "Exact endpoint name to filter by.")
orgAddCmd.MarkFlagRequired("credentials") //nolint
orgAddCmd.MarkFlagRequired("name") //nolint

View file

@ -30,6 +30,7 @@ import (
var (
repoOwner string
repoName string
repoEndpoint string
repoWebhookSecret string
repoCreds string
forgeType string
@ -213,6 +214,9 @@ var repoListCmd = &cobra.Command{
}
listReposReq := apiClientRepos.NewListReposParams()
listReposReq.Name = &repoName
listReposReq.Owner = &repoOwner
listReposReq.Endpoint = &repoEndpoint
response, err := apiCli.Repositories.ListRepos(listReposReq, authToken)
if err != nil {
return err
@ -321,6 +325,9 @@ func init() {
repoAddCmd.MarkFlagsOneRequired("webhook-secret", "random-webhook-secret")
repoListCmd.Flags().BoolVarP(&long, "long", "l", false, "Include additional info.")
repoListCmd.Flags().StringVarP(&repoName, "name", "n", "", "Exact repo name to filter by.")
repoListCmd.Flags().StringVarP(&repoOwner, "owner", "o", "", "Exact repo owner to filter by.")
repoListCmd.Flags().StringVarP(&repoEndpoint, "endpoint", "e", "", "Exact endpoint name to filter by.")
repoAddCmd.MarkFlagRequired("credentials") //nolint
repoAddCmd.MarkFlagRequired("owner") //nolint