Skip to content
Snippets Groups Projects
Commit 861dd8ff authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Added Application Settings

parent 6ec3f987
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
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
@@ -27,6 +27,7 @@
 
class Project < ActiveRecord::Base
include ProjectStatus
include CurrentSettings
 
has_many :commits, dependent: :destroy
has_many :builds, through: :commits, dependent: :destroy
Loading
Loading
@@ -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)
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