Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-shell
Commits
b6625587
Commit
b6625587
authored
Jun 24, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify custom hook output handling
parent
cab00513
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
29 deletions
+16
-29
lib/gitlab_custom_hook.rb
lib/gitlab_custom_hook.rb
+16
-29
No files found.
lib/gitlab_custom_hook.rb
View file @
b6625587
...
@@ -25,37 +25,24 @@ class GitlabCustomHook
...
@@ -25,37 +25,24 @@ class GitlabCustomHook
private
private
def
call_receive_hook
(
hook
,
changes
)
def
call_receive_hook
(
hook
,
changes
)
# function will return true if succesful
# Prepare the hook subprocess. Attach a pipe to its stdin, and merge
exit_status
=
false
# both its stdout and stderr into our own stdout.
stdin_reader
,
stdin_writer
=
IO
.
pipe
hook_pid
=
spawn
(
hook
,
in:
stdin_reader
,
err: :out
)
stdin_reader
.
close
# we combine both stdout and stderr as we don't know what stream
# Submit changes to the hook via its stdin.
# will be used by the custom hook
Open3
.
popen2e
(
hook
)
do
|
stdin
,
stdout_stderr
,
wait_thr
|
exit_status
=
true
stdin
.
sync
=
true
# in git, pre- and post- receive hooks may just exit without
# reading stdin. We catch the exception to avoid a broken pipe
# warning
begin
begin
# inject all the changes as stdin to the hook
IO
.
copy_stream
(
StringIO
.
new
(
changes
),
stdin_writer
)
changes
.
lines
do
|
line
|
stdin
.
puts
(
line
)
end
rescue
Errno
::
EPIPE
rescue
Errno
::
EPIPE
# It is not an error if the hook does not consume all of its input.
end
end
# need to close stdin before reading stdout
# Close the pipe to let the hook know there is no further input.
stdin
.
close
stdin_writer
.
close
unless
wait_thr
.
value
==
0
exit_status
=
false
end
stdout_stderr
.
each_line
{
|
line
|
puts
line
}
end
exit_status
Process
.
wait
(
hook_pid
)
$?
.
success?
end
end
def
hook_file
(
hook_type
,
repo_path
)
def
hook_file
(
hook_type
,
repo_path
)
...
...
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