a6c7d8050e
Fix https://gitlab.com/gitlab-org/gitlab-ee/issues/4474 Conflicts: db/schema.rb ee/app/controllers/ee/admin/application_settings_controller.rb ee/app/helpers/ee/application_settings_helper.rb ee/app/models/ee/application_setting.rb ee/app/models/license.rb ee/app/views/layouts/service_desk.html.haml ee/app/views/notify/approved_merge_request_email.html.haml ee/app/views/notify/service_desk_new_note_email.text.erb ee/app/views/notify/service_desk_thank_you_email.text.erb ee/app/views/notify/unapproved_merge_request_email.html.haml ee/lib/ee/api/entities.rb ee/spec/controllers/admin/application_settings_controller_spec.rb ee/spec/models/application_setting_spec.rb ee/spec/requests/api/settings_spec.rb lib/api/settings.rb spec/mailers/previews/notify_preview.rb
84 lines
2.1 KiB
Ruby
84 lines
2.1 KiB
Ruby
module Gitlab
|
|
module Utils
|
|
extend self
|
|
|
|
# Run system command without outputting to stdout.
|
|
#
|
|
# @param cmd [Array<String>]
|
|
# @return [Boolean]
|
|
def system_silent(cmd)
|
|
Popen.popen(cmd).last.zero?
|
|
end
|
|
|
|
def force_utf8(str)
|
|
str.force_encoding(Encoding::UTF_8)
|
|
end
|
|
|
|
# A slugified version of the string, suitable for inclusion in URLs and
|
|
# domain names. Rules:
|
|
#
|
|
# * Lowercased
|
|
# * Anything not matching [a-z0-9-] is replaced with a -
|
|
# * Maximum length is 63 bytes
|
|
# * First/Last Character is not a hyphen
|
|
def slugify(str)
|
|
return str.downcase
|
|
.gsub(/[^a-z0-9]/, '-')[0..62]
|
|
.gsub(/(\A-+|-+\z)/, '')
|
|
end
|
|
|
|
# Converts newlines into HTML line break elements
|
|
def nlbr(str)
|
|
ActionView::Base.full_sanitizer.sanitize(str, tags: []).gsub(/\r?\n/, '<br>').html_safe
|
|
end
|
|
|
|
def remove_line_breaks(str)
|
|
str.gsub(/\r?\n/, '')
|
|
end
|
|
|
|
def to_boolean(value)
|
|
return value if [true, false].include?(value)
|
|
return true if value =~ /^(true|t|yes|y|1|on)$/i
|
|
return false if value =~ /^(false|f|no|n|0|off)$/i
|
|
|
|
nil
|
|
end
|
|
|
|
def boolean_to_yes_no(bool)
|
|
if bool
|
|
'Yes'
|
|
else
|
|
'No'
|
|
end
|
|
end
|
|
|
|
def random_string
|
|
Random.rand(Float::MAX.to_i).to_s(36)
|
|
end
|
|
|
|
# See: http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
|
|
# Cross-platform way of finding an executable in the $PATH.
|
|
#
|
|
# which('ruby') #=> /usr/bin/ruby
|
|
def which(cmd, env = ENV)
|
|
exts = env['PATHEXT'] ? env['PATHEXT'].split(';') : ['']
|
|
|
|
env['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
|
exts.each do |ext|
|
|
exe = File.join(path, "#{cmd}#{ext}")
|
|
return exe if File.executable?(exe) && !File.directory?(exe)
|
|
end
|
|
end
|
|
|
|
nil
|
|
end
|
|
|
|
# Used in EE
|
|
# Accepts either an Array or a String and returns an array
|
|
def ensure_array_from_string(string_or_array)
|
|
return string_or_array if string_or_array.is_a?(Array)
|
|
|
|
string_or_array.split(',').map(&:strip)
|
|
end
|
|
end
|
|
end
|