in pkg/gitprovider/bitbucket.go [233:270]
func (b *BitbucketClient) ProjectExists(ctx context.Context, _, _, projectID string) (bool, error) {
owner, repo, err := parseProjectID(projectID)
if err != nil {
return false, err
}
r, err := b.client.GetRepositoriesWorkspaceWithResponse(
ctx,
owner,
nil,
func(ctx context.Context, req *http.Request) error {
// nolint: gocritic // Can't use %q instead of "%s" because need double quotes.
req.URL.RawQuery = fmt.Sprintf(`q=slug="%s"`, repo)
return nil
},
)
if err != nil {
return false, fmt.Errorf("failed to get Bitbucket repository: %w", err)
}
if r.StatusCode() != http.StatusOK {
return false, fmt.Errorf("failed to get Bitbucket repository: %s %s", r.Status(), r.Body)
}
if r.JSON200 == nil || r.JSON200.Values == nil {
return false, nil
}
// nolint: gocritic // Force to use copy value.
for _, v := range *r.JSON200.Values {
if v.FullName != nil && *v.FullName == projectID {
return true, nil
}
}
return false, nil
}