Commit 62a458e3 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '197918-add-package-type-param-to-group-packages-api' into 'master'

Add package_type as parameter to group packages list api

See merge request gitlab-org/gitlab!26833
parents 392d2b0d d52d97a0
---
title: Add package_type as a filter option to the group packages list API endpoint
merge_request: 26833
author:
type: added
...@@ -67,6 +67,7 @@ GET /groups/:id/packages ...@@ -67,6 +67,7 @@ GET /groups/:id/packages
| `exclude_subgroups` | boolean | false | If the param is included as true, packages from projects from subgroups are not listed. Default is `false`. | | `exclude_subgroups` | boolean | false | If the param is included as true, packages from projects from subgroups are not listed. Default is `false`. |
| `order_by`| string | no | The field to use as order. One of `created_at` (default), `name`, `version`, `type`, or `project_path`. | | `order_by`| string | no | The field to use as order. One of `created_at` (default), `name`, `version`, `type`, or `project_path`. |
| `sort` | string | no | The direction of the order, either `asc` (default) for ascending order or `desc` for descending order. | | `sort` | string | no | The direction of the order, either `asc` (default) for ascending order or `desc` for descending order. |
| `package_type` | string | no | Filter the returned packages by type. One of `conan`, `maven`, `npm` or `nuget`. (_Introduced in GitLab 12.9_) |
```shell ```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/groups/:id/packages?exclude_subgroups=true curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/groups/:id/packages?exclude_subgroups=true
......
...@@ -25,14 +25,14 @@ module API ...@@ -25,14 +25,14 @@ module API
desc: 'Return packages ordered by `created_at`, `name`, `version` or `type` fields.' desc: 'Return packages ordered by `created_at`, `name`, `version` or `type` fields.'
optional :sort, type: String, values: %w[asc desc], default: 'asc', optional :sort, type: String, values: %w[asc desc], default: 'asc',
desc: 'Return packages sorted in `asc` or `desc` order.' desc: 'Return packages sorted in `asc` or `desc` order.'
optional :package_type, type: String, values: Packages::Package.package_types.keys,
desc: 'Return packages of a certain type'
end end
get ':id/packages' do get ':id/packages' do
packages = Packages::GroupPackagesFinder.new( packages = Packages::GroupPackagesFinder.new(
current_user, current_user,
user_group, user_group,
exclude_subgroups: params[:exclude_subgroups], declared(params).slice(:exclude_subgroups, :order_by, :sort, :package_type)
order_by: params[:order_by],
sort: params[:sort]
).execute ).execute
present paginate(packages), with: EE::API::Entities::Package, user: current_user, group: true present paginate(packages), with: EE::API::Entities::Package, user: current_user, group: true
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
require 'spec_helper' require 'spec_helper'
describe API::GroupPackages do describe API::GroupPackages do
let(:group) { create(:group, :public) } let_it_be(:group) { create(:group, :public) }
let(:project) { create(:project, :public, namespace: group, name: 'project A') } let_it_be(:project) { create(:project, :public, namespace: group, name: 'project A') }
let!(:package1) { create(:npm_package, project: project, version: '3.1.0', name: "@#{project.root_namespace.path}/foo1") } let!(:package1) { create(:npm_package, project: project, version: '3.1.0', name: "@#{project.root_namespace.path}/foo1") }
let!(:package2) { create(:nuget_package, project: project, version: '2.0.4') } let!(:package2) { create(:nuget_package, project: project, version: '2.0.4') }
let(:user) { create(:user) } let(:user) { create(:user) }
...@@ -128,6 +128,31 @@ describe API::GroupPackages do ...@@ -128,6 +128,31 @@ describe API::GroupPackages do
it_behaves_like 'returns paginated packages' it_behaves_like 'returns paginated packages'
end end
context 'filtering on package_type' do
let_it_be(:package1) { create(:conan_package, project: project) }
let_it_be(:package2) { create(:maven_package, project: project) }
let_it_be(:package3) { create(:npm_package, project: project) }
let_it_be(:package4) { create(:nuget_package, project: project) }
context 'for each type' do
%w[conan maven npm nuget].each do |package_type|
it "returns #{package_type} packages" do
url = "/groups/#{group.id}/packages?package_type=#{package_type}"
get api(url)
expect(json_response.map { |package| package['package_type'] }).to eq([package_type])
end
end
end
context 'does not accept non supported package_type value' do
let(:url) { "/groups/#{group.id}/packages?package_type=foo" }
it_behaves_like 'returning response status', :bad_request
end
end
end end
context 'with packages feature disabled' do context 'with packages feature disabled' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment