diff options
Diffstat (limited to 'app/controllers/concerns/harbor/repository.rb')
-rw-r--r-- | app/controllers/concerns/harbor/repository.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/app/controllers/concerns/harbor/repository.rb b/app/controllers/concerns/harbor/repository.rb new file mode 100644 index 00000000000..0e541e2172e --- /dev/null +++ b/app/controllers/concerns/harbor/repository.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +module Harbor + module Repository + def index + respond_to do |format| + format.html + format.json do + repositories + end + end + end + + # The show action renders index to allow frontend routing to work on page refresh + def show + render :index + end + + private + + def query_params + params.permit(:search, :sort, :page, :limit) + end + + def query + Gitlab::Harbor::Query.new(container.harbor_integration, query_params) + end + + def repositories + unless query.valid? + return render( + json: { message: 'Invalid parameters', errors: query.errors }, + status: :unprocessable_entity + ) + end + + repositories_json = ::Integrations::HarborSerializers::RepositorySerializer.new + .with_pagination(request, response) + .represent( + query.repositories, + url: container.harbor_integration.url, + project_name: container.harbor_integration.project_name + ) + render json: repositories_json + end + + def container + raise NotImplementedError + end + end +end |