Skip to content

Commit

Permalink
feat(RELTEC-12347): search repository by url
Browse files Browse the repository at this point in the history
  • Loading branch information
KRaffael committed Dec 20, 2024
1 parent 5ac34f3 commit 9c188dc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
7 changes: 7 additions & 0 deletions api/openapi-v3-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
5 changes: 4 additions & 1 deletion 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 @@ -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
}
}
}
}
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 9c188dc

Please sign in to comment.