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
12331a55
Commit
12331a55
authored
Feb 14, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use update hook to add post event to redis. Use GL_ID instead of GL_USER
parent
ba68af63
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
27 deletions
+41
-27
CHANGELOG
CHANGELOG
+5
-0
hooks/post-receive
hooks/post-receive
+4
-9
hooks/update
hooks/update
+1
-1
lib/gitlab_shell.rb
lib/gitlab_shell.rb
+1
-1
lib/gitlab_update.rb
lib/gitlab_update.rb
+30
-16
No files found.
CHANGELOG
0 → 100644
View file @
12331a55
v1.0.4
- requires gitlab b698094
- dont use post-receive file any more. Make all updates in update
- fixed issue with invalid GL_USER
- use GL_ID instead of GL_USER
hooks/post-receive
View file @
12331a55
#!/usr/bin/env
bash
#!/usr/bin/env
ruby
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
# This file was placed here by GitLab.
# IT IS DEPRECATED NOW.
# All GitLab logic handled by update hook
while
read
oldrev newrev ref
do
# For every branch or tag that was pushed, create a Resque job in redis.
repo_path
=
`
pwd
`
env
-i
redis-cli rpush
"resque:gitlab:queue:post_receive"
"{
\"
class
\"
:
\"
PostReceive
\"
,
\"
args
\"
:[
\"
$repo_path
\"
,
\"
$oldrev
\"
,
\"
$newrev
\"
,
\"
$ref
\"
,
\"
$GL_USER
\"
]}"
>
/dev/null 2>&1
done
hooks/update
View file @
12331a55
...
...
@@ -4,7 +4,7 @@
# will be processed properly.
refname
=
ARGV
[
0
]
key_id
=
ENV
[
'GL_
USER
'
]
key_id
=
ENV
[
'GL_
ID
'
]
repo_path
=
`pwd`
require_relative
'../lib/gitlab_update'
...
...
lib/gitlab_shell.rb
View file @
12331a55
...
...
@@ -16,7 +16,7 @@ class GitlabShell
parse_cmd
if
git_cmds
.
include?
(
@git_cmd
)
ENV
[
'GL_
USER
'
]
=
@key_id
ENV
[
'GL_
ID
'
]
=
@key_id
if
validate_access
process_cmd
...
...
lib/gitlab_update.rb
View file @
12331a55
...
...
@@ -3,33 +3,38 @@ require_relative 'gitlab_net'
class
GitlabUpdate
def
initialize
(
repo_path
,
key_id
,
refname
)
@repo_path
=
repo_path
.
strip
@repo_name
=
repo_path
@repo_name
.
gsub!
(
GitlabConfig
.
new
.
repos_path
.
to_s
,
""
)
@repo_name
.
gsub!
(
/.git$/
,
""
)
@repo_name
.
gsub!
(
/^\//
,
""
)
@key_id
=
key_id
@refname
=
/refs\/heads\/([\w\.-]+)/
.
match
(
refname
).
to_a
.
last
@refname
=
refname
@branch_name
=
/refs\/heads\/([\w\.-]+)/
.
match
(
refname
).
to_a
.
last
@oldrev
=
ARGV
[
1
]
@newrev
=
ARGV
[
2
]
end
def
exec
# Skip update hook for local push when key_id is nil
# It required for gitlab instance to make local pushes
# without validation of access
exit
0
if
@key_id
.
nil?
# Also skip update hook for non-gitlab keys
# and reset GL_USER env
unless
@key_id
=~
/\Akey\-\d+\Z/
ENV
[
'GL_USER'
]
=
nil
exit
0
end
# reset GL_USER env since we already
# get value from it
ENV
[
'GL_ID'
]
=
nil
if
api
.
allowed?
(
'git-receive-pack'
,
@repo_name
,
@key_id
,
@refname
)
exit
0
# If its push over ssh
# we need to check user persmission per branch first
if
ssh?
if
api
.
allowed?
(
'git-receive-pack'
,
@repo_name
,
@key_id
,
@branch_name
)
update_redis
exit
0
else
puts
"GitLab: You are not allowed to access
#{
@branch_name
}
! "
exit
1
end
else
puts
"GitLab: You are not allowed to access
#{
@refname
}
! "
exit
1
update_redis
exit
0
end
end
...
...
@@ -38,4 +43,13 @@ class GitlabUpdate
def
api
GitlabNet
.
new
end
def
ssh?
@key_id
=~
/\Akey\-\d+\Z/
end
def
update_redis
command
=
"env -i redis-cli rpush 'resque:gitlab:queue:post_receive' '{
\"
class
\"
:
\"
PostReceive
\"
,
\"
args
\"
:[
\"
#{
@repo_path
}
\"
,
\"
#{
@oldrev
}
\"
,
\"
#{
@newrev
}
\"
,
\"
#{
@refname
}
\"
,
\"
#{
@key_id
}
\"
]}' > /dev/null 2>&1"
system
(
command
)
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