Commit 9b337b8328a65c5e692c90ba1f817184bd054257

Authored by Dmitriy Zaporozhets
1 parent b3a0ee8e

Epic: Gitlab configuration with default values

@@ -40,6 +40,7 @@ gem "foreman" @@ -40,6 +40,7 @@ gem "foreman"
40 gem "colored" 40 gem "colored"
41 gem 'resque_mailer' 41 gem 'resque_mailer'
42 gem 'tabs_on_rails' 42 gem 'tabs_on_rails'
  43 +gem 'settingslogic'
43 44
44 group :assets do 45 group :assets do
45 gem "sass-rails", "3.2.5" 46 gem "sass-rails", "3.2.5"
@@ -313,6 +313,7 @@ GEM @@ -313,6 +313,7 @@ GEM
313 libwebsocket (~> 0.1.3) 313 libwebsocket (~> 0.1.3)
314 multi_json (~> 1.0) 314 multi_json (~> 1.0)
315 rubyzip 315 rubyzip
  316 + settingslogic (2.0.8)
316 shoulda-matchers (1.1.0) 317 shoulda-matchers (1.1.0)
317 activesupport (>= 3.0.0) 318 activesupport (>= 3.0.0)
318 simplecov (0.6.4) 319 simplecov (0.6.4)
@@ -416,6 +417,7 @@ DEPENDENCIES @@ -416,6 +417,7 @@ DEPENDENCIES
416 rspec-rails 417 rspec-rails
417 sass-rails (= 3.2.5) 418 sass-rails (= 3.2.5)
418 seed-fu 419 seed-fu
  420 + settingslogic
