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
07be72a3
Commit
07be72a3
authored
Jan 29, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate route map
parent
4aad7b5c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
13 deletions
+58
-13
app/models/project.rb
app/models/project.rb
+5
-12
app/views/projects/blob/_actions.html.haml
app/views/projects/blob/_actions.html.haml
+1
-1
lib/gitlab/route_map.rb
lib/gitlab/route_map.rb
+52
-0
No files found.
app/models/project.rb
View file @
07be72a3
...
@@ -1549,7 +1549,7 @@ class Project < ActiveRecord::Base
...
@@ -1549,7 +1549,7 @@ class Project < ActiveRecord::Base
deployments_query
=
with_tags
?
'ref = ? OR tag IS TRUE'
:
'ref = ?'
deployments_query
=
with_tags
?
'ref = ? OR tag IS TRUE'
:
'ref = ?'
deployments
.
where
(
deployments_query
,
ref
.
to_s
)
deployments
.
where
(
deployments_query
,
ref
.
to_s
)
elsif
commit
elsif
commit
dep
s
=
dep
loyments
.
where
(
sha:
commit
.
sha
)
deployments
.
where
(
sha:
commit
.
sha
)
else
else
Deployment
.
none
Deployment
.
none
end
end
...
@@ -1585,13 +1585,9 @@ class Project < ActiveRecord::Base
...
@@ -1585,13 +1585,9 @@ class Project < ActiveRecord::Base
data
=
repository
.
route_map_file
(
sha
)
data
=
repository
.
route_map_file
(
sha
)
next
unless
data
next
unless
data
# TODO: Validate
Gitlab
::
RouteMap
.
new
(
data
)
YAML
.
safe_load
(
data
).
map
do
|
mapping
|
rescue
Gitlab
::
RouteMap
::
FormatError
{
nil
source:
Regexp
.
new
(
"^
#{
mapping
[
'source'
][
1
...-
1
]
}
$"
),
public:
mapping
[
'public'
]
}
end
end
end
end
end
...
@@ -1602,10 +1598,7 @@ class Project < ActiveRecord::Base
...
@@ -1602,10 +1598,7 @@ class Project < ActiveRecord::Base
map
=
route_map_for_commit
(
commit_sha
)
map
=
route_map_for_commit
(
commit_sha
)
return
unless
map
return
unless
map
mapping
=
map
.
find
{
|
mapping
|
path
=~
mapping
[
:source
]
}
map
.
public_path_for_source_path
(
path
)
return
unless
mapping
path
.
sub
(
mapping
[
:source
],
mapping
[
:public
])
end
end
private
private
...
...
app/views/projects/blob/_actions.html.haml
View file @
07be72a3
lib/gitlab/route_map.rb
0 → 100644
View file @
07be72a3
module
Gitlab
class
RouteMap
class
FormatError
<
StandardError
;
end
def
initialize
(
data
)
begin
entries
=
YAML
.
safe_load
(
data
)
rescue
raise
FormatError
,
'Route map needs to be valid YAML'
end
raise
FormatError
,
'Route map needs to be an array'
unless
entries
.
is_a?
(
Array
)
@map
=
entries
.
map
{
|
entry
|
parse_entry
(
entry
)
}
end
def
public_path_for_source_path
(
path
)
mapping
=
@map
.
find
{
|
mapping
|
path
=~
mapping
[
:source
]
}
return
unless
mapping
path
.
sub
(
mapping
[
:source
],
mapping
[
:public
])
end
private
def
parse_entry
(
entry
)
raise
FormatError
,
'Route map entry needs to be a hash'
unless
entry
.
is_a?
(
Hash
)
raise
FormatError
,
'Route map entry requires a source key'
unless
entry
.
has_key?
(
'source'
)
raise
FormatError
,
'Route map entry requires a public key'
unless
entry
.
has_key?
(
'public'
)
source_regexp
=
entry
[
'source'
]
public_path
=
entry
[
'public'
]
unless
source_regexp
.
start_with?
(
'/'
)
&&
source_regexp
.
end_with?
(
'/'
)
raise
FormatError
,
'Route map entry source needs to start and end in a slash (/)'
end
source_regexp
=
source_regexp
[
1
...-
1
].
gsub
(
'\/'
,
'/'
)
begin
source_regexp
=
Regexp
.
new
(
"^
#{
source_regexp
}
$"
)
rescue
RegexpError
=>
e
raise
FormatError
,
"Route map entry source needs to be a valid regular expression:
#{
e
}
"
end
{
source:
source_regexp
,
public:
public_path
}
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