Commit 9b337b8328a65c5e692c90ba1f817184bd054257
1 parent
b3a0ee8e
Exists in
master
and in
4 other branches
Epic: Gitlab configuration with default values
Showing
28 changed files
with
178 additions
and
76 deletions
Show diff stats
Gemfile
Gemfile.lock
... | ... | @@ -313,6 +313,7 @@ GEM |
313 | 313 | libwebsocket (~> 0.1.3) |
314 | 314 | multi_json (~> 1.0) |
315 | 315 | rubyzip |
316 | + settingslogic (2.0.8) | |
316 | 317 | shoulda-matchers (1.1.0) |
317 | 318 | activesupport (>= 3.0.0) |
318 | 319 | simplecov (0.6.4) |
... | ... | @@ -416,6 +417,7 @@ DEPENDENCIES |
416 | 417 | rspec-rails |
417 | 418 | sass-rails (= 3.2.5) |
418 | 419 | seed-fu |
420 | + settingslogic | |
419 | 421 | shoulda-matchers |
420 | 422 | simplecov |
421 | 423 | six | ... | ... |
app/assets/stylesheets/gitlab_bootstrap.scss
app/helpers/application_helper.rb
app/mailers/notify.rb
... | ... | @@ -2,10 +2,10 @@ class Notify < ActionMailer::Base |
2 | 2 | include Resque::Mailer |
3 | 3 | add_template_helper ApplicationHelper |
4 | 4 | |
5 | - default_url_options[:host] = EMAIL_OPTS["host"] | |
6 | - default_url_options[:protocol] = -> { EMAIL_OPTS["protocol"] ? EMAIL_OPTS["protocol"] : "http" }.call | |
5 | + default_url_options[:host] = Gitlab.config.web_host | |
6 | + default_url_options[:protocol] = Gitlab.config.web_protocol | |
7 | 7 | |
8 | - default from: EMAIL_OPTS["from"] | |
8 | + default from: Gitlab.config.email_from | |
9 | 9 | |
10 | 10 | def new_user_email(user_id, password) |
11 | 11 | @user = User.find(user_id) | ... | ... |
app/models/project.rb
app/roles/git_push.rb
... | ... | @@ -73,7 +73,7 @@ module GitPush |
73 | 73 | id: commit.id, |
74 | 74 | message: commit.safe_message, |
75 | 75 | timestamp: commit.date.xmlschema, |
76 | - url: "http://#{GIT_HOST['host']}/#{code}/commits/#{commit.id}", | |
76 | + url: "#{Gitlab.config.url}/#{code}/commits/#{commit.id}", | |
77 | 77 | author: { |
78 | 78 | name: commit.author_name, |
79 | 79 | email: commit.author_email | ... | ... |
app/roles/repository.rb
... | ... | @@ -68,7 +68,7 @@ module Repository |
68 | 68 | end |
69 | 69 | |
70 | 70 | def path_to_repo |
71 | - File.join(GIT_HOST["base_path"], "#{path}.git") | |
71 | + File.join(Gitlab.config.git_base_path, "#{path}.git") | |
72 | 72 | end |
73 | 73 | |
74 | 74 | def update_repository |
... | ... | @@ -141,4 +141,12 @@ module Repository |
141 | 141 | |
142 | 142 | file_path |
143 | 143 | end |
144 | + | |
145 | + def ssh_url_to_repo | |
146 | + url_to_repo | |
147 | + end | |
148 | + | |
149 | + def http_url_to_repo | |
150 | + http_url = [Gitlab.config.url, "/", path, ".git"].join() | |
151 | + end | |
144 | 152 | end | ... | ... |
app/views/admin/projects/_form.html.haml
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | Path |
14 | 14 | .input |
15 | 15 | .input-prepend |
16 | - %span.add-on= "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:" | |
16 | + %span.add-on= Gitlab.config.ssh_path | |
17 | 17 | = f.text_field :path, :placeholder => "example_project", :disabled => !@admin_project.new_record? |
18 | 18 | .clearfix |
19 | 19 | = f.label :code do | ... | ... |
app/views/projects/_form.html.haml
... | ... | @@ -18,7 +18,7 @@ |
18 | 18 | Git Clone |
19 | 19 | .input |
20 | 20 | .input-prepend |
21 | - %span.add-on= "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:" | |
21 | + %span.add-on= Gitlab.config.ssh_path | |
22 | 22 | = f.text_field :path, :placeholder => "example_project", :disabled => !@project.new_record? |
23 | 23 | %span.add-on= ".git" |
24 | 24 | .clearfix | ... | ... |
app/views/projects/_new_form.html.haml
... | ... | @@ -17,7 +17,7 @@ |
17 | 17 | Git Clone |
18 | 18 | .input |
19 | 19 | .input-prepend |
20 | - %span.add-on= "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:" | |
20 | + %span.add-on= Gitlab.config.ssh_path | |
21 | 21 | = f.text_field :path, :placeholder => "example_project", :disabled => !@project.new_record? |
22 | 22 | %span.add-on= ".git" |
23 | 23 | .clearfix | ... | ... |
app/views/projects/show.html.haml
... | ... | @@ -4,8 +4,11 @@ |
4 | 4 | .row |
5 | 5 | .span7 |
6 | 6 | .form-horizontal |
7 | - .input-prepend | |
7 | + .input-prepend.project_clone_holder | |
8 | + | |
8 | 9 | %span.add-on git clone |
10 | + = link_to "SSH", "#", :class => "btn small active", :"data-clone" => @project.ssh_url_to_repo | |
11 | + = link_to "HTTP", "#", :class => "btn small", :"data-clone" => @project.http_url_to_repo | |
9 | 12 | = text_field_tag :project_clone, @project.url_to_repo, :class => "one_click_select span5" |
10 | 13 | .span4.right |
11 | 14 | .right |
... | ... | @@ -23,4 +26,12 @@ |
23 | 26 | = render "events/event_last_push", :event => @last_push |
24 | 27 | .content_list= render @events |
25 | 28 | |
26 | - | |
29 | +:javascript | |
30 | + $(function(){ | |
31 | + var link_sel = ".project_clone_holder a"; | |
32 | + $(link_sel).bind("click", function() { | |
33 | + $(link_sel).removeClass("active"); | |
34 | + $(this).addClass("active"); | |
35 | + $("#project_clone").val($(this).attr("data-clone")); | |
36 | + }) | |
37 | + }) | ... | ... |
config/gitlab.yml.example
1 | -# Gitlab application config file | |
1 | +# # # # # # # # # # # # # # # # # # | |
2 | +# Gitlab application config file # | |
3 | +# # # # # # # # # # # # # # # # # # | |
4 | + | |
5 | +# Web application specific settings | |
6 | +web: | |
7 | + host: localhost | |
8 | + port: 80 | |
9 | + https: false | |
2 | 10 | |
3 | 11 | # Email used for notification |
4 | 12 | # about new issues, comments |
5 | 13 | email: |
6 | - from: notify@gitlabhq.com | |
7 | - host: gitlabhq.com | |
8 | - | |
9 | - # Protocol used for links in email letters | |
10 | - # Value can be http or https | |
11 | - protocol: http # or https | |
14 | + from: notify@localhost | |
12 | 15 | |
13 | 16 | # Git Hosting configuration |
14 | 17 | git_host: |
15 | - system: gitolite | |
16 | 18 | admin_uri: git@localhost:gitolite-admin |
17 | 19 | base_path: /home/git/repositories/ |
18 | 20 | host: localhost | ... | ... |
config/initializers/00_before_all.rb
... | ... | @@ -1,4 +0,0 @@ |
1 | -GIT_HOST = YAML.load_file("#{Rails.root}/config/gitlab.yml")["git_host"] | |
2 | -EMAIL_OPTS = YAML.load_file("#{Rails.root}/config/gitlab.yml")["email"] | |
3 | -GIT_OPTS = YAML.load_file("#{Rails.root}/config/gitlab.yml")["git"] | |
4 | -GITLAB_OPTS = YAML.load_file("#{Rails.root}/config/gitlab.yml")["gitlab"] |
... | ... | @@ -0,0 +1 @@ |
1 | +GITLAB_OPTS = YAML.load_file("#{Rails.root}/config/gitlab.yml")["gitlab"] | ... | ... |
... | ... | @@ -0,0 +1,75 @@ |
1 | +class Settings < Settingslogic | |
2 | + source "#{Rails.root}/config/gitlab.yml" | |
3 | + | |
4 | + class << self | |
5 | + def web_protocol | |
6 | + self.web['protocol'] ||= web.https ? "https://" : "http://" | |
7 | + end | |
8 | + | |
9 | + def web_host | |
10 | + self.web['host'] ||= 'localhost' | |
11 | + end | |
12 | + | |
13 | + def email_from | |
14 | + self.email['from'] ||= "notify@" + web_host | |
15 | + end | |
16 | + | |
17 | + def url | |
18 | + self['url'] ||= build_url | |
19 | + end | |
20 | + | |
21 | + def build_url | |
22 | + raw_url = self.web_protocol | |
23 | + raw_url << web.host | |
24 | + raw_url << ":#{web.port}" if web.port.to_i != 80 | |
25 | + end | |
26 | + | |
27 | + def ssh_port | |
28 | + git_host['port'] || 22 | |
29 | + end | |
30 | + | |
31 | + def ssh_user | |
32 | + git_host['git_user'] || 'git' | |
33 | + end | |
34 | + | |
35 | + def ssh_host | |
36 | + git_host['host'] || 'localhost' | |
37 | + end | |
38 | + | |
39 | + def ssh_path | |
40 | + if ssh_port != 22 | |
41 | + "ssh://#{ssh_user}@#{ssh_host}:#{ssh_port}/" | |
42 | + else | |
43 | + "#{ssh_user}@#{ssh_host}:" | |
44 | + end | |
45 | + end | |
46 | + | |
47 | + def git_base_path | |
48 | + git_host['base_path'] || '/home/git/repositories/' | |
49 | + end | |
50 | + | |
51 | + def git_upload_pack | |
52 | + git_host['upload_pack'] || true | |
53 | + end | |
54 | + | |
55 | + def git_receive_pack | |
56 | + git_host['receive_pack'] || true | |
57 | + end | |
58 | + | |
59 | + def git_bin_path | |
60 | + git['path'] || '/usr/bin/git' | |
61 | + end | |
62 | + | |
63 | + def git_max_size | |
64 | + git['git_max_size'] || 5242880 # 5.megabytes | |
65 | + end | |
66 | + | |
67 | + def git_timeout | |
68 | + git['git_timeout'] || 10 | |
69 | + end | |
70 | + | |
71 | + def gitolite_admin_uri | |
72 | + git['admin_uri'] || 'git@localhost:gitolite-admin' | |
73 | + end | |
74 | + end | |
75 | +end | ... | ... |
... | ... | @@ -0,0 +1,28 @@ |
1 | +require 'grit' | |
2 | +require 'pygments' | |
3 | + | |
4 | +Grit::Git.git_timeout = Gitlab.config.git_timeout | |
5 | +Grit::Git.git_max_size = Gitlab.config.git_max_size | |
6 | + | |
7 | +Grit::Blob.class_eval do | |
8 | + include Linguist::BlobHelper | |
9 | + | |
10 | + def data | |
11 | + @data ||= @repo.git.cat_file({:p => true}, id) | |
12 | + Gitlab::Encode.utf8 @data | |
13 | + end | |
14 | +end | |
15 | + | |
16 | +Grit::Diff.class_eval do | |
17 | + def old_path | |
18 | + Gitlab::Encode.utf8 @a_path | |
19 | + end | |
20 | + | |
21 | + def new_path | |
22 | + Gitlab::Encode.utf8 @b_path | |
23 | + end | |
24 | + | |
25 | + def diff | |
26 | + Gitlab::Encode.utf8 @diff | |
27 | + end | |
28 | +end | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +Resque.watch_queue(PostReceive.instance_variable_get("@queue")) | ... | ... |
config/initializers/devise.rb
... | ... | @@ -4,7 +4,7 @@ Devise.setup do |config| |
4 | 4 | # ==> Mailer Configuration |
5 | 5 | # Configure the e-mail address which will be shown in Devise::Mailer, |
6 | 6 | # note that it will be overwritten if you use your own mailer class with default "from" parameter. |
7 | - config.mailer_sender = EMAIL_OPTS["from"] | |
7 | + config.mailer_sender = Gitlab.config.email_from | |
8 | 8 | |
9 | 9 | # Configure the class responsible to send e-mails. |
10 | 10 | # config.mailer = "Devise::Mailer" | ... | ... |
config/initializers/gitlab/10_app.rb
config/initializers/gitlab/20_grit_ext.rb
... | ... | @@ -1,28 +0,0 @@ |
1 | -require 'grit' | |
2 | -require 'pygments' | |
3 | - | |
4 | -Grit::Git.git_timeout = GIT_OPTS["git_timeout"] | |
5 | -Grit::Git.git_max_size = GIT_OPTS["git_max_size"] | |
6 | - | |
7 | -Grit::Blob.class_eval do | |
8 | - include Linguist::BlobHelper | |
9 | - | |
10 | - def data | |
11 | - @data ||= @repo.git.cat_file({:p => true}, id) | |
12 | - Gitlab::Encode.utf8 @data | |
13 | - end | |
14 | -end | |
15 | - | |
16 | -Grit::Diff.class_eval do | |
17 | - def old_path | |
18 | - Gitlab::Encode.utf8 @a_path | |
19 | - end | |
20 | - | |
21 | - def new_path | |
22 | - Gitlab::Encode.utf8 @b_path | |
23 | - end | |
24 | - | |
25 | - def diff | |
26 | - Gitlab::Encode.utf8 @diff | |
27 | - end | |
28 | -end |
config/initializers/gitlab/30_resque_queues.rb
... | ... | @@ -1 +0,0 @@ |
1 | -Resque.watch_queue(PostReceive.instance_variable_get("@queue")) |
config/routes.rb
... | ... | @@ -14,10 +14,10 @@ Gitlab::Application.routes.draw do |
14 | 14 | |
15 | 15 | # Enable Grack support |
16 | 16 | mount Grack::Bundle.new({ |
17 | - git_path: GIT_OPTS['path'], | |
18 | - project_root: GIT_HOST['base_path'], | |
19 | - upload_pack: GIT_HOST['upload_pack'], | |
20 | - receive_pack: GIT_HOST['receive_pack'] | |
17 | + git_path: Gitlab.config.git_bin_path, | |
18 | + project_root: Gitlab.config.git_base_path, | |
19 | + upload_pack: Gitlab.config.git_upload_pack, | |
20 | + receive_pack: Gitlab.config.git_receive_pack | |
21 | 21 | }), at: '/:path', constraints: { path: /[\w-]+\.git/ } |
22 | 22 | |
23 | 23 | # | ... | ... |
lib/gitlab/git_host.rb
... | ... | @@ -7,15 +7,11 @@ module Gitlab |
7 | 7 | end |
8 | 8 | |
9 | 9 | def self.admin_uri |
10 | - GIT_HOST["admin_uri"] | |
10 | + Gitlab.config.git_host.admin_uri | |
11 | 11 | end |
12 | 12 | |
13 | 13 | def self.url_to_repo(path) |
14 | - if !GIT_HOST["port"] or GIT_HOST["port"] == 22 | |
15 | - "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{path}.git" | |
16 | - else | |
17 | - "ssh://#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{GIT_HOST["port"]}/#{path}.git" | |
18 | - end | |
14 | + Gitlab.config.ssh_path + "#{path}.git" | |
19 | 15 | end |
20 | 16 | end |
21 | 17 | end | ... | ... |
lib/tasks/gitlab/status.rake
... | ... | @@ -3,6 +3,7 @@ namespace :gitlab do |
3 | 3 | desc "GITLAB | Check gitlab installation status" |
4 | 4 | task :status => :environment do |
5 | 5 | puts "Starting diagnostic" |
6 | + git_base_path = Gitlab.config.git_base_path | |
6 | 7 | |
7 | 8 | print "config/database.yml............" |
8 | 9 | if File.exists?(File.join Rails.root, "config", "database.yml") |
... | ... | @@ -21,16 +22,16 @@ namespace :gitlab do |
21 | 22 | end |
22 | 23 | |
23 | 24 | GIT_HOST = YAML.load_file("#{Rails.root}/config/gitlab.yml")["git_host"] |
24 | - print "#{GIT_HOST['base_path']}............" | |
25 | - if File.exists?(GIT_HOST['base_path']) | |
25 | + print "#{git_base_path}............" | |
26 | + if File.exists?(git_base_path) | |
26 | 27 | puts "exists".green |
27 | 28 | else |
28 | 29 | puts "missing".red |
29 | 30 | return |
30 | 31 | end |
31 | 32 | |
32 | - print "#{GIT_HOST['base_path']} is writable?............" | |
33 | - if File.stat(GIT_HOST['base_path']).writable? | |
33 | + print "#{git_base_path} is writable?............" | |
34 | + if File.stat(git_base_path).writable? | |
34 | 35 | puts "YES".green |
35 | 36 | else |
36 | 37 | puts "NO".red |
... | ... | @@ -38,7 +39,7 @@ namespace :gitlab do |
38 | 39 | end |
39 | 40 | |
40 | 41 | begin |
41 | - `git clone #{GIT_HOST["admin_uri"]} /tmp/gitolite_gitlab_test` | |
42 | + `git clone #{Gitlab.config.gitolite_admin_uri} /tmp/gitolite_gitlab_test` | |
42 | 43 | FileUtils.rm_rf("/tmp/gitolite_gitlab_test") |
43 | 44 | print "Can clone gitolite-admin?............" |
44 | 45 | puts "YES".green |
... | ... | @@ -49,7 +50,7 @@ namespace :gitlab do |
49 | 50 | end |
50 | 51 | |
51 | 52 | print "UMASK for .gitolite.rc is 0007? ............" |
52 | - unless open("#{GIT_HOST['base_path']}/../.gitolite.rc").grep(/REPO_UMASK = 0007/).empty? | |
53 | + unless open("#{git_base_path}/../.gitolite.rc").grep(/REPO_UMASK = 0007/).empty? | |
53 | 54 | puts "YES".green |
54 | 55 | else |
55 | 56 | puts "NO".red | ... | ... |
spec/mailers/notify_spec.rb
... | ... | @@ -5,7 +5,7 @@ describe Notify do |
5 | 5 | include EmailSpec::Matchers |
6 | 6 | |
7 | 7 | before :all do |
8 | - default_url_options[:host] = EMAIL_OPTS['host'] | |
8 | + default_url_options[:host] = Gitlab.config.web_host | |
9 | 9 | end |
10 | 10 | |
11 | 11 | let(:recipient) { Factory.create(:user, :email => 'recipient@example.com') } | ... | ... |
spec/models/project_spec.rb
... | ... | @@ -56,7 +56,7 @@ describe Project do |
56 | 56 | |
57 | 57 | it "returns the full web URL for this repo" do |
58 | 58 | project = Project.new(:code => "somewhere") |
59 | - project.web_url.should == "#{GIT_HOST['host']}/somewhere" | |
59 | + project.web_url.should == "#{Gitlab.config.url}/somewhere" | |
60 | 60 | end |
61 | 61 | |
62 | 62 | describe :valid_repo? do | ... | ... |