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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
c837da34
Commit
c837da34
authored
Mar 24, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Helper method for storage path stripping
parent
b46ac16c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
8 deletions
+49
-8
app/workers/post_receive.rb
app/workers/post_receive.rb
+4
-8
lib/gitlab/repo_path.rb
lib/gitlab/repo_path.rb
+23
-0
spec/lib/gitlab/repo_path_spec.rb
spec/lib/gitlab/repo_path_spec.rb
+22
-0
No files found.
app/workers/post_receive.rb
View file @
c837da34
...
@@ -3,20 +3,16 @@ class PostReceive
...
@@ -3,20 +3,16 @@ class PostReceive
include
DedicatedSidekiqQueue
include
DedicatedSidekiqQueue
def
perform
(
repo_path
,
identifier
,
changes
)
def
perform
(
repo_path
,
identifier
,
changes
)
if
repository_storage
=
Gitlab
.
config
.
repositories
.
storages
.
find
{
|
p
|
repo_path
.
start_with?
(
p
[
1
][
'path'
].
to_s
)
}
repo_relative_path
=
Gitlab
::
RepoPath
.
strip_storage_path
(
repo_path
)
repo_path
.
gsub!
(
repository_storage
[
1
][
'path'
].
to_s
,
""
)
else
log
(
"Check gitlab.yml config for correct repositories.storages values. No repository storage path matches
\"
#{
repo_path
}
\"
"
)
end
changes
=
Base64
.
decode64
(
changes
)
unless
changes
.
include?
(
' '
)
changes
=
Base64
.
decode64
(
changes
)
unless
changes
.
include?
(
' '
)
# Use Sidekiq.logger so arguments can be correlated with execution
# Use Sidekiq.logger so arguments can be correlated with execution
# time and thread ID's.
# time and thread ID's.
Sidekiq
.
logger
.
info
"changes:
#{
changes
.
inspect
}
"
if
ENV
[
'SIDEKIQ_LOG_ARGUMENTS'
]
Sidekiq
.
logger
.
info
"changes:
#{
changes
.
inspect
}
"
if
ENV
[
'SIDEKIQ_LOG_ARGUMENTS'
]
post_received
=
Gitlab
::
GitPostReceive
.
new
(
repo_path
,
identifier
,
changes
)
post_received
=
Gitlab
::
GitPostReceive
.
new
(
repo_
relative_
path
,
identifier
,
changes
)
if
post_received
.
project
.
nil?
if
post_received
.
project
.
nil?
log
(
"Triggered hook for non-existing project with full path
\"
#{
repo_path
}
\"
"
)
log
(
"Triggered hook for non-existing project with full path
\"
#{
repo_
relative_
path
}
\"
"
)
return
false
return
false
end
end
...
@@ -25,7 +21,7 @@ class PostReceive
...
@@ -25,7 +21,7 @@ class PostReceive
elsif
post_received
.
regular_project?
elsif
post_received
.
regular_project?
process_project_changes
(
post_received
)
process_project_changes
(
post_received
)
else
else
log
(
"Triggered hook for unidentifiable repository type with full path
\"
#{
repo_path
}
\"
"
)
log
(
"Triggered hook for unidentifiable repository type with full path
\"
#{
repo_
relative_
path
}
\"
"
)
false
false
end
end
end
end
...
...
lib/gitlab/repo_path.rb
0 → 100644
View file @
c837da34
module
Gitlab
module
RepoPath
NotFoundError
=
Class
.
new
(
StandardError
)
def
self
.
strip_storage_path
(
repo_path
)
result
=
nil
Gitlab
.
config
.
repositories
.
storages
.
values
.
each
do
|
params
|
storage_path
=
params
[
'path'
]
if
repo_path
.
start_with?
(
storage_path
)
result
=
repo_path
.
sub
(
storage_path
,
''
)
break
end
end
if
result
.
nil?
raise
NotFoundError
.
new
(
"No known storage path matches
#{
repo_path
.
inspect
}
"
)
end
result
.
sub
(
/\A\/*/
,
''
)
end
end
end
spec/lib/gitlab/repo_path_spec.rb
0 → 100644
View file @
c837da34
require
'spec_helper'
describe
::
Gitlab
::
RepoPath
do
describe
'.strip_storage_path'
do
before
do
allow
(
Gitlab
.
config
.
repositories
).
to
receive
(
:storages
).
and_return
({
'storage1'
=>
{
'path'
=>
'/foo'
},
'storage2'
=>
{
'path'
=>
'/bar'
},
})
end
it
'strips the storage path'
do
expect
(
described_class
.
strip_storage_path
(
'/bar/foo/qux/baz.git'
)).
to
eq
(
'foo/qux/baz.git'
)
end
it
'raises NotFoundError if no storage matches the path'
do
expect
{
described_class
.
strip_storage_path
(
'/doesnotexist/foo.git'
)
}.
to
raise_error
(
described_class
::
NotFoundError
)
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