summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2015-07-30 13:45:27 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2015-07-30 13:45:27 +0000
commitdc51460c34b185ec85cb27c69767878eeb02779a (patch)
tree7b6636c78baed3d28faa491554461489f21fcf01
parentdb03907e8fa773af4e7d5934e65c3fd0da92d6f3 (diff)
parent6c1a756768bcf9370d104c2532077e62253f05e3 (diff)
downloadgitlab-ci-dc51460c34b185ec85cb27c69767878eeb02779a.tar.gz
Merge branch 'application_settings' into 'master'
Added Application Settings This moves some of the settings from application.yml to Admin page. ![Screen_Shot_2015-07-30_at_12.22.27](https://gitlab.com/gitlab-org/gitlab-ci/uploads/d37aa0003d9afaeb85aa350bb02e6f07/Screen_Shot_2015-07-30_at_12.22.27.png) /cc @sytses @vsizov See merge request !215
-rw-r--r--CHANGELOG3
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock2
-rw-r--r--app/controllers/admin/application_settings_controller.rb29
-rw-r--r--app/models/application_setting.rb25
-rw-r--r--app/models/project.rb16
-rw-r--r--app/views/admin/application_settings/_form.html.haml24
-rw-r--r--app/views/admin/application_settings/show.html.haml3
-rw-r--r--app/views/layouts/_nav_admin.html.haml8
-rw-r--r--config/initializers/1_settings.rb4
-rw-r--r--config/routes.rb2
-rw-r--r--db/migrate/20150729145246_create_application_settings.rb10
-rw-r--r--db/schema.rb9
-rw-r--r--lib/current_settings.rb20
14 files changed, 144 insertions, 12 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 1ccf229..b545f1e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,7 +1,8 @@
v7.14.0 (unreleased)
- Truncate commit messages after subject line in table
- Adjust CI config to support Docker executors
-
+ - Added Application Settings
+
v7.13.1
- Fix: user could steal specific runner
- Fix: don't send notifications for jobs with allow_failure set
diff --git a/Gemfile b/Gemfile
index 1ceb7dd..f8ffdde 100644
--- a/Gemfile
+++ b/Gemfile
@@ -76,6 +76,7 @@ gem 'attr_encrypted', '1.3.4'
# Other
gem 'rake'
gem 'foreman'
+gem 'request_store'
gem 'jquery-rails', '~> 3.1.3'
gem 'gitlab_ci_meta', '~> 4.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index 23eff90..5d648b3 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -339,6 +339,7 @@ GEM
redis (3.0.6)
redis-namespace (1.4.1)
redis (~> 3.0.4)
+ request_store (1.2.0)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
@@ -505,6 +506,7 @@ DEPENDENCIES
rake
rb-fsevent
rb-inotify
+ request_store
rspec-rails
rubocop (= 0.28.0)
sass-rails (~> 4.0.5)
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb
new file mode 100644
index 0000000..8f673b9
--- /dev/null
+++ b/app/controllers/admin/application_settings_controller.rb
@@ -0,0 +1,29 @@
+class Admin::ApplicationSettingsController < Admin::ApplicationController
+ before_action :set_application_setting
+
+ def show
+ end
+
+ def update
+ if @application_setting.update_attributes(application_setting_params)
+ redirect_to admin_application_settings_path,
+ notice: 'Application settings saved successfully'
+ else
+ render :show
+ end
+ end
+
+ private
+
+ def set_application_setting
+ @application_setting = ApplicationSetting.current
+ @application_setting ||= ApplicationSetting.create_from_defaults
+ end
+
+ def application_setting_params
+ params.require(:application_setting).permit(
+ :all_broken_builds,
+ :add_pusher,
+ )
+ end
+end
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb
new file mode 100644
index 0000000..f68f10a
--- /dev/null
+++ b/app/models/application_setting.rb
@@ -0,0 +1,25 @@
+# == Schema Information
+#
+# Table name: application_settings
+#
+# id :integer not null, primary key
+# all_broken_builds :boolean
+# add_pusher :boolean
+# created_at :datetime
+# updated_at :datetime
+#
+
+class ApplicationSetting < ActiveRecord::Base
+
+ def self.current
+ ApplicationSetting.last
+ end
+
+ def self.create_from_defaults
+ create(
+ all_broken_builds: Settings.gitlab_ci['all_broken_builds'],
+ add_pusher: Settings.gitlab_ci['add_pusher'],
+ )
+ end
+
+end
diff --git a/app/models/project.rb b/app/models/project.rb
index 4e3e966..b4a3ffc 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -61,6 +61,8 @@ class Project < ActiveRecord::Base
before_validation :set_default_values
class << self
+ include CurrentSettings
+
def base_build_script
<<-eos
git submodule update --init
@@ -70,13 +72,13 @@ ls -la
def parse(project)
params = {
- name: project.name_with_namespace,
- gitlab_id: project.id,
- path: project.path_with_namespace,
- default_ref: project.default_branch || 'master',
- ssh_url_to_repo: project.ssh_url_to_repo,
- email_add_pusher: GitlabCi.config.gitlab_ci.add_pusher,
- email_only_broken_builds: GitlabCi.config.gitlab_ci.all_broken_builds,
+ name: project.name_with_namespace,
+ gitlab_id: project.id,
+ path: project.path_with_namespace,
+ default_ref: project.default_branch || 'master',
+ ssh_url_to_repo: project.ssh_url_to_repo,
+ email_add_pusher: current_application_settings.add_pusher,
+ email_only_broken_builds: current_application_settings.all_broken_builds,
}
project = Project.new(params)
diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml
new file mode 100644
index 0000000..a767257
--- /dev/null
+++ b/app/views/admin/application_settings/_form.html.haml
@@ -0,0 +1,24 @@
+= form_for @application_setting, url: admin_application_settings_path, html: { class: 'form-horizontal fieldset-form' } do |f|
+ - if @application_setting.errors.any?
+ #error_explanation
+ .alert.alert-danger
+ - @application_setting.errors.full_messages.each do |msg|
+ %p= msg
+
+ %fieldset
+ %legend Default Project Settings
+ .form-group
+ .col-sm-offset-2.col-sm-10
+ .checkbox
+ = f.label :all_broken_builds do
+ = f.check_box :all_broken_builds
+ Send emails only on broken builds
+ .form-group
+ .col-sm-offset-2.col-sm-10
+ .checkbox
+ = f.label :add_pusher do
+ = f.check_box :add_pusher
+ Add pusher to recipients list
+
+ .form-actions
+ = f.submit 'Save', class: 'btn btn-primary'
diff --git a/app/views/admin/application_settings/show.html.haml b/app/views/admin/application_settings/show.html.haml
new file mode 100644
index 0000000..7ef0aa8
--- /dev/null
+++ b/app/views/admin/application_settings/show.html.haml
@@ -0,0 +1,3 @@
+%h3.page-title Settings
+%hr
+= render 'form'
diff --git a/app/views/layouts/_nav_admin.html.haml b/app/views/layouts/_nav_admin.html.haml
index 12bfb80..94b5468 100644
--- a/app/views/layouts/_nav_admin.html.haml
+++ b/app/views/layouts/_nav_admin.html.haml
@@ -19,4 +19,10 @@
Builds
%small.pull-right
= Build.count(:all)
-
+ %li
+ %hr
+ = nav_link(controller: :application_settings, html_options: { class: 'separate-item'}) do
+ = link_to admin_application_settings_path do
+ %i.icon-cogs
+ %span
+ Settings
diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb
index a8f1107..bd44569 100644
--- a/config/initializers/1_settings.rb
+++ b/config/initializers/1_settings.rb
@@ -37,8 +37,8 @@ Settings.gitlab_ci['relative_url_root'] ||= ENV['RAILS_RELATIVE_URL_ROOT'] ||
Settings.gitlab_ci['protocol'] ||= Settings.gitlab_ci.https ? "https" : "http"
Settings.gitlab_ci['email_from'] ||= "gitlab-ci@#{Settings.gitlab_ci.host}"
Settings.gitlab_ci['support_email'] ||= Settings.gitlab_ci.email_from
-Settings.gitlab_ci['all_broken_builds'] = true if Settings.gitlab_ci['all_broken_builds'].nil?
-Settings.gitlab_ci['add_pusher'] = false if Settings.gitlab_ci['add_pusher'].nil?
+Settings.gitlab_ci['all_broken_builds'] = true if Settings.gitlab_ci['all_broken_builds'].nil?
+Settings.gitlab_ci['add_pusher'] = false if Settings.gitlab_ci['add_pusher'].nil?
Settings.gitlab_ci['url'] ||= Settings.send(:build_gitlab_ci_url)
Settings.gitlab_ci['builds_path'] = File.expand_path(Settings.gitlab_ci['builds_path'] || "builds/", Rails.root)
diff --git a/config/routes.rb b/config/routes.rb
index 2b3ad5c..e92e726 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -90,6 +90,8 @@ Rails.application.routes.draw do
end
resources :builds, only: :index
+
+ resource :application_settings, only: [:show, :update]
end
root to: 'projects#index'
diff --git a/db/migrate/20150729145246_create_application_settings.rb b/db/migrate/20150729145246_create_application_settings.rb
new file mode 100644
index 0000000..4623345
--- /dev/null
+++ b/db/migrate/20150729145246_create_application_settings.rb
@@ -0,0 +1,10 @@
+class CreateApplicationSettings < ActiveRecord::Migration
+ def change
+ create_table :application_settings do |t|
+ t.boolean :all_broken_builds
+ t.boolean :add_pusher
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 1363111..e23f099 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,11 +11,18 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20150721204649) do
+ActiveRecord::Schema.define(version: 20150729145246) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
+ create_table "application_settings", force: true do |t|
+ t.boolean "all_broken_builds"
+ t.boolean "add_pusher"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "builds", force: true do |t|
t.integer "project_id"
t.string "status"
diff --git a/lib/current_settings.rb b/lib/current_settings.rb
new file mode 100644
index 0000000..59dedfd
--- /dev/null
+++ b/lib/current_settings.rb
@@ -0,0 +1,20 @@
+module CurrentSettings
+ def current_application_settings
+ key = :current_application_settings
+
+ RequestStore.store[key] ||= begin
+ if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?('application_settings')
+ ApplicationSetting.current || ApplicationSetting.create_from_defaults
+ else
+ fake_application_settings
+ end
+ end
+ end
+
+ def fake_application_settings
+ OpenStruct.new(
+ all_broken_builds: Settings.gitlab_ci['all_broken_builds'],
+ add_pusher: Settings.gitlab_ci['add_pusher'],
+ )
+ end
+end