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
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
nexedi
gitlab-shell
Commits
3ef7cdf9
Commit
3ef7cdf9
authored
Oct 29, 2014
by
Drew Blessing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for custom hooks
parent
00b3d2cb
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
8 deletions
+72
-8
hooks/post-receive
hooks/post-receive
+4
-3
hooks/pre-receive
hooks/pre-receive
+3
-2
hooks/update
hooks/update
+17
-0
lib/gitlab_access.rb
lib/gitlab_access.rb
+1
-1
lib/gitlab_custom_hook.rb
lib/gitlab_custom_hook.rb
+42
-0
lib/gitlab_post_receive.rb
lib/gitlab_post_receive.rb
+5
-2
No files found.
hooks/post-receive
View file @
3ef7cdf9
...
...
@@ -2,15 +2,16 @@
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
# You can add your own hooks to this file, but be careful when updating gitlab-shell!
change
s
=
ARGF
.
read
ref
s
=
ARGF
.
read
key_id
=
ENV
[
'GL_ID'
]
repo_path
=
Dir
.
pwd
require_relative
'../lib/gitlab_custom_hook'
require_relative
'../lib/gitlab_post_receive'
if
GitlabPostReceive
.
new
(
repo_path
,
key_id
,
changes
).
exec
if
GitlabPostReceive
.
new
(
repo_path
,
key_id
,
refs
).
exec
&&
GitlabCustomHook
.
new
.
post_receive
(
refs
,
repo_path
)
exit
0
else
exit
1
...
...
hooks/pre-receive
View file @
3ef7cdf9
...
...
@@ -2,15 +2,16 @@
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
# You can add your own hooks to this file, but be careful when updating gitlab-shell!
refs
=
ARGF
.
read
key_id
=
ENV
[
'GL_ID'
]
repo_path
=
Dir
.
pwd
require_relative
'../lib/gitlab_custom_hook'
require_relative
'../lib/gitlab_access'
if
GitlabAccess
.
new
(
repo_path
,
key_id
,
refs
).
exec
if
GitlabAccess
.
new
(
repo_path
,
key_id
,
refs
).
exec
&&
GitlabCustomHook
.
new
.
pre_receive
(
refs
,
repo_path
)
exit
0
else
exit
1
...
...
hooks/update
0 → 100755
View file @
3ef7cdf9
#!/usr/bin/env ruby
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
ref_name
=
ARGV
[
0
]
old_value
=
ARGV
[
1
]
new_value
=
ARGV
[
2
]
repo_path
=
Dir
.
pwd
require_relative
'../lib/gitlab_custom_hook'
if
GitlabCustomHook
.
new
.
update
(
ref_name
,
old_value
,
new_value
,
repo_path
)
exit
0
else
exit
1
end
lib/gitlab_access.rb
View file @
3ef7cdf9
...
...
@@ -23,7 +23,7 @@ class GitlabAccess
# reset GL_ID env since we stop git push here
ENV
[
'GL_ID'
]
=
nil
puts
"GitLab: You are not allowed to access some of the refs!"
exit
1
return
false
end
end
...
...
lib/gitlab_custom_hook.rb
0 → 100644
View file @
3ef7cdf9
class
GitlabCustomHook
def
pre_receive
(
refs
,
repo_path
)
if
receive
(
'pre-receive'
,
refs
,
repo_path
)
return
true
else
# reset GL_ID env since we stop git push here
ENV
[
'GL_ID'
]
=
nil
return
false
end
end
def
post_receive
(
refs
,
repo_path
)
receive
(
'post-receive'
,
refs
,
repo_path
)
end
def
update
(
ref_name
,
old_value
,
new_value
,
repo_path
)
hook
=
hook_file
(
'update'
,
repo_path
)
return
true
if
hook
.
nil?
system
(
*
hook
,
ref_name
,
old_value
,
new_value
)
?
true
:
false
end
private
def
receive
(
type
,
refs
,
repo_path
)
unless
type
==
'pre-receive'
||
type
==
'post-receive'
puts
'GitLab: An unexpected error occurred '
\
'(invalid pre/post-receive hook type)'
return
false
end
hook
=
hook_file
(
type
,
repo_path
)
return
true
if
hook
.
nil?
cmd
=
"
#{
hook
}
#{
refs
}
"
system
(
*
cmd
)
?
true
:
false
end
def
hook_file
(
hook_type
,
repo_path
)
hook_path
=
File
.
join
(
repo_path
.
strip
,
'custom_hooks'
)
hook_file
=
"
#{
hook_path
}
/
#{
hook_type
}
"
hook_file
if
File
.
exist?
(
hook_file
)
end
end
lib/gitlab_post_receive.rb
View file @
3ef7cdf9
...
...
@@ -23,9 +23,12 @@ class GitlabPostReceive
def
update_redis
queue
=
"
#{
config
.
redis_namespace
}
:queue:post_receive"
msg
=
JSON
.
dump
({
'class'
=>
'PostReceive'
,
'args'
=>
[
@repo_path
,
@actor
,
@changes
]})
unless
system
(
*
config
.
redis_command
,
'rpush'
,
queue
,
msg
,
err:
'/dev/null'
,
out:
'/dev/null'
)
if
system
(
*
config
.
redis_command
,
'rpush'
,
queue
,
msg
,
err:
'/dev/null'
,
out:
'/dev/null'
)
return
true
else
puts
"GitLab: An unexpected error occurred (redis-cli returned
#{
$?
.
exitstatus
}
)."
exit
1
return
false
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