Commit 537da4b3 authored by Nick Kipling's avatar Nick Kipling Committed by Rémy Coutable

Adds PyPi to package list tabs

Updates the frontend to show the PyPi tab
Updated the projects API to accept new param
Updated tests
parent 7c61599f
...@@ -89,4 +89,8 @@ export const PACKAGE_REGISTRY_TABS = [ ...@@ -89,4 +89,8 @@ export const PACKAGE_REGISTRY_TABS = [
title: s__('PackageRegistry|NuGet'), title: s__('PackageRegistry|NuGet'),
type: PackageType.NUGET, type: PackageType.NUGET,
}, },
{
title: s__('PackageRegistry|PyPi'),
type: PackageType.PYPI,
},
]; ];
...@@ -3,6 +3,7 @@ export const PackageType = { ...@@ -3,6 +3,7 @@ export const PackageType = {
MAVEN: 'maven', MAVEN: 'maven',
NPM: 'npm', NPM: 'npm',
NUGET: 'nuget', NUGET: 'nuget',
PYPI: 'pypi',
}; };
export const TrackingActions = { export const TrackingActions = {
......
---
title: Adds PyPi tab to the packages list page
merge_request: 30078
author:
type: added
...@@ -24,7 +24,7 @@ module API ...@@ -24,7 +24,7 @@ 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: %w[conan maven npm nuget], optional :package_type, type: String, values: Packages::Package.package_types.keys,
desc: 'Return packages of a certain type' desc: 'Return packages of a certain type'
optional :package_name, type: String, optional :package_name, type: String,
desc: 'Return packages with this name' desc: 'Return packages with this name'
......
...@@ -334,6 +334,73 @@ exports[`packages_list_app renders 1`] = ` ...@@ -334,6 +334,73 @@ exports[`packages_list_app renders 1`] = `
</p> </p>
</p> </p>
<div
class="text-center"
>
<!---->
<!---->
</div>
</div>
</div>
</div>
</div>
</template>
</b-tab-stub>
<b-tab-stub
buttonid=""
tag="div"
title="PyPi"
titlelinkclass="gl-tab-nav-item"
>
<template>
<div>
<div
class="row empty-state"
>
<div
class="col-12"
>
<div
class="svg-250 svg-content"
>
<img
alt="There are no PyPi packages yet"
class=""
src="helpSvg"
/>
</div>
</div>
<div
class="col-12"
>
<div
class="text-content"
>
<h4
class="center"
style=""
>
There are no PyPi packages yet
</h4>
<p
class="center"
style=""
>
<p>
Learn how to
<a
href="helpUrl"
target="_blank"
>
publish and share your packages
</a>
with GitLab.
</p>
</p>
<div <div
class="text-center" class="text-center"
> >
......
...@@ -129,29 +129,14 @@ describe API::GroupPackages do ...@@ -129,29 +129,14 @@ describe API::GroupPackages do
it_behaves_like 'returns paginated packages' it_behaves_like 'returns paginated packages'
end end
context 'filtering on package_type' do it_behaves_like 'filters on each package_type', is_project: false
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 context 'does not accept non supported package_type value' do
%w[conan maven npm nuget].each do |package_type| include_context 'package filter context'
it "returns #{package_type} packages" do
url = "/groups/#{group.id}/packages?package_type=#{package_type}"
get api(url) let(:url) { group_filter_url(:type, 'foo') }
expect(json_response.map { |package| package['package_type'] }).to eq([package_type]) it_behaves_like 'returning response status', :bad_request
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 end
......
...@@ -95,26 +95,11 @@ describe API::ProjectPackages do ...@@ -95,26 +95,11 @@ describe API::ProjectPackages do
end end
end end
context 'filtering on package_type' do it_behaves_like 'filters on each package_type', is_project: true
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 = package_filter_url(:type, package_type)
get api(url, user)
expect(json_response.length).to eq(1)
expect(json_response.map { |package| package['package_type'] }).to contain_exactly(package_type)
end
end
end
end
context 'filtering on package_name' do context 'filtering on package_name' do
include_context 'package filter context'
it 'returns the named package' do it 'returns the named package' do
url = package_filter_url(:name, 'nuget') url = package_filter_url(:name, 'nuget')
get api(url, user) get api(url, user)
...@@ -123,10 +108,6 @@ describe API::ProjectPackages do ...@@ -123,10 +108,6 @@ describe API::ProjectPackages do
expect(json_response.first['name']).to include(package2.name) expect(json_response.first['name']).to include(package2.name)
end end
end end
def package_filter_url(filter, param)
"/projects/#{project.id}/packages?package_#{filter}=#{param}"
end
end end
context 'packages feature disabled' do context 'packages feature disabled' do
......
...@@ -142,6 +142,42 @@ RSpec.shared_examples 'background upload schedules a file migration' do ...@@ -142,6 +142,42 @@ RSpec.shared_examples 'background upload schedules a file migration' do
end end
end end
RSpec.shared_context 'package filter context' do
def package_filter_url(filter, param)
"/projects/#{project.id}/packages?package_#{filter}=#{param}"
end
def group_filter_url(filter, param)
"/groups/#{group.id}/packages?package_#{filter}=#{param}"
end
end
RSpec.shared_examples 'filters on each package_type' do |is_project: false|
include_context 'package filter context'
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) }
let_it_be(:package5) { create(:pypi_package, project: project) }
let_it_be(:package6) { create(:composer_package, project: project) }
Packages::Package.package_types.keys.each do |package_type|
context "for package type #{package_type}" do
let(:url) { is_project ? package_filter_url(:type, package_type) : group_filter_url(:type, package_type) }
subject { get api(url, user) }
it "returns #{package_type} packages" do
subject
expect(json_response.length).to eq(1)
expect(json_response.map { |package| package['package_type'] }).to contain_exactly(package_type)
end
end
end
end
shared_examples 'package workhorse uploads' do shared_examples 'package workhorse uploads' do
context 'without a workhorse header' do context 'without a workhorse header' do
let(:workhorse_token) { JWT.encode({ 'iss' => 'invalid header' }, Gitlab::Workhorse.secret, 'HS256') } let(:workhorse_token) { JWT.encode({ 'iss' => 'invalid header' }, Gitlab::Workhorse.secret, 'HS256') }
......
...@@ -14530,6 +14530,9 @@ msgstr "" ...@@ -14530,6 +14530,9 @@ msgstr ""
msgid "PackageRegistry|Published to the repository at %{timestamp}" msgid "PackageRegistry|Published to the repository at %{timestamp}"
msgstr "" msgstr ""
msgid "PackageRegistry|PyPi"
msgstr ""
msgid "PackageRegistry|Registry Setup" msgid "PackageRegistry|Registry Setup"
msgstr "" msgstr ""
......
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