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
3fd02428
Commit
3fd02428
authored
Jun 05, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor PostReceive worker to limit merge conflicts
parent
38b3064c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
37 deletions
+30
-37
app/workers/post_receive.rb
app/workers/post_receive.rb
+17
-21
spec/workers/post_receive_spec.rb
spec/workers/post_receive_spec.rb
+13
-16
No files found.
app/workers/post_receive.rb
View file @
3fd02428
...
@@ -17,14 +17,15 @@ class PostReceive
...
@@ -17,14 +17,15 @@ class PostReceive
post_received
=
Gitlab
::
GitPostReceive
.
new
(
project
,
identifier
,
changes
)
post_received
=
Gitlab
::
GitPostReceive
.
new
(
project
,
identifier
,
changes
)
if
is_wiki
if
is_wiki
# Nothing defined here yet.
process_wiki_changes
(
post_received
)
else
else
process_project_changes
(
post_received
)
process_project_changes
(
post_received
)
process_repository_update
(
post_received
)
end
end
end
end
def
process_repository_update
(
post_received
)
private
def
process_project_changes
(
post_received
)
changes
=
[]
changes
=
[]
refs
=
Set
.
new
refs
=
Set
.
new
...
@@ -36,33 +37,28 @@ class PostReceive
...
@@ -36,33 +37,28 @@ class PostReceive
return
false
return
false
end
end
if
Gitlab
::
Git
.
tag_ref?
(
ref
)
GitTagPushService
.
new
(
post_received
.
project
,
@user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
).
execute
elsif
Gitlab
::
Git
.
branch_ref?
(
ref
)
GitPushService
.
new
(
post_received
.
project
,
@user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
).
execute
end
changes
<<
Gitlab
::
DataBuilder
::
Repository
.
single_change
(
oldrev
,
newrev
,
ref
)
changes
<<
Gitlab
::
DataBuilder
::
Repository
.
single_change
(
oldrev
,
newrev
,
ref
)
refs
<<
ref
refs
<<
ref
end
end
hook_data
=
Gitlab
::
DataBuilder
::
Repository
.
update
(
post_received
.
project
,
@user
,
changes
,
refs
.
to_a
)
after_project_changes_hooks
(
post_received
,
@user
,
refs
.
to_a
,
changes
)
SystemHooksService
.
new
.
execute_hooks
(
hook_data
,
:repository_update_hooks
)
end
end
def
process_project_changes
(
post_received
)
def
after_project_changes_hooks
(
post_received
,
user
,
refs
,
changes
)
post_received
.
changes_refs
do
|
oldrev
,
newrev
,
ref
|
hook_data
=
Gitlab
::
DataBuilder
::
Repository
.
update
(
post_received
.
project
,
user
,
changes
,
refs
)
@user
||=
post_received
.
identify
(
newrev
)
SystemHooksService
.
new
.
execute_hooks
(
hook_data
,
:repository_update_hooks
)
unless
@user
log
(
"Triggered hook for non-existing user
\"
#{
post_received
.
identifier
}
\"
"
)
return
false
end
end
if
Gitlab
::
Git
.
tag_ref?
(
ref
)
def
process_wiki_changes
(
post_received
)
GitTagPushService
.
new
(
post_received
.
project
,
@user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
).
execute
# Nothing defined here yet.
elsif
Gitlab
::
Git
.
branch_ref?
(
ref
)
GitPushService
.
new
(
post_received
.
project
,
@user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
).
execute
end
end
end
end
private
# To maintain backwards compatibility, we accept both gl_repository or
# To maintain backwards compatibility, we accept both gl_repository or
# repository paths as project identifiers. Our plan is to migrate to
# repository paths as project identifiers. Our plan is to migrate to
# gl_repository only with the following plan:
# gl_repository only with the following plan:
...
...
spec/workers/post_receive_spec.rb
View file @
3fd02428
...
@@ -94,26 +94,23 @@ describe PostReceive do
...
@@ -94,26 +94,23 @@ describe PostReceive do
it
{
expect
{
subject
}.
not_to
change
{
Ci
::
Pipeline
.
count
}
}
it
{
expect
{
subject
}.
not_to
change
{
Ci
::
Pipeline
.
count
}
}
end
end
end
end
end
describe
'#process_repository_update'
do
context
'after project changes hooks'
do
let
(
:changes
)
{
'123456 789012 refs/heads/tést'
}
let
(
:changes
)
{
'123456 789012 refs/heads/tést'
}
let
(
:fake_hook_data
)
do
let
(
:fake_hook_data
)
{
Hash
.
new
(
event_name:
'repository_update'
)
}
{
event_name:
'repository_update'
}
end
before
do
before
do
allow_any_instance_of
(
Gitlab
::
GitPostReceive
).
to
receive
(
:identify
).
and_return
(
project
.
owner
)
allow_any_instance_of
(
Gitlab
::
DataBuilder
::
Repository
).
to
receive
(
:update
).
and_return
(
fake_hook_data
)
allow_any_instance_of
(
Gitlab
::
DataBuilder
::
Repository
).
to
receive
(
:update
).
and_return
(
fake_hook_data
)
# silence hooks so we can isolate
# silence hooks so we can isolate
allow_any_instance_of
(
Key
).
to
receive
(
:post_create_hook
).
and_return
(
true
)
allow_any_instance_of
(
Key
).
to
receive
(
:post_create_hook
).
and_return
(
true
)
allow
(
subject
).
to
receive
(
:process_project_changes
).
and_return
(
true
)
allow_any_instance_of
(
GitPushService
).
to
receive
(
:execute
).
and_return
(
true
)
end
end
it
'calls SystemHooksService'
do
it
'calls SystemHooksService'
do
expect_any_instance_of
(
SystemHooksService
).
to
receive
(
:execute_hooks
).
with
(
fake_hook_data
,
:repository_update_hooks
).
and_return
(
true
)
expect_any_instance_of
(
SystemHooksService
).
to
receive
(
:execute_hooks
).
with
(
fake_hook_data
,
:repository_update_hooks
).
and_return
(
true
)
subject
.
perform
(
pwd
(
project
),
key_id
,
base64_changes
)
described_class
.
new
.
perform
(
project_identifier
,
key_id
,
base64_changes
)
end
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