419 shoulda-matchers 421 shoulda-matchers
420 simplecov 422 simplecov
421 six 423 six
app/assets/stylesheets/gitlab_bootstrap.scss
@@ -158,6 +158,11 @@ table { @@ -158,6 +158,11 @@ table {
158 &.small { 158 &.small {
159 @extend .btn-small; 159 @extend .btn-small;
160 } 160 }
  161 +
  162 + &.active {
  163 + border-color:#aaa;
  164 + background-color:#ccc;
  165 + }
161 } 166 }
162 167
163 a:focus { 168 a:focus {
app/helpers/application_helper.rb
@@ -13,7 +13,7 @@ module ApplicationHelper @@ -13,7 +13,7 @@ module ApplicationHelper
13 end 13 end
14 14
15 def web_app_url 15 def web_app_url
16 - "#{request_protocol}://#{GIT_HOST["host"]}/" 16 + "#{request_protocol}://#{Gitlab.config.web_host}/"
17 end 17 end
18 18
19 def last_commit(project) 19 def last_commit(project)
app/mailers/notify.rb
@@ -2,10 +2,10 @@ class Notify < ActionMailer::Base @@ -2,10 +2,10 @@ class Notify < ActionMailer::Base
2 include Resque::Mailer 2 include Resque::Mailer
3 add_template_helper ApplicationHelper 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 def new_user_email(user_id, password) 10 def new_user_email(user_id, password)
11 @user = User.find(user_id) 11 @user = User.find(user_id)
app/models/project.rb
@@ -113,7 +113,7 @@ class Project < ActiveRecord::Base @@ -113,7 +113,7 @@ class Project < ActiveRecord::Base
113 end 113 end
114 114
115 def web_url 115 def web_url
116 - [GIT_HOST['host'], code].join("/") 116 + [Gitlab.config.url, code].join("/")
117 end 117 end
118 118
119 def common_notes 119 def common_notes
app/roles/git_push.rb
@@ -73,7 +73,7 @@ module GitPush @@ -73,7 +73,7 @@ module GitPush
73 id: commit.id, 73 id: commit.id,
74 message: commit.safe_message, 74 message: commit.safe_message,
75 timestamp: commit.date.xmlschema, 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 author: { 77 author: {
78 name: commit.author_name, 78 name: commit.author_name,
79 email: commit.author_email 79 email: commit.author_email
app/roles/repository.rb
@@ -68,7 +68,7 @@ module Repository @@ -68,7 +68,7 @@ module Repository
68 end 68 end
69 69
70 def path_to_repo 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 end 72 end
73 73
74 def update_repository 74 def update_repository
@@ -141,4 +141,12 @@ module Repository @@ -141,4 +141,12 @@ module Repository
141 141
142 file_path 142 file_path
143 end 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 end 152 end
app/views/admin/projects/_form.html.haml
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 Path 13 Path
14 .input 14 .input
15 .input-prepend 15 .input-prepend
16 - %span.add-on= "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:" 16 + %span.add-on= Gitlab.config.ssh_path
17 = f.text_field :path, :placeholder => "example_project", :disabled => !@admin_project.new_record? 17 = f.text_field :path, :placeholder => "example_project", :disabled => !@admin_project.new_record?
18 .clearfix 18 .clearfix
19 = f.label :code do 19 = f.label :code do
app/views/projects/_form.html.haml
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 Git Clone 18 Git Clone
19 .input 19 .input
20 .input-prepend 20 .input-prepend
21 - %span.add-on= "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:" 21 + %span.add-on= Gitlab.config.ssh_path
22 = f.text_field :path, :placeholder => "example_project", :disabled => !@project.new_record? 22 = f.text_field :path, :placeholder => "example_project", :disabled => !@project.new_record?
23 %span.add-on= ".git" 23 %span.add-on= ".git"
24 .clearfix 24 .clearfix
app/views/projects/_new_form.html.haml
@@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
17 Git Clone 17 Git Clone
18 .input 18 .input
19 .input-prepend 19 .input-prepend
20 - %span.add-on= "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:" 20 + %span.add-on= Gitlab.config.ssh_path
21 = f.text_field :path, :placeholder => "example_project", :disabled => !@project.new_record? 21 = f.text_field :path, :placeholder => "example_project", :disabled => !@project.new_record?
22 %span.add-on= ".git" 22 %span.add-on= ".git"
23 .clearfix 23 .clearfix
app/views/projects/show.html.haml
@@ -4,8 +4,11 @@ @@ -4,8 +4,11 @@
4 .row 4 .row
5 .span7 5 .span7
6 .form-horizontal 6 .form-horizontal
7 - .input-prepend 7 + .input-prepend.project_clone_holder
  8 +
8 %span.add-on git clone 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 = text_field_tag :project_clone, @project.url_to_repo, :class => "one_click_select span5" 12 = text_field_tag :project_clone, @project.url_to_repo, :class => "one_click_select span5"
10 .span4.right 13 .span4.right
11 .right 14 .right
@@ -23,4 +26,12 @@ @@ -23,4 +26,12 @@
23 = render "events/event_last_push", :event => @last_push 26 = render "events/event_last_push", :event => @last_push
24 .content_list= render @events 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 # Email used for notification 11 # Email used for notification
4 # about new issues, comments 12 # about new issues, comments
5 email: 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 # Git Hosting configuration 16 # Git Hosting configuration
14 git_host: 17 git_host:
15 - system: gitolite  
16 admin_uri: git@localhost:gitolite-admin 18 admin_uri: git@localhost:gitolite-admin
17 base_path: /home/git/repositories/ 19 base_path: /home/git/repositories/
18 host: localhost 20 host: localhost
config/initializers/00_before_all.rb
@@ -1,4 +0,0 @@ @@ -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"]  
config/initializers/0_before_all.rb 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +GITLAB_OPTS = YAML.load_file("#{Rails.root}/config/gitlab.yml")["gitlab"]
config/initializers/1_settings.rb 0 → 100644
@@ -0,0 +1,75 @@ @@ -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
config/initializers/2_app.rb 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +module Gitlab
  2 + Version = File.read(Rails.root.join("VERSION"))
  3 + Revision = `git log --pretty=format:'%h' -n 1`
  4 +
  5 + def self.config
  6 + Settings
  7 + end
  8 +end
config/initializers/3_grit_ext.rb 0 → 100644
@@ -0,0 +1,28 @@ @@ -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
config/initializers/4_resque_queues.rb 0 → 100644
@@ -0,0 +1 @@ @@ -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,7 +4,7 @@ Devise.setup do |config|
4 # ==> Mailer Configuration 4 # ==> Mailer Configuration
5 # Configure the e-mail address which will be shown in Devise::Mailer, 5 # Configure the e-mail address which will be shown in Devise::Mailer,
6 # note that it will be overwritten if you use your own mailer class with default "from" parameter. 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 # Configure the class responsible to send e-mails. 9 # Configure the class responsible to send e-mails.
10 # config.mailer = "Devise::Mailer" 10 # config.mailer = "Devise::Mailer"
config/initializers/gitlab/10_app.rb
@@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
1 -module Gitlab  
2 - Version = File.read(Rails.root.join("VERSION"))  
3 - Revision = `git log --pretty=format:'%h' -n 1`  
4 -end  
config/initializers/gitlab/20_grit_ext.rb
@@ -1,28 +0,0 @@ @@ -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 +0,0 @@
1 -Resque.watch_queue(PostReceive.instance_variable_get("@queue"))  
config/routes.rb
@@ -14,10 +14,10 @@ Gitlab::Application.routes.draw do @@ -14,10 +14,10 @@ Gitlab::Application.routes.draw do
14 14
15 # Enable Grack support 15 # Enable Grack support
16 mount Grack::Bundle.new({ 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 }), at: '/:path', constraints: { path: /[\w-]+\.git/ } 21 }), at: '/:path', constraints: { path: /[\w-]+\.git/ }
22 22
23 # 23 #
lib/gitlab/git_host.rb
@@ -7,15 +7,11 @@ module Gitlab @@ -7,15 +7,11 @@ module Gitlab
7 end 7 end
8 8
9 def self.admin_uri 9 def self.admin_uri
10 - GIT_HOST["admin_uri"] 10 + Gitlab.config.git_host.admin_uri
11 end 11 end
12 12
13 def self.url_to_repo(path) 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 end 15 end
20 end 16 end
21 end 17 end
lib/tasks/gitlab/status.rake
@@ -3,6 +3,7 @@ namespace :gitlab do @@ -3,6 +3,7 @@ namespace :gitlab do
3 desc "GITLAB | Check gitlab installation status" 3 desc "GITLAB | Check gitlab installation status"
4 task :status => :environment do 4 task :status => :environment do
5 puts "Starting diagnostic" 5 puts "Starting diagnostic"
  6 + git_base_path = Gitlab.config.git_base_path
6 7
7 print "config/database.yml............" 8 print "config/database.yml............"
8 if File.exists?(File.join Rails.root, "config", "database.yml") 9 if File.exists?(File.join Rails.root, "config", "database.yml")
@@ -21,16 +22,16 @@ namespace :gitlab do @@ -21,16 +22,16 @@ namespace :gitlab do
21 end 22 end
22 23
23 GIT_HOST = YAML.load_file("#{Rails.root}/config/gitlab.yml")["git_host"] 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 puts "exists".green 27 puts "exists".green
27 else 28 else
28 puts "missing".red 29 puts "missing".red
29 return 30 return
30 end 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 puts "YES".green 35 puts "YES".green
35 else 36 else
36 puts "NO".red 37 puts "NO".red
@@ -38,7 +39,7 @@ namespace :gitlab do @@ -38,7 +39,7 @@ namespace :gitlab do
38 end 39 end
39 40
40 begin 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 FileUtils.rm_rf("/tmp/gitolite_gitlab_test") 43 FileUtils.rm_rf("/tmp/gitolite_gitlab_test")
43 print "Can clone gitolite-admin?............" 44 print "Can clone gitolite-admin?............"
44 puts "YES".green 45 puts "YES".green
@@ -49,7 +50,7 @@ namespace :gitlab do @@ -49,7 +50,7 @@ namespace :gitlab do
49 end 50 end
50 51
51 print "UMASK for .gitolite.rc is 0007? ............" 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 puts "YES".green 54 puts "YES".green
54 else 55 else
55 puts "NO".red 56 puts "NO".red
spec/mailers/notify_spec.rb
@@ -5,7 +5,7 @@ describe Notify do @@ -5,7 +5,7 @@ describe Notify do
5 include EmailSpec::Matchers 5 include EmailSpec::Matchers
6 6
7 before :all do 7 before :all do
8 - default_url_options[:host] = EMAIL_OPTS['host'] 8 + default_url_options[:host] = Gitlab.config.web_host
9 end 9 end
10 10
11 let(:recipient) { Factory.create(:user, :email => 'recipient@example.com') } 11 let(:recipient) { Factory.create(:user, :email => 'recipient@example.com') }
spec/models/project_spec.rb
@@ -56,7 +56,7 @@ describe Project do @@ -56,7 +56,7 @@ describe Project do
56 56
57 it "returns the full web URL for this repo" do 57 it "returns the full web URL for this repo" do
58 project = Project.new(:code => "somewhere") 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 end 60 end
61 61
62 describe :valid_repo? do 62 describe :valid_repo? do