diff --git a/api/openapi-v3-spec.yaml b/api/openapi-v3-spec.yaml index 3048376..e52d09f 100644 --- a/api/openapi-v3-spec.yaml +++ b/api/openapi-v3-spec.yaml @@ -750,6 +750,13 @@ paths: schema: type: string example: helm-chart + - name: url + in: query + description: 'Optional - allows filtering the output by repository url. Must match `^[a-z](-?:?@?.?\/?[a-z0-9]+)*$`.' + required: false + schema: + type: string + example: git@github.com:some-org/some-repo.git responses: '200': description: Success diff --git a/internal/acorn/service/repositoriesint.go b/internal/acorn/service/repositoriesint.go index a6d29ac..142b861 100644 --- a/internal/acorn/service/repositoriesint.go +++ b/internal/acorn/service/repositoriesint.go @@ -16,7 +16,8 @@ type Repositories interface { GetRepositories(ctx context.Context, ownerAliasFilter string, serviceNameFilter string, - nameFilter string, typeFilter string) (openapi.RepositoryListDto, error) + nameFilter string, typeFilter string, + urlFilter string) (openapi.RepositoryListDto, error) GetRepository(ctx context.Context, repoKey string) (openapi.RepositoryDto, error) // CreateRepository returns the repository as it was created, with commit hash and timestamp filled in. diff --git a/internal/service/repositories/repositories.go b/internal/service/repositories/repositories.go index 2f8533b..0933635 100644 --- a/internal/service/repositories/repositories.go +++ b/internal/service/repositories/repositories.go @@ -93,6 +93,7 @@ func (s *Impl) validRepositoryType(repoType string) bool { func (s *Impl) GetRepositories(ctx context.Context, ownerAliasFilter string, serviceNameFilter string, nameFilter string, typeFilter string, + urlFilter string, ) (openapi.RepositoryListDto, error) { result := openapi.RepositoryListDto{ Repositories: make(map[string]openapi.RepositoryDto), @@ -141,7 +142,9 @@ func (s *Impl) GetRepositories(ctx context.Context, if ownerAliasFilter == "" || ownerAliasFilter == repository.Owner { if nameFilter == "" || nameFilter == keyName { if typeFilter == "" || typeFilter == keyType { - result.Repositories[key] = repository + if urlFilter == "" || urlFilter == repository.Url { + result.Repositories[key] = repository + } } } } diff --git a/internal/service/vcswebhookshandler/vcswebhookshandler.go b/internal/service/vcswebhookshandler/vcswebhookshandler.go index 0e32c84..db020ae 100644 --- a/internal/service/vcswebhookshandler/vcswebhookshandler.go +++ b/internal/service/vcswebhookshandler/vcswebhookshandler.go @@ -237,7 +237,7 @@ func (h *Impl) verifyRepository(ctx context.Context, path string, contents strin } func (h *Impl) verifyRepositoryData(ctx context.Context, dtoKey string, dtoRepo *openapi.RepositoryDto) error { - repositories, err := h.Repositories.GetRepositories(ctx, "", "", "", "") + repositories, err := h.Repositories.GetRepositories(ctx, "", "", "", "", "") if err == nil { for repoKey, repo := range repositories.Repositories { if repoKey == dtoKey { diff --git a/internal/web/controller/repositoryctl/repositoryctl.go b/internal/web/controller/repositoryctl/repositoryctl.go index b1e7123..76c5c77 100644 --- a/internal/web/controller/repositoryctl/repositoryctl.go +++ b/internal/web/controller/repositoryctl/repositoryctl.go @@ -20,6 +20,7 @@ const ownerParam = "owner" const serviceParam = "service" const nameParam = "name" const typeParam = "type" +const urlParam = "url" type Impl struct { Configuration librepo.Configuration @@ -69,10 +70,12 @@ func (c *Impl) GetRepositories(w http.ResponseWriter, r *http.Request) { serviceNameFilter := util.StringQueryParam(r, serviceParam) nameFilter := util.StringQueryParam(r, nameParam) typeFilter := util.StringQueryParam(r, typeParam) + urlFilter := util.StringQueryParam(r, urlParam) repositories, err := c.Repositories.GetRepositories(ctx, ownerAliasFilter, serviceNameFilter, - nameFilter, typeFilter) + nameFilter, typeFilter, + urlFilter) if err != nil { if apierrors.IsNotFoundError(err) { // acceptable case - no matching repositories, so return empty list