From 3b651afe077f2d0bc655f2d1811b5b3232dd8cd1 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Wed, 16 Aug 2023 12:29:07 +0000 Subject: [PATCH] Add optional --install-webhook flag when creating repo/org Signed-off-by: Gabriel Adrian Samfira --- cmd/garm-cli/cmd/organization.go | 22 +++++++++++++++++++++- cmd/garm-cli/cmd/repository.go | 22 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/cmd/garm-cli/cmd/organization.go b/cmd/garm-cli/cmd/organization.go index b3dbd0e1..d833e2dd 100644 --- a/cmd/garm-cli/cmd/organization.go +++ b/cmd/garm-cli/cmd/organization.go @@ -32,6 +32,7 @@ var ( orgRandomWebhookSecret bool insecureOrgWebhook bool keepOrgWebhook bool + installOrgWebhook bool ) // organizationCmd represents the organization command @@ -170,7 +171,25 @@ var orgAddCmd = &cobra.Command{ if err != nil { return err } - formatOneOrganization(response.Payload) + + if installOrgWebhook { + installWebhookReq := apiClientOrgs.NewInstallOrgWebhookParams() + installWebhookReq.OrgID = response.Payload.ID + installWebhookReq.Body.WebhookEndpointType = params.WebhookEndpointDirect + + _, err = apiCli.Organizations.InstallOrgWebhook(installWebhookReq, authToken) + if err != nil { + return err + } + } + + getOrgRequest := apiClientOrgs.NewGetOrgParams() + getOrgRequest.OrgID = response.Payload.ID + org, err := apiCli.Organizations.GetOrg(getOrgRequest, authToken) + if err != nil { + return err + } + formatOneOrganization(org.Payload) return nil }, } @@ -286,6 +305,7 @@ func init() { orgAddCmd.Flags().StringVar(&orgWebhookSecret, "webhook-secret", "", "The webhook secret for this organization") orgAddCmd.Flags().StringVar(&orgCreds, "credentials", "", "Credentials name. See credentials list.") orgAddCmd.Flags().BoolVar(&orgRandomWebhookSecret, "random-webhook-secret", false, "Generate a random webhook secret for this organization.") + 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") diff --git a/cmd/garm-cli/cmd/repository.go b/cmd/garm-cli/cmd/repository.go index 5d596dd6..8482264b 100644 --- a/cmd/garm-cli/cmd/repository.go +++ b/cmd/garm-cli/cmd/repository.go @@ -33,6 +33,7 @@ var ( randomWebhookSecret bool insecureRepoWebhook bool keepRepoWebhook bool + installRepoWebhook bool ) // repositoryCmd represents the repository command @@ -172,7 +173,25 @@ var repoAddCmd = &cobra.Command{ if err != nil { return err } - formatOneRepository(response.Payload) + + if installRepoWebhook { + installWebhookReq := apiClientRepos.NewInstallRepoWebhookParams() + installWebhookReq.RepoID = response.Payload.ID + installWebhookReq.Body.WebhookEndpointType = params.WebhookEndpointDirect + + _, err := apiCli.Repositories.InstallRepoWebhook(installWebhookReq, authToken) + if err != nil { + return err + } + } + + getRepoReq := apiClientRepos.NewGetRepoParams() + getRepoReq.RepoID = response.Payload.ID + repo, err := apiCli.Repositories.GetRepo(getRepoReq, authToken) + if err != nil { + return err + } + formatOneRepository(repo.Payload) return nil }, } @@ -290,6 +309,7 @@ func init() { repoAddCmd.Flags().StringVar(&repoWebhookSecret, "webhook-secret", "", "The webhook secret for this repository") repoAddCmd.Flags().StringVar(&repoCreds, "credentials", "", "Credentials name. See credentials list.") repoAddCmd.Flags().BoolVar(&randomWebhookSecret, "random-webhook-secret", false, "Generate a random webhook secret for this repository.") + repoAddCmd.Flags().BoolVar(&installRepoWebhook, "install-webhook", false, "Install the webhook as part of the add operation.") repoAddCmd.MarkFlagsMutuallyExclusive("webhook-secret", "random-webhook-secret") repoAddCmd.MarkFlagsOneRequired("webhook-secret", "random-webhook-secret")