summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG3
-rw-r--r--app/controllers/admin/application_settings_controller.rb29
-rw-r--r--app/models/application_setting.rb25
-rw-r--r--app/models/project.rb15
-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
12 files changed, 140 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/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..1b98e19 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -27,6 +27,7 @@
class Project < ActiveRecord::Base
include ProjectStatus
+ include CurrentSettings
has_many :commits, dependent: :destroy
has_many :builds, through: :commits, dependent: :destroy
@@ -70,13 +71,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