Commit 318f01f5 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch 'add-golang-to-packages' into 'master'

Add Golang Package type

See merge request gitlab-org/gitlab!41712
parents 55eb2732 a7c32fe2
......@@ -40,12 +40,13 @@ class Packages::Package < ApplicationRecord
validates :version, format: { with: Gitlab::Regex.conan_recipe_component_regex }, if: :conan?
validates :version, format: { with: Gitlab::Regex.maven_version_regex }, if: -> { version? && maven? }
validates :version, format: { with: Gitlab::Regex.pypi_version_regex }, if: :pypi?
validates :version, format: { with: Gitlab::Regex.prefixed_semver_regex }, if: :golang?
validates :version,
presence: true,
format: { with: Gitlab::Regex.generic_package_version_regex },
if: :generic?
enum package_type: { maven: 1, npm: 2, conan: 3, nuget: 4, pypi: 5, composer: 6, generic: 7 }
enum package_type: { maven: 1, npm: 2, conan: 3, nuget: 4, pypi: 5, composer: 6, generic: 7, golang: 8 }
scope :with_name, ->(name) { where(name: name) }
scope :with_name_like, ->(name) { where(arel_table[:name].matches(name)) }
......
---
title: Add Go(lang) to Packages
merge_request: 41712
author: Ethan Reesor (@firelizzard)
type: added
# frozen_string_literal: true
class AddGolangPackageMaxFileSizeToPlanLimits < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column(:plan_limits, :golang_max_file_size, :bigint, default: 100.megabytes, null: false)
end
end
860c45fd6293f2f8f10d7351cb5a2fbab2cc9147e56b538cb62d75469b039ef0
\ No newline at end of file
......@@ -14364,7 +14364,8 @@ CREATE TABLE plan_limits (
npm_max_file_size bigint DEFAULT 524288000 NOT NULL,
nuget_max_file_size bigint DEFAULT 524288000 NOT NULL,
pypi_max_file_size bigint DEFAULT '3221225472'::bigint NOT NULL,
generic_packages_max_file_size bigint DEFAULT '5368709120'::bigint NOT NULL
generic_packages_max_file_size bigint DEFAULT '5368709120'::bigint NOT NULL,
golang_max_file_size bigint DEFAULT 104857600 NOT NULL
);
CREATE SEQUENCE plan_limits_id_seq
......
......@@ -11536,6 +11536,11 @@ enum PackageTypeEnum {
"""
GENERIC
"""
Packages from the golang package manager
"""
GOLANG
"""
Packages from the maven package manager
"""
......
......@@ -34436,6 +34436,12 @@
"description": "Packages from the generic package manager",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "GOLANG",
"description": "Packages from the golang package manager",
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
......@@ -3290,6 +3290,7 @@ Values for sorting projects.
| `COMPOSER` | Packages from the composer package manager |
| `CONAN` | Packages from the conan package manager |
| `GENERIC` | Packages from the generic package manager |
| `GOLANG` | Packages from the golang package manager |
| `MAVEN` | Packages from the maven package manager |
| `NPM` | Packages from the npm package manager |
| `NUGET` | Packages from the nuget package manager |
......
......@@ -26,7 +26,7 @@ GET /projects/:id/packages
| `id` | integer/string | yes | ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) |
| `order_by`| string | no | The field to use as order. One of `created_at` (default), `name`, `version`, or `type`. |
| `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`, `pypi`, `composer`, or `nuget`. (_Introduced in GitLab 12.9_)
| `package_type` | string | no | Filter the returned packages by type. One of `conan`, `maven`, `npm`, `pypi`, `composer`, `nuget`, or `golang`. (_Introduced in GitLab 12.9_)
| `package_name` | string | no | Filter the project packages with a fuzzy search by name. (_Introduced in GitLab 12.9_)
```shell
......@@ -73,7 +73,7 @@ GET /groups/:id/packages
| `exclude_subgroups` | boolean | false | If the parameter 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`, `pypi`, `composer`, or `nuget`. (_Introduced in GitLab 12.9_) |
| `package_type` | string | no | Filter the returned packages by type. One of `conan`, `maven`, `npm`, `pypi`, `composer`, `nuget`, or `golang`. (_Introduced in GitLab 12.9_) |
| `package_name` | string | no | Filter the project packages with a fuzzy search by name. (_[Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/30980) in GitLab 13.0_)
```shell
......
......@@ -80,6 +80,11 @@ module Gitlab
@semver_regex ||= Regexp.new("\\A#{::Gitlab::Regex.unbounded_semver_regex.source}\\z", ::Gitlab::Regex.unbounded_semver_regex.options)
end
def prefixed_semver_regex
# identical to semver_regex, except starting with 'v'
@prefixed_semver_regex ||= Regexp.new("\\Av#{::Gitlab::Regex.unbounded_semver_regex.source}\\z", ::Gitlab::Regex.unbounded_semver_regex.options)
end
def go_package_regex
# A Go package name looks like a URL but is not; it:
# - Must not have a scheme, such as http:// or https://
......
......@@ -91,6 +91,12 @@ FactoryBot.define do
end
end
factory :golang_package do
sequence(:name) { |n| "golang.org/x/pkg-#{n}"}
sequence(:version) { |n| "v1.0.#{n}" }
package_type { :golang }
end
factory :conan_package do
conan_metadatum
......
......@@ -4,6 +4,6 @@ require 'spec_helper'
RSpec.describe GitlabSchema.types['PackageTypeEnum'] do
it 'exposes all package types' do
expect(described_class.values.keys).to contain_exactly(*%w[MAVEN NPM CONAN NUGET PYPI COMPOSER GENERIC])
expect(described_class.values.keys).to contain_exactly(*%w[MAVEN NPM CONAN NUGET PYPI COMPOSER GENERIC GOLANG])
end
end
......@@ -448,4 +448,17 @@ RSpec.describe Gitlab::Regex do
it { is_expected.not_to match('my file name') }
it { is_expected.not_to match('!!()()') }
end
describe '.prefixed_semver_regex' do
subject { described_class.prefixed_semver_regex }
it { is_expected.to match('v1.2.3') }
it { is_expected.to match('v1.2.3-beta') }
it { is_expected.to match('v1.2.3-alpha.3') }
it { is_expected.not_to match('v1') }
it { is_expected.not_to match('v1.2') }
it { is_expected.not_to match('v1./2.3') }
it { is_expected.not_to match('v../../../../../1.2.3') }
it { is_expected.not_to match('v%2e%2e%2f1.2.3') }
end
end
......@@ -170,6 +170,7 @@ RSpec.shared_examples 'filters on each package_type' do |is_project: false|
let_it_be(:package5) { create(:pypi_package, project: project) }
let_it_be(:package6) { create(:composer_package, project: project) }
let_it_be(:package7) { create(:generic_package, project: project) }
let_it_be(:package8) { create(:golang_package, project: project) }
Packages::Package.package_types.keys.each do |package_type|
context "for package type #{package_type}" 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