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
0e6e54eb
Commit
0e6e54eb
authored
Jun 19, 2017
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use gl_repository exclusively as identifier on post-receive
parent
7718377a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
54 deletions
+21
-54
app/workers/post_receive.rb
app/workers/post_receive.rb
+3
-18
spec/workers/ee/post_receive_spec.rb
spec/workers/ee/post_receive_spec.rb
+5
-11
spec/workers/post_receive_spec.rb
spec/workers/post_receive_spec.rb
+13
-25
No files found.
app/workers/post_receive.rb
View file @
0e6e54eb
...
...
@@ -3,11 +3,11 @@ class PostReceive
include
DedicatedSidekiqQueue
prepend
EE
::
PostReceive
def
perform
(
project_identifier
,
identifier
,
changes
)
project
,
is_wiki
=
parse_project_identifier
(
project_identifier
)
def
perform
(
gl_repository
,
identifier
,
changes
)
project
,
is_wiki
=
Gitlab
::
GlRepository
.
parse
(
gl_repository
)
if
project
.
nil?
log
(
"Triggered hook for non-existing project with
identifier
\"
#{
project_identifier
}
\"
"
)
log
(
"Triggered hook for non-existing project with
gl_repository
\"
#{
gl_repository
}
\"
"
)
return
false
end
...
...
@@ -60,21 +60,6 @@ class PostReceive
# Nothing defined here yet.
end
# To maintain backwards compatibility, we accept both gl_repository or
# repository paths as project identifiers. Our plan is to migrate to
# gl_repository only with the following plan:
# 9.2: Handle both possible values. Keep Gitlab-Shell sending only repo paths
# 9.3 (or patch release): Make GitLab Shell pass gl_repository if present
# 9.4 (or patch release): Make GitLab Shell always pass gl_repository
# 9.5 (or patch release): Handle only gl_repository as project identifier on this method
def
parse_project_identifier
(
project_identifier
)
if
project_identifier
.
start_with?
(
'/'
)
Gitlab
::
RepoPath
.
parse
(
project_identifier
)
else
Gitlab
::
GlRepository
.
parse
(
project_identifier
)
end
end
def
log
(
message
)
Gitlab
::
GitLogger
.
error
(
"POST-RECEIVE:
#{
message
}
"
)
end
...
...
spec/workers/ee/post_receive_spec.rb
View file @
0e6e54eb
...
...
@@ -4,7 +4,7 @@ describe PostReceive do
let
(
:changes
)
{
"123456 789012 refs/heads/tést
\n
654321 210987 refs/tags/tag"
}
let
(
:wrongly_encoded_changes
)
{
changes
.
encode
(
"ISO-8859-1"
).
force_encoding
(
"UTF-8"
)
}
let
(
:base64_changes
)
{
Base64
.
encode64
(
wrongly_encoded_changes
)
}
let
(
:
project_identifier
)
{
"project-
#{
project
.
id
}
"
}
let
(
:
gl_repository
)
{
"project-
#{
project
.
id
}
"
}
let
(
:key
)
{
create
(
:key
,
user:
project
.
owner
)
}
let
(
:key_id
)
{
key
.
shell_id
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
...
...
@@ -28,13 +28,13 @@ describe PostReceive do
it
'calls Geo::RepositoryUpdatedEventStore'
do
expect_any_instance_of
(
Geo
::
RepositoryUpdatedEventStore
).
to
receive
(
:create
)
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
end
end
end
describe
'#process_wiki_changes'
do
let
(
:
project_identifier
)
{
"
#{
pwd
(
project
)
}
.wiki
"
}
let
(
:
gl_repository
)
{
"wiki-
#{
project
.
id
}
"
}
it
'triggers Geo::RepositoryUpdatedEventStore when Geo is enabled'
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:enabled?
)
{
true
}
...
...
@@ -42,21 +42,15 @@ describe PostReceive do
expect
(
Geo
::
RepositoryUpdatedEventStore
).
to
receive
(
:new
).
with
(
instance_of
(
Project
),
source:
Geo
::
RepositoryUpdatedEvent
::
WIKI
).
and_call_original
expect_any_instance_of
(
Geo
::
RepositoryUpdatedEventStore
).
to
receive
(
:create
)
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
end
it
'triggers wiki index update when ElasticSearch is enabled'
do
expect
(
Project
).
to
receive
(
:find_by_full_path
).
with
(
"
#{
project
.
full_path
}
.wiki"
,
follow_redirects:
true
).
and_return
(
nil
)
expect
(
Project
).
to
receive
(
:find_by_full_path
).
with
(
project
.
full_path
,
follow_redirects:
true
).
and_return
(
project
)
stub_application_setting
(
elasticsearch_search:
true
,
elasticsearch_indexing:
true
)
expect_any_instance_of
(
ProjectWiki
).
to
receive
(
:index_blobs
)
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
end
end
def
pwd
(
project
)
File
.
join
(
Gitlab
.
config
.
repositories
.
storages
.
default
[
'path'
],
project
.
path_with_namespace
)
end
end
spec/workers/post_receive_spec.rb
View file @
0e6e54eb
...
...
@@ -4,7 +4,7 @@ describe PostReceive do
let
(
:changes
)
{
"123456 789012 refs/heads/tést
\n
654321 210987 refs/tags/tag"
}
let
(
:wrongly_encoded_changes
)
{
changes
.
encode
(
"ISO-8859-1"
).
force_encoding
(
"UTF-8"
)
}
let
(
:base64_changes
)
{
Base64
.
encode64
(
wrongly_encoded_changes
)
}
let
(
:
project_identifier
)
{
"project-
#{
project
.
id
}
"
}
let
(
:
gl_repository
)
{
"project-
#{
project
.
id
}
"
}
let
(
:key
)
{
create
(
:key
,
user:
project
.
owner
)
}
let
(
:key_id
)
{
key
.
shell_id
}
...
...
@@ -19,22 +19,14 @@ describe PostReceive do
end
context
'with a non-existing project'
do
let
(
:
project_identifier
)
{
"project-123456789"
}
let
(
:
gl_repository
)
{
"project-123456789"
}
let
(
:error_message
)
do
"Triggered hook for non-existing project with
identifier
\"
#{
project_identifier
}
\"
"
"Triggered hook for non-existing project with
gl_repository
\"
#{
gl_repository
}
\"
"
end
it
"returns false and logs an error"
do
expect
(
Gitlab
::
GitLogger
).
to
receive
(
:error
).
with
(
"POST-RECEIVE:
#{
error_message
}
"
)
expect
(
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)).
to
be
(
false
)
end
end
context
"with an absolute path as the project identifier"
do
it
"searches the project by full path"
do
expect
(
Project
).
to
receive
(
:find_by_full_path
).
with
(
project
.
full_path
,
follow_redirects:
true
).
and_call_original
described_class
.
new
.
perform
(
pwd
(
project
),
key_id
,
base64_changes
)
expect
(
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)).
to
be
(
false
)
end
end
...
...
@@ -49,7 +41,7 @@ describe PostReceive do
it
"calls GitTagPushService"
do
expect_any_instance_of
(
GitPushService
).
to
receive
(
:execute
).
and_return
(
true
)
expect_any_instance_of
(
GitTagPushService
).
not_to
receive
(
:execute
)
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
end
end
...
...
@@ -59,7 +51,7 @@ describe PostReceive do
it
"calls GitTagPushService"
do
expect_any_instance_of
(
GitPushService
).
not_to
receive
(
:execute
)
expect_any_instance_of
(
GitTagPushService
).
to
receive
(
:execute
).
and_return
(
true
)
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
end
end
...
...
@@ -69,12 +61,12 @@ describe PostReceive do
it
"does not call any of the services"
do
expect_any_instance_of
(
GitPushService
).
not_to
receive
(
:execute
)
expect_any_instance_of
(
GitTagPushService
).
not_to
receive
(
:execute
)
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
end
end
context
"gitlab-ci.yml"
do
subject
{
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)
}
subject
{
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
}
context
"creates a Ci::Pipeline for every change"
do
before
do
...
...
@@ -111,7 +103,7 @@ describe PostReceive do
it
'calls SystemHooksService'
do
expect_any_instance_of
(
SystemHooksService
).
to
receive
(
:execute_hooks
).
with
(
fake_hook_data
,
:repository_update_hooks
).
and_return
(
true
)
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
end
end
end
...
...
@@ -119,7 +111,7 @@ describe PostReceive do
context
"webhook"
do
it
"fetches the correct project"
do
expect
(
Project
).
to
receive
(
:find_by
).
with
(
id:
project
.
id
.
to_s
)
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
end
it
"does not run if the author is not in the project"
do
...
...
@@ -129,7 +121,7 @@ describe PostReceive do
expect
(
project
).
not_to
receive
(
:execute_hooks
)
expect
(
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)).
to
be_falsey
expect
(
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)).
to
be_falsey
end
it
"asks the project to trigger all hooks"
do
...
...
@@ -137,18 +129,14 @@ describe PostReceive do
expect
(
project
).
to
receive
(
:execute_hooks
).
twice
expect
(
project
).
to
receive
(
:execute_services
).
twice
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
end
it
"enqueues a UpdateMergeRequestsWorker job"
do
allow
(
Project
).
to
receive
(
:find_by
).
and_return
(
project
)
expect
(
UpdateMergeRequestsWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
project
.
owner
.
id
,
any_args
)
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)
end
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
end
def
pwd
(
project
)
File
.
join
(
Gitlab
.
config
.
repositories
.
storages
.
default
[
'path'
],
project
.
path_with_namespace
)
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