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
Léo-Paul Géneau
gitlab-ce
Commits
f0a64399
Commit
f0a64399
authored
Feb 27, 2018
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor plugin execution method
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
2150b2cd
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
25 deletions
+49
-25
app/workers/plugin_worker.rb
app/workers/plugin_worker.rb
+0
-2
lib/gitlab/plugin.rb
lib/gitlab/plugin.rb
+10
-1
spec/lib/gitlab/plugin_spec.rb
spec/lib/gitlab/plugin_spec.rb
+39
-14
spec/workers/plugin_worker_spec.rb
spec/workers/plugin_worker_spec.rb
+0
-8
No files found.
app/workers/plugin_worker.rb
View file @
f0a64399
...
@@ -5,7 +5,5 @@ class PluginWorker
...
@@ -5,7 +5,5 @@ class PluginWorker
def
perform
(
file_name
,
data
)
def
perform
(
file_name
,
data
)
Gitlab
::
Plugin
.
execute
(
file_name
,
data
)
Gitlab
::
Plugin
.
execute
(
file_name
,
data
)
rescue
=>
e
Rails
.
logger
.
error
(
"
#{
self
.
class
}
:
#{
e
.
message
}
"
)
end
end
end
end
lib/gitlab/plugin.rb
View file @
f0a64399
...
@@ -13,11 +13,20 @@ module Gitlab
...
@@ -13,11 +13,20 @@ module Gitlab
end
end
def
self
.
execute
(
file
,
data
)
def
self
.
execute
(
file
,
data
)
_output
,
exit_status
=
Gitlab
::
Popen
.
popen
([
file
])
do
|
stdin
|
result
=
Gitlab
::
Popen
.
popen_with_detail
([
file
])
do
|
stdin
|
stdin
.
write
(
data
.
to_json
)
stdin
.
write
(
data
.
to_json
)
end
end
exit_status
=
result
.
status
&
.
exitstatus
unless
exit_status
.
zero?
Rails
.
logger
.
error
(
"Plugin Error =>
#{
file
}
:
#{
result
.
stderr
}
"
)
end
exit_status
.
zero?
exit_status
.
zero?
rescue
=>
e
Rails
.
logger
.
error
(
"Plugin Error =>
#{
file
}
:
#{
e
.
message
}
"
)
false
end
end
end
end
end
end
spec/lib/gitlab/plugin_spec.rb
View file @
f0a64399
...
@@ -6,18 +6,33 @@ describe Gitlab::Plugin do
...
@@ -6,18 +6,33 @@ describe Gitlab::Plugin do
let
(
:plugin
)
{
Rails
.
root
.
join
(
'plugins'
,
'test.rb'
)
}
let
(
:plugin
)
{
Rails
.
root
.
join
(
'plugins'
,
'test.rb'
)
}
let
(
:tmp_file
)
{
Tempfile
.
new
(
'plugin-dump'
)
}
let
(
:tmp_file
)
{
Tempfile
.
new
(
'plugin-dump'
)
}
let
(
:plugin_source
)
do
<<~
EOS
#!/usr/bin/env ruby
x = STDIN.read
File.write('
#{
tmp_file
.
path
}
', x)
EOS
end
before
do
before
do
File
.
write
(
plugin
,
plugin_source
)
File
.
write
(
plugin
,
plugin_source
)
File
.
chmod
(
0
o777
,
plugin
)
end
end
after
do
after
do
FileUtils
.
rm
(
plugin
)
FileUtils
.
rm
(
plugin
)
tmp_file
.
close!
end
end
subject
{
described_class
.
execute
(
plugin
.
to_s
,
data
)
}
subject
{
described_class
.
execute
(
plugin
.
to_s
,
data
)
}
context
'successful execution'
do
before
do
File
.
chmod
(
0
o777
,
plugin
)
end
after
do
tmp_file
.
close!
end
it
{
is_expected
.
to
be
true
}
it
{
is_expected
.
to
be
true
}
it
'ensures plugin received data via stdin'
do
it
'ensures plugin received data via stdin'
do
...
@@ -27,13 +42,23 @@ describe Gitlab::Plugin do
...
@@ -27,13 +42,23 @@ describe Gitlab::Plugin do
end
end
end
end
private
context
'non-executable'
do
it
{
is_expected
.
to
be
false
}
end
def
plugin_source
context
'non-zero exit'
do
let
(
:plugin_source
)
do
<<~
EOS
<<~
EOS
#!/usr/bin/env ruby
#!/usr/bin/env ruby
x = STDIN.read
exit 1
File.write('
#{
tmp_file
.
path
}
', x)
EOS
EOS
end
end
before
do
File
.
chmod
(
0
o777
,
plugin
)
end
it
{
is_expected
.
to
be
false
}
end
end
end
end
spec/workers/plugin_worker_spec.rb
View file @
f0a64399
...
@@ -15,13 +15,5 @@ describe PluginWorker do
...
@@ -15,13 +15,5 @@ describe PluginWorker do
expect
(
subject
.
perform
(
filename
,
data
)).
to
be_truthy
expect
(
subject
.
perform
(
filename
,
data
)).
to
be_truthy
end
end
it
'handles exception well'
do
data
=
{
'event_name'
=>
'project_create'
}
allow
(
Gitlab
::
Plugin
).
to
receive
(
:execute
).
with
(
filename
,
data
).
and_raise
(
'Permission denied'
)
expect
{
subject
.
perform
(
filename
,
data
)
}.
not_to
raise_error
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