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
c0b47341
Commit
c0b47341
authored
Oct 03, 2016
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added GL_ID
parent
0b4fd0af
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
7 deletions
+52
-7
CHANGELOG
CHANGELOG
+3
-0
hooks/post-receive
hooks/post-receive
+1
-1
hooks/pre-receive
hooks/pre-receive
+1
-1
hooks/update
hooks/update
+3
-2
lib/gitlab_custom_hook.rb
lib/gitlab_custom_hook.rb
+9
-3
spec/gitlab_custom_hook_spec.rb
spec/gitlab_custom_hook_spec.rb
+33
-0
spec/support/gl_id_test_hook
spec/support/gl_id_test_hook
+2
-0
No files found.
CHANGELOG
View file @
c0b47341
v3.6.3
- Re-exposing GL_ID to custom hooks
v3.6.2
- Enable GIT_TRACE/GIT_TRACE_PACKET/GIT_TRACE_PERFORMANCE by providing the git_trace_log_file config key
...
...
hooks/post-receive
View file @
c0b47341
...
...
@@ -11,7 +11,7 @@ require_relative '../lib/gitlab_custom_hook'
require_relative
'../lib/gitlab_post_receive'
if
GitlabPostReceive
.
new
(
repo_path
,
key_id
,
refs
).
exec
&&
GitlabCustomHook
.
new
.
post_receive
(
refs
,
repo_path
)
GitlabCustomHook
.
new
(
key_id
)
.
post_receive
(
refs
,
repo_path
)
exit
0
else
exit
1
...
...
hooks/pre-receive
View file @
c0b47341
...
...
@@ -17,7 +17,7 @@ require_relative '../lib/gitlab_access'
# other hand, we run GitlabPostReceive first because the push is already done
# and we don't want to skip it if the custom hook fails.
if
GitlabAccess
.
new
(
repo_path
,
key_id
,
refs
,
protocol
).
exec
&&
GitlabCustomHook
.
new
.
pre_receive
(
refs
,
repo_path
)
&&
GitlabCustomHook
.
new
(
key_id
)
.
pre_receive
(
refs
,
repo_path
)
&&
GitlabReferenceCounter
.
new
(
repo_path
).
increase
exit
0
else
...
...
hooks/update
View file @
c0b47341
...
...
@@ -7,10 +7,11 @@ ref_name = ARGV[0]
old_value
=
ARGV
[
1
]
new_value
=
ARGV
[
2
]
repo_path
=
Dir
.
pwd
key_id
=
ENV
.
delete
(
'GL_ID'
)
require_relative
'../lib/gitlab_custom_hook'
if
GitlabCustomHook
.
new
.
update
(
ref_name
,
old_value
,
new_value
,
repo_path
)
if
GitlabCustomHook
.
new
(
key_id
)
.
update
(
ref_name
,
old_value
,
new_value
,
repo_path
)
exit
0
else
exit
1
...
...
lib/gitlab_custom_hook.rb
View file @
c0b47341
require
'open3'
class
GitlabCustomHook
attr_reader
:vars
def
initialize
(
key_id
)
@vars
=
{
'GL_ID'
=>
key_id
}
end
def
pre_receive
(
changes
,
repo_path
)
hook
=
hook_file
(
'pre-receive'
,
repo_path
)
return
true
if
hook
.
nil?
...
...
@@ -19,7 +25,7 @@ class GitlabCustomHook
hook
=
hook_file
(
'update'
,
repo_path
)
return
true
if
hook
.
nil?
system
(
hook
,
ref_name
,
old_value
,
new_value
)
system
(
vars
,
hook
,
ref_name
,
old_value
,
new_value
)
end
private
...
...
@@ -28,7 +34,7 @@ class GitlabCustomHook
# Prepare the hook subprocess. Attach a pipe to its stdin, and merge
# both its stdout and stderr into our own stdout.
stdin_reader
,
stdin_writer
=
IO
.
pipe
hook_pid
=
spawn
(
hook
,
in:
stdin_reader
,
err: :out
)
hook_pid
=
spawn
(
vars
,
hook
,
in:
stdin_reader
,
err: :out
)
stdin_reader
.
close
# Submit changes to the hook via its stdin.
...
...
spec/gitlab_custom_hook_spec.rb
0 → 100644
View file @
c0b47341
# coding: utf-8
require
'spec_helper'
require
'pry'
require
'gitlab_custom_hook'
describe
GitlabCustomHook
do
let
(
:gitlab_custom_hook
)
{
GitlabCustomHook
.
new
(
'key_1'
)
}
let
(
:hook_path
)
{
File
.
join
(
ROOT_PATH
,
'spec/support/gl_id_test_hook'
)
}
context
'pre_receive hook'
do
it
'passes GL_ID variable to hook'
do
allow
(
gitlab_custom_hook
).
to
receive
(
:hook_file
).
and_return
(
hook_path
)
expect
(
gitlab_custom_hook
.
pre_receive
(
'changes'
,
'repo_path'
)).
to
be_true
end
end
context
'post_receive hook'
do
it
'passes GL_ID variable to hook'
do
allow
(
gitlab_custom_hook
).
to
receive
(
:hook_file
).
and_return
(
hook_path
)
expect
(
gitlab_custom_hook
.
post_receive
(
'changes'
,
'repo_path'
)).
to
be_true
end
end
context
'update hook'
do
it
'passes GL_ID variable to hook'
do
allow
(
gitlab_custom_hook
).
to
receive
(
:hook_file
).
and_return
(
hook_path
)
expect
(
gitlab_custom_hook
.
update
(
'master'
,
''
,
''
,
'repo_path'
)).
to
be_true
end
end
end
spec/support/gl_id_test_hook
0 → 100755
View file @
c0b47341
#!/bin/sh
printenv
GL_ID |
grep
-q
'^key_1$'
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