Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
255b205c
Commit
255b205c
authored
Feb 19, 2020
by
Sean Carroll
Committed by
Stan Hu
Feb 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add filepath column to release_links
Part of
https://gitlab.com/gitlab-org/gitlab/issues/27300
parent
5e6aa649
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
0 deletions
+64
-0
app/models/releases/link.rb
app/models/releases/link.rb
+3
-0
changelogs/unreleased/27300-enable-a-direct-link-to-a-release-and-release-assets-2.yml
...nable-a-direct-link-to-a-release-and-release-assets-2.yml
+5
-0
db/migrate/20200219105209_add_filepath_to_release_links.rb
db/migrate/20200219105209_add_filepath_to_release_links.rb
+8
-0
db/schema.rb
db/schema.rb
+1
-0
spec/factories/releases/link.rb
spec/factories/releases/link.rb
+1
-0
spec/lib/gitlab/import_export/safe_model_attributes.yml
spec/lib/gitlab/import_export/safe_model_attributes.yml
+1
-0
spec/models/releases/link_spec.rb
spec/models/releases/link_spec.rb
+45
-0
No files found.
app/models/releases/link.rb
View file @
255b205c
...
...
@@ -6,8 +6,11 @@ module Releases
belongs_to
:release
FILEPATH_REGEX
=
/\A\/([\-\.\w]+\/?)*[\da-zA-Z]+\z/
.
freeze
validates
:url
,
presence:
true
,
addressable_url:
{
schemes:
%w(http https ftp)
},
uniqueness:
{
scope: :release
}
validates
:name
,
presence:
true
,
uniqueness:
{
scope: :release
}
validates
:filepath
,
uniqueness:
{
scope: :release
},
format:
{
with:
FILEPATH_REGEX
},
allow_blank:
true
,
length:
{
maximum:
128
}
scope
:sorted
,
->
{
order
(
created_at: :desc
)
}
...
...
changelogs/unreleased/27300-enable-a-direct-link-to-a-release-and-release-assets-2.yml
0 → 100644
View file @
255b205c
---
title
:
Add filepath to ReleaseLink
merge_request
:
25512
author
:
type
:
added
db/migrate/20200219105209_add_filepath_to_release_links.rb
0 → 100644
View file @
255b205c
# frozen_string_literal: true
class
AddFilepathToReleaseLinks
<
ActiveRecord
::
Migration
[
6.0
]
DOWNTIME
=
false
def
change
add_column
:release_links
,
:filepath
,
:string
,
limit:
128
end
end
db/schema.rb
View file @
255b205c
...
...
@@ -3648,6 +3648,7 @@ ActiveRecord::Schema.define(version: 2020_02_21_105436) do
t
.
string
"name"
,
null:
false
t
.
datetime_with_timezone
"created_at"
,
null:
false
t
.
datetime_with_timezone
"updated_at"
,
null:
false
t
.
string
"filepath"
,
limit:
128
t
.
index
[
"release_id"
,
"name"
],
name:
"index_release_links_on_release_id_and_name"
,
unique:
true
t
.
index
[
"release_id"
,
"url"
],
name:
"index_release_links_on_release_id_and_url"
,
unique:
true
end
...
...
spec/factories/releases/link.rb
View file @
255b205c
...
...
@@ -5,5 +5,6 @@ FactoryBot.define do
release
sequence
(
:name
)
{
|
n
|
"release-18.
#{
n
}
.dmg"
}
sequence
(
:url
)
{
|
n
|
"https://example.com/scrambled-url/app-
#{
n
}
.zip"
}
sequence
(
:filepath
)
{
|
n
|
"/binaries/awesome-app-
#{
n
}
"
}
end
end
spec/lib/gitlab/import_export/safe_model_attributes.yml
View file @
255b205c
...
...
@@ -133,6 +133,7 @@ Releases::Link:
-
id
-
url
-
name
-
filepath
-
created_at
-
updated_at
ProjectMember
:
...
...
spec/models/releases/link_spec.rb
View file @
255b205c
...
...
@@ -13,6 +13,7 @@ describe Releases::Link do
describe
'validation'
do
it
{
is_expected
.
to
validate_presence_of
(
:url
)
}
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
it
{
is_expected
.
to
validate_length_of
(
:filepath
).
is_at_most
(
128
)
}
context
'when url is invalid'
do
let
(
:link
)
{
build
(
:release_link
,
url:
'hoge'
)
}
...
...
@@ -43,6 +44,16 @@ describe Releases::Link do
end
end
context
'when duplicate filepath is added to a release'
do
let!
(
:link
)
{
create
(
:release_link
,
filepath:
'/binaries/gitlab-runner-linux-amd64'
,
release:
release
)
}
it
'raises an error'
do
expect
do
create
(
:release_link
,
filepath:
'/binaries/gitlab-runner-linux-amd64'
,
release:
release
)
end
.
to
raise_error
(
ActiveRecord
::
RecordInvalid
)
end
end
describe
'.sorted'
do
subject
{
described_class
.
sorted
}
...
...
@@ -101,4 +112,38 @@ describe Releases::Link do
end
end
end
describe
'FILEPATH_REGEX with table'
do
using
RSpec
::
Parameterized
::
TableSyntax
let
(
:link
)
{
build
(
:release_link
)}
where
(
:reason
,
:filepath
,
:result
)
do
'cannot contain `//`'
|
'/https//www.example.com'
|
be_invalid
'cannot start with `//`'
|
'//www.example.com'
|
be_invalid
'cannot contain a `?`'
|
'/example.com/?stuff=true'
|
be_invalid
'cannot contain a `:`'
|
'/example:5000'
|
be_invalid
'cannot end in a `-`'
|
'/binaries/awesome-app.dmg-'
|
be_invalid
'cannot end in a `.`'
|
'/binaries/awesome-app.dmg.'
|
be_invalid
'cannot end in a `_`'
|
'/binaries/awesome-app.dmg_'
|
be_invalid
'cannot start with a `.`'
|
'.binaries/awesome-app.dmg'
|
be_invalid
'cannot start with a `-`'
|
'-binaries/awesome-app.dmg'
|
be_invalid
'cannot start with a `_`'
|
'_binaries/awesome-app.dmg'
|
be_invalid
'cannot start with a number'
|
'3binaries/awesome-app.dmg'
|
be_invalid
'cannot start with a letter'
|
'binaries/awesome-app.dmg'
|
be_invalid
'cannot contain accents'
|
'/binarïes/âwésome-app.dmg'
|
be_invalid
'can end in a character'
|
'/binaries/awesome-app.dmg'
|
be_valid
'can end in a number'
|
'/binaries/awesome-app-1'
|
be_valid
'can contain one or more dots, dashes or underscores'
|
'/sub_tr__ee.ex..ample-2--1/v99.com'
|
be_valid
'can contain multiple non-sequential slashes'
|
'/example.com/path/to/file.exe'
|
be_valid
'can be nil'
|
nil
|
be_valid
end
with_them
do
specify
do
link
.
filepath
=
filepath
expect
(
link
).
to
result
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment