Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab FOSS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab FOSS
Commits
e7470534
There was a problem fetching the pipeline summary.
Commit
e7470534
authored
7 years ago
by
Alejandro Rodríguez
Browse files
Options
Downloads
Patches
Plain Diff
Use gl_repository exclusively as identifier on post-receive
parent
585e6aa5
No related branches found
No related tags found
Loading
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/workers/post_receive.rb
+3
-18
3 additions, 18 deletions
app/workers/post_receive.rb
spec/workers/post_receive_spec.rb
+13
-25
13 additions, 25 deletions
spec/workers/post_receive_spec.rb
with
16 additions
and
43 deletions
app/workers/post_receive.rb
+
3
−
18
View file @
e7470534
...
...
@@ -2,11 +2,11 @@ class PostReceive
include
Sidekiq
::
Worker
include
DedicatedSidekiqQueue
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
...
...
@@ -59,21 +59,6 @@ def process_wiki_changes(post_received)
# 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
...
...
This diff is collapsed.
Click to expand it.
spec/workers/post_receive_spec.rb
+
13
−
25
View file @
e7470534
...
...
@@ -4,7 +4,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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
)
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
This diff is collapsed.
Click to expand it.
Stefan Rinkes
@srinkes
mentioned in issue
#36783 (closed)
·
7 years ago
mentioned in issue
#36783 (closed)
mentioned in issue #36783
Toggle commit list
Nick Thomas
@nick.thomas
mentioned in issue
#41841 (closed)
·
7 years ago
mentioned in issue
#41841 (closed)
mentioned in issue #41841
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment