Skip to content

Commit

Permalink
Merge pull request #391 from Interhyp/RELTEC-12347
Browse files Browse the repository at this point in the history
feat(RELTEC-12347): search repository by url
  • Loading branch information
KRaffael authored Dec 20, 2024
2 parents c6ae1e7 + 457f631 commit 838ef0f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
7 changes: 7 additions & 0 deletions api/openapi-v3-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,13 @@ paths:
summary: get repositories
description: 'Obtain a list of repositories, potentially filtered by owner alias or service name'
parameters:
- 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: [email protected]:some-org/some-repo.git
- name: owner
in: query
description: 'Optional - the alias of an owner. If present, only repositories with this owner are returned. Must match `^[a-z](-?[a-z0-9]+)*$`.'
Expand Down
3 changes: 2 additions & 1 deletion internal/acorn/service/repositoriesint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions internal/service/repositories/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -138,10 +139,12 @@ func (s *Impl) GetRepositories(ctx context.Context,
keyType = keyComponents[1]
}

if ownerAliasFilter == "" || ownerAliasFilter == repository.Owner {
if nameFilter == "" || nameFilter == keyName {
if typeFilter == "" || typeFilter == keyType {
result.Repositories[key] = repository
if urlFilter == "" || urlFilter == repository.Url {
if ownerAliasFilter == "" || ownerAliasFilter == repository.Owner {
if nameFilter == "" || nameFilter == keyName {
if typeFilter == "" || typeFilter == keyType {
result.Repositories[key] = repository
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/vcswebhookshandler/vcswebhookshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion internal/web/controller/repositoryctl/repositoryctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 838ef0f

Please sign in to comment.