Commit d52d97a0 authored by Nick Kipling's avatar Nick Kipling Committed by Mayra Cabrera

Added package_type to group packages api

Added package_type param to api options
Updated tests
Updated documentation
Added changelog entry
parent 8b58db35
---
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
| `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`. |
| `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
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
desc: 'Return packages ordered by `created_at`, `name`, `version` or `type` fields.'
optional :sort, type: String, values: %w[asc desc], default: 'asc',
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
get ':id/packages' do
packages = Packages::GroupPackagesFinder.new(
current_user,
user_group,
exclude_subgroups: params[:exclude_subgroups],
order_by: params[:order_by],
sort: params[:sort]
declared(params).slice(:exclude_subgroups, :order_by, :sort, :package_type)
).execute
present paginate(packages), with: EE::API::Entities::Package, user: current_user, group: true
......
......@@ -3,8 +3,8 @@
require 'spec_helper'
describe API::GroupPackages do
let(:group) { create(:group, :public) }
let(:project) { create(:project, :public, namespace: group, name: 'project A') }
let_it_be(:group) { create(:group, :public) }
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!(:package2) { create(:nuget_package, project: project, version: '2.0.4') }
let(:user) { create(:user) }
......@@ -128,6 +128,31 @@ describe API::GroupPackages do
it_behaves_like 'returns paginated packages'
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
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