Skip to content
Snippets Groups Projects
Commit dc51460c authored by Kamil Trzciński's avatar Kamil Trzciński
Browse files

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
parents db03907e 6c1a7567
No related branches found
No related tags found
No related merge requests found
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
Loading
Loading
Loading
Loading
@@ -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'
 
Loading
Loading
Loading
Loading
@@ -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)
Loading
Loading
@@ -505,6 +506,7 @@ DEPENDENCIES
rake
rb-fsevent
rb-inotify
request_store
rspec-rails
rubocop (= 0.28.0)
sass-rails (~> 4.0.5)
Loading
Loading
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
# == 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
Loading
Loading
@@ -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
Loading
Loading
@@ -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)
Loading
Loading
= 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'
%h3.page-title Settings
%hr
= render 'form'
Loading
Loading
@@ -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
Loading
Loading
@@ -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)
 
Loading
Loading
Loading
Loading
@@ -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'
Loading
Loading
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
Loading
Loading
@@ -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"
Loading
Loading
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment