func()

in pkg/client/sonar/sonar.go [483:512]


func (sc Client) AddWebhook(webhookName string, webhookUrl string) error {
	webHookExist, err := sc.checkWebhookExist(webhookName)
	if err != nil {
		return err
	}

	if webHookExist {
		return nil
	}

	log.Info(fmt.Sprintf("Start creating webhook %v in Sonar", webhookName))

	resp, err := sc.jsonTypeRequest().
		SetQueryParams(map[string]string{
			nameField: webhookName,
			"url":     webhookUrl,
		}).
		Post("/webhooks/create")
	if err != nil {
		return fmt.Errorf("failed to send request to add webhook: %w", err)
	}

	if resp.IsError() {
		return fmt.Errorf("failed to add webhook %s with response %s", webhookName, resp.Status())
	}

	log.Info(fmt.Sprintf("Webhook %v has been created", webhookName))

	return nil
}