Add optional --install-webhook flag when creating repo/org
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
93bfb6fe07
commit
3b651afe07
2 changed files with 42 additions and 2 deletions
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue