Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(RELTEC-12347): search repository by url #391

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading