func()

in pkg/gitprovider/bitbucket.go [153:186]


func (b *BitbucketClient) GetWebHooks(ctx context.Context, _, _, projectID string) ([]*WebHook, error) {
	owner, repo, err := parseProjectID(projectID)
	if err != nil {
		return nil, err
	}

	r, err := b.client.GetRepositoriesWorkspaceRepoSlugHooksWithResponse(ctx, owner, repo)
	if err != nil {
		return nil, fmt.Errorf("failed to get Bitbucket web hooks: %w", err)
	}

	if r.StatusCode() != http.StatusOK {
		return nil, fmt.Errorf("failed to get Bitbucket web hooks: %s %s", r.Status(), r.Body)
	}

	if r.JSON200 == nil || r.JSON200.Values == nil {
		return []*WebHook{}, nil
	}

	webHooks := make([]*WebHook, len(*r.JSON200.Values))

	for i, hook := range *r.JSON200.Values {
		if hook.Uuid == nil || hook.Url == nil {
			return nil, fmt.Errorf("failed to get Bitbucket web hooks: invalid response %s", r.Body)
		}

		webHooks[i] = &WebHook{
			ID:  *hook.Uuid,
			URL: *hook.Url,
		}
	}

	return webHooks, nil
}