Commit e03d01d036bf5f5257d767a1b6ab23f06787a421
1 parent
5e35f216
Exists in
master
and in
4 other branches
extract server-side git commands to constants
Showing
1 changed file
with
7 additions
and
3 deletions
Show diff stats
lib/api/internal.rb
1 | 1 | module API |
2 | 2 | # Internal access API |
3 | 3 | class Internal < Grape::API |
4 | + | |
5 | + DOWNLOAD_COMMANDS = %w{ git-upload-pack git-upload-archive } | |
6 | + PUSH_COMMANDS = %w{ git-receive-pack } | |
7 | + | |
4 | 8 | namespace 'internal' do |
5 | 9 | # |
6 | 10 | # Check if ssh key has access to project code |
... | ... | @@ -26,16 +30,16 @@ module API |
26 | 30 | |
27 | 31 | |
28 | 32 | if key.is_a? DeployKey |
29 | - key.projects.include?(project) && git_cmd.starts_with?('git-upload-') | |
33 | + key.projects.include?(project) && DOWNLOAD_COMMANDS.include?(git_cmd) | |
30 | 34 | else |
31 | 35 | user = key.user |
32 | 36 | |
33 | 37 | return false if user.blocked? |
34 | 38 | |
35 | 39 | action = case git_cmd |
36 | - when 'git-upload-pack', 'git-upload-archive' | |
40 | + when *DOWNLOAD_COMMANDS | |
37 | 41 | then :download_code |
38 | - when 'git-receive-pack' | |
42 | + when *PUSH_COMMANDS | |
39 | 43 | then |
40 | 44 | if project.protected_branch?(params[:ref]) |
41 | 45 | :push_code_to_protected_branches | ... | ... |