Skip to content

Commit

Permalink
Add optional --install-webhook flag when creating repo/org
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
  • Loading branch information
gabriel-samfira committed Aug 16, 2023
1 parent 112262c commit 896df4c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
22 changes: 21 additions & 1 deletion cmd/garm-cli/cmd/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
orgRandomWebhookSecret bool
insecureOrgWebhook bool
keepOrgWebhook bool
installOrgWebhook bool
)

// organizationCmd represents the organization command
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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")

Expand Down
22 changes: 21 additions & 1 deletion cmd/garm-cli/cmd/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
randomWebhookSecret bool
insecureRepoWebhook bool
keepRepoWebhook bool
installRepoWebhook bool
)

// repositoryCmd represents the repository command
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 896df4c

Please sign in to comment.