BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
59e7b7a6
Unverified
Commit
59e7b7a6
authored
Aug 10, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Trigger post-receive hooks after commits are made by GitLab
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
99585a73
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
post_commit_service.rb
app/services/post_commit_service.rb
+11
-11
No files found.
app/services/post_commit_service.rb
View file @
59e7b7a6
class
PostCommitService
<
BaseService
class
PostCommitService
<
BaseService
include
Gitlab
::
Popen
include
Gitlab
::
Popen
attr_reader
:changes
attr_reader
:changes
,
:repo_path
def
execute
(
sha
,
branch
)
def
execute
(
sha
,
branch
)
commit
=
repository
.
commit
(
sha
)
commit
=
repository
.
commit
(
sha
)
full_ref
=
'refs/heads/'
+
branch
full_ref
=
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
branch
old_sha
=
commit
.
parent_id
||
Gitlab
::
Git
::
BLANK_SHA
old_sha
=
commit
.
parent_id
||
Gitlab
::
Git
::
BLANK_SHA
@changes
=
"
#{
old_sha
}
#{
sha
}
#{
full_ref
}
"
@changes
=
"
#{
old_sha
}
#{
sha
}
#{
full_ref
}
"
post_receive
(
@changes
,
repository
.
path_to_repo
)
@repo_path
=
repository
.
path_to_repo
post_receive
end
end
private
private
def
post_receive
(
changes
,
repo_path
)
def
post_receive
hook
=
hook_file
(
'post-receive'
,
repo_path
)
hook
=
hook_file
(
'post-receive'
,
repo_path
)
return
true
if
hook
.
nil?
return
true
if
hook
.
nil?
call_receive_hook
(
hook
,
changes
)
?
true
:
false
call_receive_hook
(
hook
)
end
end
def
call_receive_hook
(
hook
,
changes
)
def
call_receive_hook
(
hook
)
# function will return true if succesful
# function will return true if succesful
exit_status
=
false
exit_status
=
false
vars
=
{
vars
=
{
'GL_ID'
=>
Gitlab
::
ShellEnv
.
gl_id
(
current_user
),
'GL_ID'
=>
Gitlab
::
ShellEnv
.
gl_id
(
current_user
),
'PWD'
=>
repo
sitory
.
path_to_repo
'PWD'
=>
repo
_path
}
}
options
=
{
options
=
{
chdir:
repo
sitory
.
path_to_repo
chdir:
repo
_path
}
}
# we combine both stdout and stderr as we don't know what stream
# we combine both stdout and stderr as we don't know what stream
...
@@ -45,7 +46,7 @@ class PostCommitService < BaseService
...
@@ -45,7 +46,7 @@ class PostCommitService < BaseService
begin
begin
# inject all the changes as stdin to the hook
# inject all the changes as stdin to the hook
changes
.
lines
do
|
line
|
changes
.
lines
do
|
line
|
stdin
.
puts
(
line
)
stdin
.
puts
line
end
end
rescue
Errno
::
EPIPE
rescue
Errno
::
EPIPE
end
end
...
@@ -56,7 +57,6 @@ class PostCommitService < BaseService
...
@@ -56,7 +57,6 @@ class PostCommitService < BaseService
# only output stdut_stderr if scripts doesn't return 0
# only output stdut_stderr if scripts doesn't return 0
unless
wait_thr
.
value
==
0
unless
wait_thr
.
value
==
0
exit_status
=
false
exit_status
=
false
stdout_stderr
.
each_line
{
|
line
|
puts
line
}
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