Commit 170fef0b authored by Robert Speicher's avatar Robert Speicher

Merge branch 'dm-meer-blauw-op-straat' into 'master'

Enable (and disable) more RuboCops

See merge request !9432
parents 6a398883 ade5e0b1
This diff is collapsed.
This diff is collapsed.
...@@ -301,10 +301,10 @@ group :development, :test do ...@@ -301,10 +301,10 @@ group :development, :test do
gem 'spring-commands-rspec', '~> 1.0.4' gem 'spring-commands-rspec', '~> 1.0.4'
gem 'spring-commands-spinach', '~> 1.1.0' gem 'spring-commands-spinach', '~> 1.1.0'
gem 'rubocop', '~> 0.46.0', require: false gem 'rubocop', '~> 0.47.1', require: false
gem 'rubocop-rspec', '~> 1.9.1', require: false gem 'rubocop-rspec', '~> 1.12.0', require: false
gem 'scss_lint', '~> 0.47.0', require: false gem 'scss_lint', '~> 0.47.0', require: false
gem 'haml_lint', '~> 0.18.2', require: false gem 'haml_lint', '~> 0.21.0', require: false
gem 'simplecov', '0.12.0', require: false gem 'simplecov', '0.12.0', require: false
gem 'flay', '~> 2.6.1', require: false gem 'flay', '~> 2.6.1', require: false
gem 'bundler-audit', '~> 0.5.0', require: false gem 'bundler-audit', '~> 0.5.0', require: false
......
...@@ -319,10 +319,10 @@ GEM ...@@ -319,10 +319,10 @@ GEM
multi_json (>= 1.3.2) multi_json (>= 1.3.2)
haml (4.0.7) haml (4.0.7)
tilt tilt
haml_lint (0.18.2) haml_lint (0.21.0)
haml (~> 4.0) haml (~> 4.0)
rake (>= 10, < 12) rake (>= 10, < 13)
rubocop (>= 0.36.0) rubocop (>= 0.47.0)
sysexits (~> 1.1) sysexits (~> 1.1)
hamlit (2.6.1) hamlit (2.6.1)
temple (~> 0.7.6) temple (~> 0.7.6)
...@@ -501,7 +501,7 @@ GEM ...@@ -501,7 +501,7 @@ GEM
os (0.9.6) os (0.9.6)
paranoia (2.2.0) paranoia (2.2.0)
activerecord (>= 4.0, < 5.1) activerecord (>= 4.0, < 5.1)
parser (2.3.1.4) parser (2.4.0.0)
ast (~> 2.2) ast (~> 2.2)
pg (0.18.4) pg (0.18.4)
poltergeist (1.9.0) poltergeist (1.9.0)
...@@ -642,13 +642,13 @@ GEM ...@@ -642,13 +642,13 @@ GEM
pg pg
rails rails
sqlite3 sqlite3
rubocop (0.46.0) rubocop (0.47.1)
parser (>= 2.3.1.1, < 3.0) parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1) powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0) rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1) unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-rspec (1.9.1) rubocop-rspec (1.12.0)
rubocop (>= 0.42.0) rubocop (>= 0.42.0)
ruby-fogbugz (0.2.1) ruby-fogbugz (0.2.1)
crack (~> 0.4) crack (~> 0.4)
...@@ -759,7 +759,7 @@ GEM ...@@ -759,7 +759,7 @@ GEM
rack (>= 1, < 3) rack (>= 1, < 3)
thor (0.19.4) thor (0.19.4)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (2.0.5) tilt (2.0.6)
timecop (0.8.1) timecop (0.8.1)
timfel-krb5-auth (0.8.3) timfel-krb5-auth (0.8.3)
tool (0.2.3) tool (0.2.3)
...@@ -776,7 +776,7 @@ GEM ...@@ -776,7 +776,7 @@ GEM
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext
unf_ext (0.0.7.2) unf_ext (0.0.7.2)
unicode-display_width (1.1.1) unicode-display_width (1.1.3)
unicorn (5.1.0) unicorn (5.1.0)
kgio (~> 2.6) kgio (~> 2.6)
raindrops (~> 0.7) raindrops (~> 0.7)
...@@ -888,7 +888,7 @@ DEPENDENCIES ...@@ -888,7 +888,7 @@ DEPENDENCIES
google-api-client (~> 0.8.6) google-api-client (~> 0.8.6)
grape (~> 0.18.0) grape (~> 0.18.0)
grape-entity (~> 0.6.0) grape-entity (~> 0.6.0)
haml_lint (~> 0.18.2) haml_lint (~> 0.21.0)
hamlit (~> 2.6.1) hamlit (~> 2.6.1)
health_check (~> 2.2.0) health_check (~> 2.2.0)
hipchat (~> 1.5.0) hipchat (~> 1.5.0)
...@@ -963,8 +963,8 @@ DEPENDENCIES ...@@ -963,8 +963,8 @@ DEPENDENCIES
rspec-rails (~> 3.5.0) rspec-rails (~> 3.5.0)
rspec-retry (~> 0.4.5) rspec-retry (~> 0.4.5)
rspec_profiling (~> 0.0.5) rspec_profiling (~> 0.0.5)
rubocop (~> 0.46.0) rubocop (~> 0.47.1)
rubocop-rspec (~> 1.9.1) rubocop-rspec (~> 1.12.0)
ruby-fogbugz (~> 0.2.1) ruby-fogbugz (~> 0.2.1)
ruby-prof (~> 0.16.2) ruby-prof (~> 0.16.2)
rugged (~> 0.24.0) rugged (~> 0.24.0)
......
...@@ -3,7 +3,7 @@ class Admin::SystemInfoController < Admin::ApplicationController ...@@ -3,7 +3,7 @@ class Admin::SystemInfoController < Admin::ApplicationController
'nobrowse', 'nobrowse',
'read-only', 'read-only',
'ro' 'ro'
] ].freeze
EXCLUDED_MOUNT_TYPES = [ EXCLUDED_MOUNT_TYPES = [
'autofs', 'autofs',
...@@ -27,7 +27,7 @@ class Admin::SystemInfoController < Admin::ApplicationController ...@@ -27,7 +27,7 @@ class Admin::SystemInfoController < Admin::ApplicationController
'tmpfs', 'tmpfs',
'tracefs', 'tracefs',
'vfat' 'vfat'
] ].freeze
def show def show
@cpus = Vmstat.cpu rescue nil @cpus = Vmstat.cpu rescue nil
......
...@@ -181,7 +181,7 @@ class ApplicationController < ActionController::Base ...@@ -181,7 +181,7 @@ class ApplicationController < ActionController::Base
end end
def gitlab_ldap_access(&block) def gitlab_ldap_access(&block)
Gitlab::LDAP::Access.open { |access| block.call(access) } Gitlab::LDAP::Access.open { |access| yield(access) }
end end
# JSON for infinite scroll via Pager object # JSON for infinite scroll via Pager object
......
...@@ -101,13 +101,14 @@ module CreatesCommit ...@@ -101,13 +101,14 @@ module CreatesCommit
# TODO: We should really clean this up # TODO: We should really clean this up
def set_commit_variables def set_commit_variables
if can?(current_user, :push_code, @project) @mr_source_project =
# Edit file in this project if can?(current_user, :push_code, @project)
@mr_source_project = @project # Edit file in this project
else @project
# Merge request from fork to this project else
@mr_source_project = current_user.fork_of(@project) # Merge request from fork to this project
end current_user.fork_of(@project)
end
# Merge request to this project # Merge request to this project
@mr_target_project = @project @mr_target_project = @project
......
...@@ -59,10 +59,10 @@ module ServiceParams ...@@ -59,10 +59,10 @@ module ServiceParams
:user_key, :user_key,
:username, :username,
:webhook :webhook
] ].freeze
# Parameters to ignore if no value is specified # Parameters to ignore if no value is specified
FILTER_BLANK_PARAMS = [:password] FILTER_BLANK_PARAMS = [:password].freeze
def service_params def service_params
dynamic_params = @service.event_channel_names + @service.event_names dynamic_params = @service.event_channel_names + @service.event_names
......
...@@ -27,7 +27,7 @@ module SpammableActions ...@@ -27,7 +27,7 @@ module SpammableActions
render :verify render :verify
else else
fallback.call yield
end end
end end
......
...@@ -5,7 +5,7 @@ class JwtController < ApplicationController ...@@ -5,7 +5,7 @@ class JwtController < ApplicationController
SERVICES = { SERVICES = {
Auth::ContainerRegistryAuthenticationService::AUDIENCE => Auth::ContainerRegistryAuthenticationService, Auth::ContainerRegistryAuthenticationService::AUDIENCE => Auth::ContainerRegistryAuthenticationService,
} }.freeze
def auth def auth
service = SERVICES[params[:service]] service = SERVICES[params[:service]]
...@@ -39,7 +39,8 @@ class JwtController < ApplicationController ...@@ -39,7 +39,8 @@ class JwtController < ApplicationController
message: "HTTP Basic: Access denied\n" \ message: "HTTP Basic: Access denied\n" \
"You have 2FA enabled, please use a personal access token for Git over HTTP.\n" \ "You have 2FA enabled, please use a personal access token for Git over HTTP.\n" \
"You can generate one at #{profile_personal_access_tokens_url}" } "You can generate one at #{profile_personal_access_tokens_url}" }
] }, status: 401 ]
}, status: 401
end end
def render_unauthorized def render_unauthorized
...@@ -47,7 +48,8 @@ class JwtController < ApplicationController ...@@ -47,7 +48,8 @@ class JwtController < ApplicationController
errors: [ errors: [
{ code: 'UNAUTHORIZED', { code: 'UNAUTHORIZED',
message: 'HTTP Basic: Access denied' } message: 'HTTP Basic: Access denied' }
] }, status: 401 ]
}, status: 401
end end
def auth_params def auth_params
......
...@@ -80,7 +80,7 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController ...@@ -80,7 +80,7 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
def build_qr_code def build_qr_code
uri = current_user.otp_provisioning_uri(account_string, issuer: issuer_host) uri = current_user.otp_provisioning_uri(account_string, issuer: issuer_host)
RQRCode::render_qrcode(uri, :svg, level: :m, unit: 3) RQRCode.render_qrcode(uri, :svg, level: :m, unit: 3)
end end
def account_string def account_string
......
...@@ -76,11 +76,12 @@ class Projects::GitHttpClientController < Projects::ApplicationController ...@@ -76,11 +76,12 @@ class Projects::GitHttpClientController < Projects::ApplicationController
return @project if defined?(@project) return @project if defined?(@project)
project_id, _ = project_id_with_suffix project_id, _ = project_id_with_suffix
if project_id.blank? @project =
@project = nil if project_id.blank?
else nil
@project = Project.find_by_full_path("#{params[:namespace_id]}/#{project_id}") else
end Project.find_by_full_path("#{params[:namespace_id]}/#{project_id}")
end
end end
# This method returns two values so that we can parse # This method returns two values so that we can parse
......
...@@ -381,14 +381,15 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -381,14 +381,15 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def merge_widget_refresh def merge_widget_refresh
if merge_request.merge_when_build_succeeds @status =
@status = :merge_when_build_succeeds if merge_request.merge_when_build_succeeds
else :merge_when_build_succeeds
# Only MRs that can be merged end in this action else
# MR can be already picked up for merge / merged already or can be waiting for worker to be picked up # Only MRs that can be merged end in this action
# in last case it does not have any special status. Possible error is handled inside widget js function # MR can be already picked up for merge / merged already or can be waiting for worker to be picked up
@status = :success # in last case it does not have any special status. Possible error is handled inside widget js function
end :success
end
render 'merge' render 'merge'
end end
......
...@@ -15,11 +15,12 @@ class SessionsController < Devise::SessionsController ...@@ -15,11 +15,12 @@ class SessionsController < Devise::SessionsController
def new def new
set_minimum_password_length set_minimum_password_length
if Gitlab.config.ldap.enabled @ldap_servers =
@ldap_servers = Gitlab::LDAP::Config.servers if Gitlab.config.ldap.enabled
else Gitlab::LDAP::Config.servers
@ldap_servers = [] else
end []
end
super super
end end
......
...@@ -28,8 +28,9 @@ class SnippetsController < ApplicationController ...@@ -28,8 +28,9 @@ class SnippetsController < ApplicationController
@snippets = SnippetsFinder.new.execute(current_user, { @snippets = SnippetsFinder.new.execute(current_user, {
filter: :by_user, filter: :by_user,
user: @user, user: @user,
scope: params[:scope] }). scope: params[:scope]
page(params[:page]) })
.page(params[:page])
render 'index' render 'index'
else else
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
# iids: integer[] # iids: integer[]
# #
class IssuableFinder class IssuableFinder
NONE = '0' NONE = '0'.freeze
attr_accessor :current_user, :params attr_accessor :current_user, :params
......
...@@ -28,11 +28,12 @@ class NotesFinder ...@@ -28,11 +28,12 @@ class NotesFinder
private private
def init_collection def init_collection
if @params[:target_id] @notes =
@notes = on_target(@params[:target_type], @params[:target_id]) if @params[:target_id]
else on_target(@params[:target_type], @params[:target_id])
@notes = notes_of_any_type else
end notes_of_any_type
end
end end
def notes_of_any_type def notes_of_any_type
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# #
class TodosFinder class TodosFinder
NONE = '0' NONE = '0'.freeze
attr_accessor :current_user, :params attr_accessor :current_user, :params
...@@ -99,7 +99,7 @@ class TodosFinder ...@@ -99,7 +99,7 @@ class TodosFinder
end end
def type? def type?
type.present? && ['Issue', 'MergeRequest'].include?(type) type.present? && %w(Issue MergeRequest).include?(type)
end end
def type def type
......
...@@ -69,11 +69,12 @@ module ApplicationHelper ...@@ -69,11 +69,12 @@ module ApplicationHelper
end end
def avatar_icon(user_or_email = nil, size = nil, scale = 2) def avatar_icon(user_or_email = nil, size = nil, scale = 2)
if user_or_email.is_a?(User) user =
user = user_or_email if user_or_email.is_a?(User)
else user_or_email
user = User.find_by_any_email(user_or_email.try(:downcase)) else
end User.find_by_any_email(user_or_email.try(:downcase))
end
if user if user
user.avatar_url(size) || default_avatar user.avatar_url(size) || default_avatar
......
module ApplicationSettingsHelper module ApplicationSettingsHelper
def gravatar_enabled? delegate :gravatar_enabled?,
current_application_settings.gravatar_enabled? :signup_enabled?,
end :signin_enabled?,
:akismet_enabled?,
def signup_enabled? :koding_enabled?,
current_application_settings.signup_enabled? to: :current_application_settings
end
def signin_enabled?
current_application_settings.signin_enabled?
end
def user_oauth_applications? def user_oauth_applications?
current_application_settings.user_oauth_applications current_application_settings.user_oauth_applications
end end
def askimet_enabled?
current_application_settings.akismet_enabled?
end
def koding_enabled?
current_application_settings.koding_enabled?
end
def allowed_protocols_present? def allowed_protocols_present?
current_application_settings.enabled_git_access_protocol.present? current_application_settings.enabled_git_access_protocol.present?
end end
......
...@@ -153,16 +153,17 @@ module BlobHelper ...@@ -153,16 +153,17 @@ module BlobHelper
# Because we are opionated we set the cache headers ourselves. # Because we are opionated we set the cache headers ourselves.
response.cache_control[:public] = @project.public? response.cache_control[:public] = @project.public?
if @ref && @commit && @ref == @commit.id response.cache_control[:max_age] =
# This is a link to a commit by its commit SHA. That means that the blob if @ref && @commit && @ref == @commit.id
# is immutable. The only reason to invalidate the cache is if the commit # This is a link to a commit by its commit SHA. That means that the blob
# was deleted or if the user lost access to the repository. # is immutable. The only reason to invalidate the cache is if the commit
response.cache_control[:max_age] = Blob::CACHE_TIME_IMMUTABLE # was deleted or if the user lost access to the repository.
else Blob::CACHE_TIME_IMMUTABLE
# A branch or tag points at this blob. That means that the expected blob else
# value may change over time. # A branch or tag points at this blob. That means that the expected blob
response.cache_control[:max_age] = Blob::CACHE_TIME # value may change over time.
end Blob::CACHE_TIME
end
response.etag = @blob.id response.etag = @blob.id
!stale !stale
......
...@@ -24,7 +24,7 @@ module EmailsHelper ...@@ -24,7 +24,7 @@ module EmailsHelper
def action_title(url) def action_title(url)
return unless url return unless url
["merge_requests", "issues", "commit"].each do |action| %w(merge_requests issues commit).each do |action|
if url.split("/").include?(action) if url.split("/").include?(action)
return "View #{action.humanize.singularize}" return "View #{action.humanize.singularize}"
end end
......
...@@ -23,7 +23,7 @@ module IssuablesHelper ...@@ -23,7 +23,7 @@ module IssuablesHelper
def issuable_json_path(issuable) def issuable_json_path(issuable)
project = issuable.project project = issuable.project
if issuable.kind_of?(MergeRequest) if issuable.is_a?(MergeRequest)
namespace_project_merge_request_path(project.namespace, project, issuable.iid, :json) namespace_project_merge_request_path(project.namespace, project, issuable.iid, :json)
else else
namespace_project_issue_path(project.namespace, project, issuable.iid, :json) namespace_project_issue_path(project.namespace, project, issuable.iid, :json)
...@@ -198,7 +198,7 @@ module IssuablesHelper ...@@ -198,7 +198,7 @@ module IssuablesHelper
@counts[issuable_type][state] @counts[issuable_type][state]
end end
IRRELEVANT_PARAMS_FOR_CACHE_KEY = %i[utf8 sort page] IRRELEVANT_PARAMS_FOR_CACHE_KEY = %i[utf8 sort page].freeze
private_constant :IRRELEVANT_PARAMS_FOR_CACHE_KEY private_constant :IRRELEVANT_PARAMS_FOR_CACHE_KEY
def issuables_state_counter_cache_key(issuable_type, state) def issuables_state_counter_cache_key(issuable_type, state)
......
...@@ -2,6 +2,7 @@ module JavascriptHelper ...@@ -2,6 +2,7 @@ module JavascriptHelper
def page_specific_javascript_tag(js) def page_specific_javascript_tag(js)
javascript_include_tag asset_path(js) javascript_include_tag asset_path(js)
end end
def page_specific_javascript_bundle_tag(js) def page_specific_javascript_bundle_tag(js)
javascript_include_tag(*webpack_asset_paths(js)) javascript_include_tag(*webpack_asset_paths(js))
end end
......
...@@ -33,7 +33,7 @@ module NamespacesHelper ...@@ -33,7 +33,7 @@ module NamespacesHelper
end end
def namespace_icon(namespace, size = 40) def namespace_icon(namespace, size = 40)
if namespace.kind_of?(Group) if namespace.is_a?(Group)
group_icon(namespace) group_icon(namespace)
else else
avatar_icon(namespace.owner.email, size) avatar_icon(namespace.owner.email, size)
......
...@@ -30,7 +30,7 @@ module SortingHelper ...@@ -30,7 +30,7 @@ module SortingHelper
} }
if current_controller?('admin/projects') if current_controller?('admin/projects')
options.merge!(sort_value_largest_repo => sort_title_largest_repo) options[sort_value_largest_repo] = sort_title_largest_repo
end end
options options
......
...@@ -37,8 +37,8 @@ module SubmoduleHelper ...@@ -37,8 +37,8 @@ module SubmoduleHelper
end end
def self_url?(url, namespace, project) def self_url?(url, namespace, project)
return true if url == [ Gitlab.config.gitlab.url, '/', namespace, '/', return true if url == [Gitlab.config.gitlab.url, '/', namespace, '/',
project, '.git' ].join('') project, '.git'].join('')
url == gitlab_shell.url_to_repo([namespace, '/', project].join('')) url == gitlab_shell.url_to_repo([namespace, '/', project].join(''))
end end
...@@ -48,8 +48,8 @@ module SubmoduleHelper ...@@ -48,8 +48,8 @@ module SubmoduleHelper
end end
def standard_links(host, namespace, project, commit) def standard_links(host, namespace, project, commit)
base = [ 'https://', host, '/', namespace, '/', project ].join('') base = ['https://', host, '/', namespace, '/', project].join('')
[base, [ base, '/tree/', commit ].join('')] [base, [base, '/tree/', commit].join('')]
end end
def relative_self_links(url, commit) def relative_self_links(url, commit)
......
...@@ -99,7 +99,7 @@ module TabHelper ...@@ -99,7 +99,7 @@ module TabHelper
return 'active' return 'active'
end end
if ['services', 'hooks', 'deploy_keys', 'protected_branches'].include? controller.controller_name if %w(services hooks deploy_keys protected_branches).include? controller.controller_name
"active" "active"
end end
end end
......
...@@ -150,6 +150,6 @@ module TodosHelper ...@@ -150,6 +150,6 @@ module TodosHelper
private private
def show_todo_state?(todo) def show_todo_state?(todo)
(todo.target.is_a?(MergeRequest) || todo.target.is_a?(Issue)) && ['closed', 'merged'].include?(todo.target.state) (todo.target.is_a?(MergeRequest) || todo.target.is_a?(Issue)) && %w(closed merged).include?(todo.target.state)
end end
end end
...@@ -89,13 +89,9 @@ module VisibilityLevelHelper ...@@ -89,13 +89,9 @@ module VisibilityLevelHelper
current_application_settings.restricted_visibility_levels || [] current_application_settings.restricted_visibility_levels || []
end end
def default_project_visibility delegate :default_project_visibility,
current_application_settings.default_project_visibility :default_group_visibility,
end to: :current_application_settings
def default_group_visibility
current_application_settings.default_group_visibility
end
def skip_level?(form_model, level) def skip_level?(form_model, level)
form_model.is_a?(Project) && !form_model.visibility_level_allowed?(level) form_model.is_a?(Project) && !form_model.visibility_level_allowed?(level)
......
class RepositoryCheckMailer < BaseMailer class RepositoryCheckMailer < BaseMailer
def notify(failed_count) def notify(failed_count)
if failed_count == 1 @message =
@message = "One project failed its last repository check" if failed_count == 1
else "One project failed its last repository check"
@message = "#{failed_count} projects failed their last repository check" else
end "#{failed_count} projects failed their last repository check"
end
mail( mail(
to: User.admins.pluck(:email), to: User.admins.pluck(:email),
......
...@@ -5,7 +5,7 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -5,7 +5,7 @@ class ApplicationSetting < ActiveRecord::Base
add_authentication_token_field :runners_registration_token add_authentication_token_field :runners_registration_token
add_authentication_token_field :health_check_access_token add_authentication_token_field :health_check_access_token
CACHE_KEY = 'application_setting.last' CACHE_KEY = 'application_setting.last'.freeze
DOMAIN_LIST_SEPARATOR = %r{\s*[,;]\s* # comma or semicolon, optionally surrounded by whitespace DOMAIN_LIST_SEPARATOR = %r{\s*[,;]\s* # comma or semicolon, optionally surrounded by whitespace
| # or | # or
\s # any whitespace character \s # any whitespace character
......
...@@ -22,8 +22,10 @@ module Ci ...@@ -22,8 +22,10 @@ module Ci
serialize :options serialize :options
serialize :yaml_variables, Gitlab::Serializer::Ci::Variables serialize :yaml_variables, Gitlab::Serializer::Ci::Variables
delegate :name, to: :project, prefix: true
validates :coverage, numericality: true, allow_blank: true validates :coverage, numericality: true, allow_blank: true
validates_presence_of :ref validates :ref, presence: true
scope :unstarted, ->() { where(runner_id: nil) } scope :unstarted, ->() { where(runner_id: nil) }
scope :ignore_failures, ->() { where(allow_failure: false) } scope :ignore_failures, ->() { where(allow_failure: false) }
...@@ -233,10 +235,6 @@ module Ci ...@@ -233,10 +235,6 @@ module Ci
gl_project_id gl_project_id
end end
def project_name
project.name
end
def repo_url def repo_url
auth = "gitlab-ci-token:#{ensure_token!}@" auth = "gitlab-ci-token:#{ensure_token!}@"
project.http_url_to_repo.sub(/^https?:\/\//) do |prefix| project.http_url_to_repo.sub(/^https?:\/\//) do |prefix|
...@@ -257,7 +255,7 @@ module Ci ...@@ -257,7 +255,7 @@ module Ci
return unless regex return unless regex
matches = text.scan(Regexp.new(regex)).last matches = text.scan(Regexp.new(regex)).last
matches = matches.last if matches.kind_of?(Array) matches = matches.last if matches.is_a?(Array)
coverage = matches.gsub(/\d+(\.\d+)?/).first coverage = matches.gsub(/\d+(\.\d+)?/).first
if coverage.present? if coverage.present?
......
...@@ -14,9 +14,11 @@ module Ci ...@@ -14,9 +14,11 @@ module Ci
has_many :builds, foreign_key: :commit_id has_many :builds, foreign_key: :commit_id
has_many :trigger_requests, dependent: :destroy, foreign_key: :commit_id has_many :trigger_requests, dependent: :destroy, foreign_key: :commit_id
validates_presence_of :sha, unless: :importing? delegate :id, to: :project, prefix: true
validates_presence_of :ref, unless: :importing?
validates_presence_of :status, unless: :importing? validates :sha, presence: { unless: :importing? }
validates :ref, presence: { unless: :importing? }
validates :status, presence: { unless: :importing? }
validate :valid_commit_sha, unless: :importing? validate :valid_commit_sha, unless: :importing?
after_create :keep_around_commits, unless: :importing? after_create :keep_around_commits, unless: :importing?
...@@ -153,10 +155,6 @@ module Ci ...@@ -153,10 +155,6 @@ module Ci
builds.latest.with_artifacts_not_expired.includes(project: [:namespace]) builds.latest.with_artifacts_not_expired.includes(project: [:namespace])
end end
def project_id
project.id
end
# For now the only user who participates is the user who triggered # For now the only user who participates is the user who triggered
def participants(_current_user = nil) def participants(_current_user = nil)
Array(user) Array(user)
......
...@@ -4,8 +4,8 @@ module Ci ...@@ -4,8 +4,8 @@ module Ci
RUNNER_QUEUE_EXPIRY_TIME = 60.minutes RUNNER_QUEUE_EXPIRY_TIME = 60.minutes
LAST_CONTACT_TIME = 1.hour.ago LAST_CONTACT_TIME = 1.hour.ago
AVAILABLE_SCOPES = %w[specific shared active paused online] AVAILABLE_SCOPES = %w[specific shared active paused online].freeze
FORM_EDITABLE = %i[description tag_list active run_untagged locked] FORM_EDITABLE = %i[description tag_list active run_untagged locked].freeze
has_many :builds has_many :builds
has_many :runner_projects, dependent: :destroy has_many :runner_projects, dependent: :destroy
......
...@@ -5,6 +5,6 @@ module Ci ...@@ -5,6 +5,6 @@ module Ci
belongs_to :runner belongs_to :runner
belongs_to :project, foreign_key: :gl_project_id belongs_to :project, foreign_key: :gl_project_id
validates_uniqueness_of :runner_id, scope: :gl_project_id validates :runner_id, uniqueness: { scope: :gl_project_id }
end end
end end
...@@ -7,8 +7,8 @@ module Ci ...@@ -7,8 +7,8 @@ module Ci
belongs_to :project, foreign_key: :gl_project_id belongs_to :project, foreign_key: :gl_project_id
has_many :trigger_requests, dependent: :destroy has_many :trigger_requests, dependent: :destroy
validates_presence_of :token validates :token, presence: true
validates_uniqueness_of :token validates :token, uniqueness: true
before_validation :set_default_values before_validation :set_default_values
......
...@@ -22,12 +22,12 @@ class Commit ...@@ -22,12 +22,12 @@ class Commit
DIFF_HARD_LIMIT_LINES = 50000 DIFF_HARD_LIMIT_LINES = 50000
# The SHA can be between 7 and 40 hex characters. # The SHA can be between 7 and 40 hex characters.
COMMIT_SHA_PATTERN = '\h{7,40}' COMMIT_SHA_PATTERN = '\h{7,40}'.freeze
class << self class << self
def decorate(commits, project) def decorate(commits, project)
commits.map do |commit| commits.map do |commit|
if commit.kind_of?(Commit) if commit.is_a?(Commit)
commit commit
else else
self.new(commit, project) self.new(commit, project)
...@@ -105,7 +105,7 @@ class Commit ...@@ -105,7 +105,7 @@ class Commit
end end
def diff_line_count def diff_line_count
@diff_line_count ||= Commit::diff_line_count(raw_diffs) @diff_line_count ||= Commit.diff_line_count(raw_diffs)
@diff_line_count @diff_line_count
end end
...@@ -122,11 +122,12 @@ class Commit ...@@ -122,11 +122,12 @@ class Commit
def full_title def full_title
return @full_title if @full_title return @full_title if @full_title
if safe_message.blank? @full_title =
@full_title = no_commit_message if safe_message.blank?
else no_commit_message
@full_title = safe_message.split("\n", 2).first else
end safe_message.split("\n", 2).first
end
end end
# Returns the commits description # Returns the commits description
......
...@@ -10,10 +10,11 @@ class CommitStatus < ActiveRecord::Base ...@@ -10,10 +10,11 @@ class CommitStatus < ActiveRecord::Base
belongs_to :user belongs_to :user
delegate :commit, to: :pipeline delegate :commit, to: :pipeline
delegate :sha, :short_sha, to: :pipeline
validates :pipeline, presence: true, unless: :importing? validates :pipeline, presence: true, unless: :importing?
validates_presence_of :name validates :name, presence: true
alias_attribute :author, :user alias_attribute :author, :user
...@@ -102,8 +103,6 @@ class CommitStatus < ActiveRecord::Base ...@@ -102,8 +103,6 @@ class CommitStatus < ActiveRecord::Base
end end
end end
delegate :sha, :short_sha, to: :pipeline
def before_sha def before_sha
pipeline.before_sha || Gitlab::Git::BLANK_SHA pipeline.before_sha || Gitlab::Git::BLANK_SHA
end end
......
...@@ -11,14 +11,15 @@ module CacheMarkdownField ...@@ -11,14 +11,15 @@ module CacheMarkdownField
# Knows about the relationship between markdown and html field names, and # Knows about the relationship between markdown and html field names, and
# stores the rendering contexts for the latter # stores the rendering contexts for the latter
class FieldData class FieldData
extend Forwardable
def initialize def initialize
@data = {} @data = {}
end end
def_delegators :@data, :[], :[]= delegate :[], :[]=, to: :@data
def_delegator :@data, :keys, :markdown_fields
def markdown_fields
@data.keys
end
def html_field(markdown_field) def html_field(markdown_field)
"#{markdown_field}_html" "#{markdown_field}_html"
...@@ -45,7 +46,7 @@ module CacheMarkdownField ...@@ -45,7 +46,7 @@ module CacheMarkdownField
Project Project
Release Release
Snippet Snippet
] ].freeze
def self.caching_classes def self.caching_classes
CACHING_CLASSES.map(&:constantize) CACHING_CLASSES.map(&:constantize)
......
...@@ -13,11 +13,12 @@ module CaseSensitivity ...@@ -13,11 +13,12 @@ module CaseSensitivity
params.each do |key, value| params.each do |key, value|
column = ActiveRecord::Base.connection.quote_table_name(key) column = ActiveRecord::Base.connection.quote_table_name(key)
if cast_lower condition =
condition = "LOWER(#{column}) = LOWER(:value)" if cast_lower
else "LOWER(#{column}) = LOWER(:value)"
condition = "#{column} = :value" else
end "#{column} = :value"
end
criteria = criteria.where(condition, value: value) criteria = criteria.where(condition, value: value)
end end
......
module HasStatus module HasStatus
extend ActiveSupport::Concern extend ActiveSupport::Concern
DEFAULT_STATUS = 'created' DEFAULT_STATUS = 'created'.freeze
AVAILABLE_STATUSES = %w[created pending running success failed canceled skipped] AVAILABLE_STATUSES = %w[created pending running success failed canceled skipped].freeze
STARTED_STATUSES = %w[running success failed skipped] STARTED_STATUSES = %w[running success failed skipped].freeze
ACTIVE_STATUSES = %w[pending running] ACTIVE_STATUSES = %w[pending running].freeze
COMPLETED_STATUSES = %w[success failed canceled skipped] COMPLETED_STATUSES = %w[success failed canceled skipped].freeze
ORDERED_STATUSES = %w[failed pending running canceled success skipped] ORDERED_STATUSES = %w[failed pending running canceled success skipped].freeze
class_methods do class_methods do
def status_sql def status_sql
......
...@@ -46,6 +46,17 @@ module Issuable ...@@ -46,6 +46,17 @@ module Issuable
has_one :metrics has_one :metrics
delegate :name,
:email,
to: :author,
prefix: true
delegate :name,
:email,
to: :assignee,
allow_nil: true,
prefix: true
validates :author, presence: true validates :author, presence: true
validates :title, presence: true, length: { maximum: 255 } validates :title, presence: true, length: { maximum: 255 }
...@@ -68,21 +79,10 @@ module Issuable ...@@ -68,21 +79,10 @@ module Issuable
scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) } scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) }
scope :join_project, -> { joins(:project) } scope :join_project, -> { joins(:project) }
scope :inc_notes_with_associations, -> { includes(notes: [ :project, :author, :award_emoji ]) } scope :inc_notes_with_associations, -> { includes(notes: [:project, :author, :award_emoji]) }
scope :references_project, -> { references(:project) } scope :references_project, -> { references(:project) }
scope :non_archived, -> { join_project.where(projects: { archived: false }) } scope :non_archived, -> { join_project.where(projects: { archived: false }) }
delegate :name,
:email,
to: :author,
prefix: true
delegate :name,
:email,
to: :assignee,
allow_nil: true,
prefix: true
attr_mentionable :title, pipeline: :single_line attr_mentionable :title, pipeline: :single_line
attr_mentionable :description attr_mentionable :description
...@@ -182,7 +182,7 @@ module Issuable ...@@ -182,7 +182,7 @@ module Issuable
def grouping_columns(sort) def grouping_columns(sort)
grouping_columns = [arel_table[:id]] grouping_columns = [arel_table[:id]]
if ["milestone_due_desc", "milestone_due_asc"].include?(sort) if %w(milestone_due_desc milestone_due_asc).include?(sort)
milestone_table = Milestone.arel_table milestone_table = Milestone.arel_table
grouping_columns << milestone_table[:id] grouping_columns << milestone_table[:id]
grouping_columns << milestone_table[:due_date] grouping_columns << milestone_table[:due_date]
...@@ -235,7 +235,7 @@ module Issuable ...@@ -235,7 +235,7 @@ module Issuable
# DEPRECATED # DEPRECATED
repository: project.hook_attrs.slice(:name, :url, :description, :homepage) repository: project.hook_attrs.slice(:name, :url, :description, :homepage)
} }
hook_data.merge!(assignee: assignee.hook_attrs) if assignee hook_data[:assignee] = assignee.hook_attrs if assignee
hook_data hook_data
end end
......
...@@ -5,6 +5,6 @@ module ReactiveService ...@@ -5,6 +5,6 @@ module ReactiveService
include ReactiveCaching include ReactiveCaching
# Default cache key: class name + project_id # Default cache key: class name + project_id
self.reactive_cache_key = ->(service) { [ service.class.model_name.singular, service.project_id ] } self.reactive_cache_key = ->(service) { [service.class.model_name.singular, service.project_id] }
end end
end end
...@@ -46,11 +46,12 @@ module Sortable ...@@ -46,11 +46,12 @@ module Sortable
where("label_links.target_id = #{target_column}"). where("label_links.target_id = #{target_column}").
reorder(nil) reorder(nil)
if target_type_column query =
query = query.where("label_links.target_type = #{target_type_column}") if target_type_column
else query.where("label_links.target_type = #{target_type_column}")
query = query.where(label_links: { target_type: target_type }) else
end query.where(label_links: { target_type: target_type })
end
query = query.where.not(title: excluded_labels) if excluded_labels.present? query = query.where.not(title: excluded_labels) if excluded_labels.present?
......
...@@ -8,7 +8,7 @@ class DiffNote < Note ...@@ -8,7 +8,7 @@ class DiffNote < Note
validates :position, presence: true validates :position, presence: true
validates :diff_line, presence: true validates :diff_line, presence: true
validates :line_code, presence: true, line_code: true validates :line_code, presence: true, line_code: true
validates :noteable_type, inclusion: { in: ['Commit', 'MergeRequest'] } validates :noteable_type, inclusion: { in: %w(Commit MergeRequest) }
validates :resolved_by, presence: true, if: :resolved? validates :resolved_by, presence: true, if: :resolved?
validate :positions_complete validate :positions_complete
validate :verify_supported validate :verify_supported
......
...@@ -47,7 +47,7 @@ class Event < ActiveRecord::Base ...@@ -47,7 +47,7 @@ class Event < ActiveRecord::Base
def contributions def contributions
where("action = ? OR (target_type IN (?) AND action IN (?)) OR (target_type = ? AND action = ?)", where("action = ? OR (target_type IN (?) AND action IN (?)) OR (target_type = ? AND action = ?)",
Event::PUSHED, Event::PUSHED,
["MergeRequest", "Issue"], [Event::CREATED, Event::CLOSED, Event::MERGED], %w(MergeRequest Issue), [Event::CREATED, Event::CLOSED, Event::MERGED],
"Note", Event::COMMENTED) "Note", Event::COMMENTED)
end end
......
...@@ -43,7 +43,7 @@ class ExternalIssue ...@@ -43,7 +43,7 @@ class ExternalIssue
end end
def reference_link_text(from_project = nil) def reference_link_text(from_project = nil)
return "##{id}" if /^\d+$/.match(id) return "##{id}" if id =~ /^\d+$/
id id
end end
......
...@@ -11,7 +11,7 @@ class Label < ActiveRecord::Base ...@@ -11,7 +11,7 @@ class Label < ActiveRecord::Base
cache_markdown_field :description, pipeline: :single_line cache_markdown_field :description, pipeline: :single_line
DEFAULT_COLOR = '#428BCA' DEFAULT_COLOR = '#428BCA'.freeze
default_value_for :color, DEFAULT_COLOR default_value_for :color, DEFAULT_COLOR
......
...@@ -10,6 +10,8 @@ class Member < ActiveRecord::Base ...@@ -10,6 +10,8 @@ class Member < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :source, polymorphic: true belongs_to :source, polymorphic: true
delegate :name, :username, :email, to: :user, prefix: true
validates :user, presence: true, unless: :invite? validates :user, presence: true, unless: :invite?
validates :source, presence: true validates :source, presence: true
validates :user_id, uniqueness: { scope: [:source_type, :source_id], validates :user_id, uniqueness: { scope: [:source_type, :source_id],
...@@ -73,8 +75,6 @@ class Member < ActiveRecord::Base ...@@ -73,8 +75,6 @@ class Member < ActiveRecord::Base
after_destroy :post_destroy_hook, unless: :pending? after_destroy :post_destroy_hook, unless: :pending?
after_commit :refresh_member_authorized_projects after_commit :refresh_member_authorized_projects
delegate :name, :username, :email, to: :user, prefix: true
default_value_for :notification_level, NotificationSetting.levels[:global] default_value_for :notification_level, NotificationSetting.levels[:global]
class << self class << self
......
class GroupMember < Member class GroupMember < Member
SOURCE_TYPE = 'Namespace' SOURCE_TYPE = 'Namespace'.freeze
belongs_to :group, foreign_key: 'source_id' belongs_to :group, foreign_key: 'source_id'
# Make sure group member points only to group as it source # Make sure group member points only to group as it source
default_value_for :source_type, SOURCE_TYPE default_value_for :source_type, SOURCE_TYPE
validates_format_of :source_type, with: /\ANamespace\z/ validates :source_type, format: { with: /\ANamespace\z/ }
default_scope { where(source_type: SOURCE_TYPE) } default_scope { where(source_type: SOURCE_TYPE) }
def self.access_level_roles def self.access_level_roles
......
class ProjectMember < Member class ProjectMember < Member
SOURCE_TYPE = 'Project' SOURCE_TYPE = 'Project'.freeze
include Gitlab::ShellAdapter include Gitlab::ShellAdapter
...@@ -7,7 +7,7 @@ class ProjectMember < Member ...@@ -7,7 +7,7 @@ class ProjectMember < Member
# Make sure project member points only to project as it source # Make sure project member points only to project as it source
default_value_for :source_type, SOURCE_TYPE default_value_for :source_type, SOURCE_TYPE
validates_format_of :source_type, with: /\AProject\z/ validates :source_type, format: { with: /\AProject\z/ }
validates :access_level, inclusion: { in: Gitlab::Access.values } validates :access_level, inclusion: { in: Gitlab::Access.values }
default_scope { where(source_type: SOURCE_TYPE) } default_scope { where(source_type: SOURCE_TYPE) }
......
...@@ -531,7 +531,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -531,7 +531,7 @@ class MergeRequest < ActiveRecord::Base
} }
if diff_head_commit if diff_head_commit
attrs.merge!(last_commit: diff_head_commit.hook_attrs) attrs[:last_commit] = diff_head_commit.hook_attrs
end end
attributes.merge!(attrs) attributes.merge!(attrs)
......
...@@ -7,7 +7,7 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -7,7 +7,7 @@ class MergeRequestDiff < ActiveRecord::Base
COMMITS_SAFE_SIZE = 100 COMMITS_SAFE_SIZE = 100
# Valid types of serialized diffs allowed by Gitlab::Git::Diff # Valid types of serialized diffs allowed by Gitlab::Git::Diff
VALID_CLASSES = [Hash, Rugged::Patch, Rugged::Diff::Delta] VALID_CLASSES = [Hash, Rugged::Patch, Rugged::Diff::Delta].freeze
belongs_to :merge_request belongs_to :merge_request
......
...@@ -188,11 +188,12 @@ module Network ...@@ -188,11 +188,12 @@ module Network
end end
# and mark it as reserved # and mark it as reserved
if parent_time.nil? min_time =
min_time = leaves.first.time if parent_time.nil?
else leaves.first.time
min_time = parent_time + 1 else
end parent_time + 1
end
max_time = leaves.last.time max_time = leaves.last.time
leaves.last.parents(@map).each do |parent| leaves.last.parents(@map).each do |parent|
......
...@@ -72,7 +72,7 @@ class Note < ActiveRecord::Base ...@@ -72,7 +72,7 @@ class Note < ActiveRecord::Base
scope :inc_author, ->{ includes(:author) } scope :inc_author, ->{ includes(:author) }
scope :inc_relations_for_view, ->{ includes(:project, :author, :updated_by, :resolved_by, :award_emoji) } scope :inc_relations_for_view, ->{ includes(:project, :author, :updated_by, :resolved_by, :award_emoji) }
scope :diff_notes, ->{ where(type: ['LegacyDiffNote', 'DiffNote']) } scope :diff_notes, ->{ where(type: %w(LegacyDiffNote DiffNote)) }
scope :non_diff_notes, ->{ where(type: ['Note', nil]) } scope :non_diff_notes, ->{ where(type: ['Note', nil]) }
scope :with_associations, -> do scope :with_associations, -> do
......
...@@ -35,11 +35,11 @@ class NotificationSetting < ActiveRecord::Base ...@@ -35,11 +35,11 @@ class NotificationSetting < ActiveRecord::Base
:merge_merge_request, :merge_merge_request,
:failed_pipeline, :failed_pipeline,
:success_pipeline :success_pipeline
] ].freeze
EXCLUDED_WATCHER_EVENTS = [ EXCLUDED_WATCHER_EVENTS = [
:success_pipeline :success_pipeline
] ].freeze
store :events, accessors: EMAIL_EVENTS, coder: JSON store :events, accessors: EMAIL_EVENTS, coder: JSON
......
...@@ -2,7 +2,7 @@ class PagesDomain < ActiveRecord::Base ...@@ -2,7 +2,7 @@ class PagesDomain < ActiveRecord::Base
belongs_to :project belongs_to :project
validates :domain, hostname: true validates :domain, hostname: true
validates_uniqueness_of :domain, case_sensitive: false validates :domain, uniqueness: { case_sensitive: false }
validates :certificate, certificate: true, allow_nil: true, allow_blank: true validates :certificate, certificate: true, allow_nil: true, allow_blank: true
validates :key, certificate_key: true, allow_nil: true, allow_blank: true validates :key, certificate_key: true, allow_nil: true, allow_blank: true
......
...@@ -22,7 +22,7 @@ class Project < ActiveRecord::Base ...@@ -22,7 +22,7 @@ class Project < ActiveRecord::Base
class BoardLimitExceeded < StandardError; end class BoardLimitExceeded < StandardError; end
NUMBER_OF_PERMITTED_BOARDS = 1 NUMBER_OF_PERMITTED_BOARDS = 1
UNKNOWN_IMPORT_URL = 'http://unknown.git' UNKNOWN_IMPORT_URL = 'http://unknown.git'.freeze
cache_markdown_field :description, pipeline: :description cache_markdown_field :description, pipeline: :description
...@@ -172,9 +172,11 @@ class Project < ActiveRecord::Base ...@@ -172,9 +172,11 @@ class Project < ActiveRecord::Base
accepts_nested_attributes_for :project_feature accepts_nested_attributes_for :project_feature
delegate :name, to: :owner, allow_nil: true, prefix: true delegate :name, to: :owner, allow_nil: true, prefix: true
delegate :count, to: :forks, prefix: true
delegate :members, to: :team, prefix: true delegate :members, to: :team, prefix: true
delegate :add_user, to: :team delegate :add_user, to: :team
delegate :add_guest, :add_reporter, :add_developer, :add_master, to: :team delegate :add_guest, :add_reporter, :add_developer, :add_master, to: :team
delegate :empty_repo?, to: :repository
# Validations # Validations
validates :creator, presence: true, on: :create validates :creator, presence: true, on: :create
...@@ -191,8 +193,8 @@ class Project < ActiveRecord::Base ...@@ -191,8 +193,8 @@ class Project < ActiveRecord::Base
format: { with: Gitlab::Regex.project_path_regex, format: { with: Gitlab::Regex.project_path_regex,
message: Gitlab::Regex.project_path_regex_message } message: Gitlab::Regex.project_path_regex_message }
validates :namespace, presence: true validates :namespace, presence: true
validates_uniqueness_of :name, scope: :namespace_id validates :name, uniqueness: { scope: :namespace_id }
validates_uniqueness_of :path, scope: :namespace_id validates :path, uniqueness: { scope: :namespace_id }
validates :import_url, addressable_url: true, if: :external_import? validates :import_url, addressable_url: true, if: :external_import?
validates :star_count, numericality: { greater_than_or_equal_to: 0 } validates :star_count, numericality: { greater_than_or_equal_to: 0 }
validate :check_limit, on: :create validate :check_limit, on: :create
...@@ -453,13 +455,14 @@ class Project < ActiveRecord::Base ...@@ -453,13 +455,14 @@ class Project < ActiveRecord::Base
end end
def add_import_job def add_import_job
if forked? job_id =
job_id = RepositoryForkWorker.perform_async(id, forked_from_project.repository_storage_path, if forked?
forked_from_project.path_with_namespace, RepositoryForkWorker.perform_async(id, forked_from_project.repository_storage_path,
self.namespace.full_path) forked_from_project.path_with_namespace,
else self.namespace.full_path)
job_id = RepositoryImportWorker.perform_async(self.id) else
end RepositoryImportWorker.perform_async(self.id)
end
if job_id if job_id
Rails.logger.info "Import job started for #{path_with_namespace} with job ID #{job_id}" Rails.logger.info "Import job started for #{path_with_namespace} with job ID #{job_id}"
...@@ -837,10 +840,6 @@ class Project < ActiveRecord::Base ...@@ -837,10 +840,6 @@ class Project < ActiveRecord::Base
false false
end end
def empty_repo?
repository.empty_repo?
end
def repo def repo
repository.raw repository.raw
end end
...@@ -1028,10 +1027,6 @@ class Project < ActiveRecord::Base ...@@ -1028,10 +1027,6 @@ class Project < ActiveRecord::Base
forked? && project == forked_from_project forked? && project == forked_from_project
end end
def forks_count
forks.count
end
def origin_merge_requests def origin_merge_requests
merge_requests.where(source_project_id: self.id) merge_requests.where(source_project_id: self.id)
end end
......
...@@ -18,7 +18,7 @@ class ProjectFeature < ActiveRecord::Base ...@@ -18,7 +18,7 @@ class ProjectFeature < ActiveRecord::Base
PRIVATE = 10 PRIVATE = 10
ENABLED = 20 ENABLED = 20
FEATURES = %i(issues merge_requests wiki snippets builds repository) FEATURES = %i(issues merge_requests wiki snippets builds repository).freeze
class << self class << self
def access_level_attribute(feature) def access_level_attribute(feature)
......
...@@ -3,7 +3,7 @@ require "addressable/uri" ...@@ -3,7 +3,7 @@ require "addressable/uri"
class BuildkiteService < CiService class BuildkiteService < CiService
include ReactiveService include ReactiveService
ENDPOINT = "https://buildkite.com" ENDPOINT = "https://buildkite.com".freeze
prop_accessor :project_url, :token prop_accessor :project_url, :token
boolean_accessor :enable_ssl_verification boolean_accessor :enable_ssl_verification
......
...@@ -51,7 +51,8 @@ module ChatMessage ...@@ -51,7 +51,8 @@ module ChatMessage
title: issue_title, title: issue_title,
title_link: issue_url, title_link: issue_url,
text: format(description), text: format(description),
color: "#C95823" }] color: "#C95823"
}]
end end
def project_link def project_link
......
...@@ -39,7 +39,7 @@ class DroneCiService < CiService ...@@ -39,7 +39,7 @@ class DroneCiService < CiService
def commit_status_path(sha, ref) def commit_status_path(sha, ref)
url = [drone_url, url = [drone_url,
"gitlab/#{project.full_path}/commits/#{sha}", "gitlab/#{project.full_path}/commits/#{sha}",
"?branch=#{URI::encode(ref.to_s)}&access_token=#{token}"] "?branch=#{URI.encode(ref.to_s)}&access_token=#{token}"]
URI.join(*url).to_s URI.join(*url).to_s
end end
...@@ -74,7 +74,7 @@ class DroneCiService < CiService ...@@ -74,7 +74,7 @@ class DroneCiService < CiService
def build_page(sha, ref) def build_page(sha, ref)
url = [drone_url, url = [drone_url,
"gitlab/#{project.full_path}/redirect/commits/#{sha}", "gitlab/#{project.full_path}/redirect/commits/#{sha}",
"?branch=#{URI::encode(ref.to_s)}"] "?branch=#{URI.encode(ref.to_s)}"]
URI.join(*url).to_s URI.join(*url).to_s
end end
...@@ -114,7 +114,7 @@ class DroneCiService < CiService ...@@ -114,7 +114,7 @@ class DroneCiService < CiService
end end
def merge_request_valid?(data) def merge_request_valid?(data)
['opened', 'reopened'].include?(data[:object_attributes][:state]) && %w(opened reopened).include?(data[:object_attributes][:state]) &&
data[:object_attributes][:merge_status] == 'unchecked' data[:object_attributes][:merge_status] == 'unchecked'
end end
end end
...@@ -6,7 +6,7 @@ class HipchatService < Service ...@@ -6,7 +6,7 @@ class HipchatService < Service
a b i strong em br img pre code a b i strong em br img pre code
table th tr td caption colgroup col thead tbody tfoot table th tr td caption colgroup col thead tbody tfoot
ul ol li dl dt dd ul ol li dl dt dd
] ].freeze
prop_accessor :token, :room, :server, :color, :api_version prop_accessor :token, :room, :server, :color, :api_version
boolean_accessor :notify_only_broken_builds, :notify boolean_accessor :notify_only_broken_builds, :notify
...@@ -36,7 +36,7 @@ class HipchatService < Service ...@@ -36,7 +36,7 @@ class HipchatService < Service
{ type: 'text', name: 'token', placeholder: 'Room token' }, { type: 'text', name: 'token', placeholder: 'Room token' },
{ type: 'text', name: 'room', placeholder: 'Room name or ID' }, { type: 'text', name: 'room', placeholder: 'Room name or ID' },
{ type: 'checkbox', name: 'notify' }, { type: 'checkbox', name: 'notify' },
{ type: 'select', name: 'color', choices: ['yellow', 'red', 'green', 'purple', 'gray', 'random'] }, { type: 'select', name: 'color', choices: %w(yellow red green purple gray random) },
{ type: 'text', name: 'api_version', { type: 'text', name: 'api_version',
placeholder: 'Leave blank for default (v2)' }, placeholder: 'Leave blank for default (v2)' },
{ type: 'text', name: 'server', { type: 'text', name: 'server',
......
...@@ -33,7 +33,8 @@ class IrkerService < Service ...@@ -33,7 +33,8 @@ class IrkerService < Service
end end
def settings def settings
{ server_host: server_host.present? ? server_host : 'localhost', {
server_host: server_host.present? ? server_host : 'localhost',
server_port: server_port.present? ? server_port : 6659 server_port: server_port.present? ? server_port : 6659
} }
end end
......
...@@ -3,7 +3,7 @@ class KubernetesService < DeploymentService ...@@ -3,7 +3,7 @@ class KubernetesService < DeploymentService
include Gitlab::Kubernetes include Gitlab::Kubernetes
include ReactiveCaching include ReactiveCaching
self.reactive_cache_key = ->(service) { [ service.class.model_name.singular, service.project_id ] } self.reactive_cache_key = ->(service) { [service.class.model_name.singular, service.project_id] }
# Namespace defaults to the project path, but can be overridden in case that # Namespace defaults to the project path, but can be overridden in case that
# is an invalid or inappropriate name # is an invalid or inappropriate name
...@@ -62,23 +62,19 @@ class KubernetesService < DeploymentService ...@@ -62,23 +62,19 @@ class KubernetesService < DeploymentService
{ type: 'text', { type: 'text',
name: 'namespace', name: 'namespace',
title: 'Kubernetes namespace', title: 'Kubernetes namespace',
placeholder: 'Kubernetes namespace', placeholder: 'Kubernetes namespace' },
},
{ type: 'text', { type: 'text',
name: 'api_url', name: 'api_url',
title: 'API URL', title: 'API URL',
placeholder: 'Kubernetes API URL, like https://kube.example.com/', placeholder: 'Kubernetes API URL, like https://kube.example.com/' },
},
{ type: 'text', { type: 'text',
name: 'token', name: 'token',
title: 'Service token', title: 'Service token',
placeholder: 'Service token', placeholder: 'Service token' },
},
{ type: 'textarea', { type: 'textarea',
name: 'ca_pem', name: 'ca_pem',
title: 'Custom CA bundle', title: 'Custom CA bundle',
placeholder: 'Certificate Authority bundle (PEM format)', placeholder: 'Certificate Authority bundle (PEM format)' },
},
] ]
end end
...@@ -167,7 +163,7 @@ class KubernetesService < DeploymentService ...@@ -167,7 +163,7 @@ class KubernetesService < DeploymentService
url = URI.parse(api_url) url = URI.parse(api_url)
prefix = url.path.sub(%r{/+\z}, '') prefix = url.path.sub(%r{/+\z}, '')
url.path = [ prefix, *parts ].join("/") url.path = [prefix, *parts].join("/")
url.to_s url.to_s
end end
......
class PivotaltrackerService < Service class PivotaltrackerService < Service
include HTTParty include HTTParty
API_ENDPOINT = 'https://www.pivotaltracker.com/services/v5/source_commits' API_ENDPOINT = 'https://www.pivotaltracker.com/services/v5/source_commits'.freeze
prop_accessor :token, :restrict_to_branch prop_accessor :token, :restrict_to_branch
validates :token, presence: true, if: :activated? validates :token, presence: true, if: :activated?
......
...@@ -29,25 +29,24 @@ class PushoverService < Service ...@@ -29,25 +29,24 @@ class PushoverService < Service
['Normal Priority', 0], ['Normal Priority', 0],
['High Priority', 1] ['High Priority', 1]
], ],
default_choice: 0 default_choice: 0 },
},
{ type: 'select', name: 'sound', choices: { type: 'select', name: 'sound', choices:
[ [
['Device default sound', nil], ['Device default sound', nil],
['Pushover (default)', 'pushover'], ['Pushover (default)', 'pushover'],
['Bike', 'bike'], %w(Bike bike),
['Bugle', 'bugle'], %w(Bugle bugle),
['Cash Register', 'cashregister'], ['Cash Register', 'cashregister'],
['Classical', 'classical'], %w(Classical classical),
['Cosmic', 'cosmic'], %w(Cosmic cosmic),
['Falling', 'falling'], %w(Falling falling),
['Gamelan', 'gamelan'], %w(Gamelan gamelan),
['Incoming', 'incoming'], %w(Incoming incoming),
['Intermission', 'intermission'], %w(Intermission intermission),
['Magic', 'magic'], %w(Magic magic),
['Mechanical', 'mechanical'], %w(Mechanical mechanical),
['Piano Bar', 'pianobar'], ['Piano Bar', 'pianobar'],
['Siren', 'siren'], %w(Siren siren),
['Space Alarm', 'spacealarm'], ['Space Alarm', 'spacealarm'],
['Tug Boat', 'tugboat'], ['Tug Boat', 'tugboat'],
['Alien Alarm (long)', 'alien'], ['Alien Alarm (long)', 'alien'],
...@@ -56,8 +55,7 @@ class PushoverService < Service ...@@ -56,8 +55,7 @@ class PushoverService < Service
['Pushover Echo (long)', 'echo'], ['Pushover Echo (long)', 'echo'],
['Up Down (long)', 'updown'], ['Up Down (long)', 'updown'],
['None (silent)', 'none'] ['None (silent)', 'none']
] ] },
},
] ]
end end
...@@ -72,13 +70,14 @@ class PushoverService < Service ...@@ -72,13 +70,14 @@ class PushoverService < Service
before = data[:before] before = data[:before]
after = data[:after] after = data[:after]
if Gitlab::Git.blank_ref?(before) message =
message = "#{data[:user_name]} pushed new branch \"#{ref}\"." if Gitlab::Git.blank_ref?(before)
elsif Gitlab::Git.blank_ref?(after) "#{data[:user_name]} pushed new branch \"#{ref}\"."
message = "#{data[:user_name]} deleted branch \"#{ref}\"." elsif Gitlab::Git.blank_ref?(after)
else "#{data[:user_name]} deleted branch \"#{ref}\"."
message = "#{data[:user_name]} push to branch \"#{ref}\"." else
end "#{data[:user_name]} push to branch \"#{ref}\"."
end
if data[:total_commits_count] > 0 if data[:total_commits_count] > 0
message << "\nTotal commits count: #{data[:total_commits_count]}" message << "\nTotal commits count: #{data[:total_commits_count]}"
...@@ -97,7 +96,7 @@ class PushoverService < Service ...@@ -97,7 +96,7 @@ class PushoverService < Service
# Sound parameter MUST NOT be sent to API if not selected # Sound parameter MUST NOT be sent to API if not selected
if sound if sound
pushover_data.merge!(sound: sound) pushover_data[:sound] = sound
end end
PushoverService.post('/messages.json', body: pushover_data) PushoverService.post('/messages.json', body: pushover_data)
......
...@@ -4,7 +4,7 @@ class ProjectStatistics < ActiveRecord::Base ...@@ -4,7 +4,7 @@ class ProjectStatistics < ActiveRecord::Base
before_save :update_storage_size before_save :update_storage_size
STORAGE_COLUMNS = [:repository_size, :lfs_objects_size, :build_artifacts_size] STORAGE_COLUMNS = [:repository_size, :lfs_objects_size, :build_artifacts_size].freeze
STATISTICS_COLUMNS = [:commit_count] + STORAGE_COLUMNS STATISTICS_COLUMNS = [:commit_count] + STORAGE_COLUMNS
def total_repository_size def total_repository_size
......
...@@ -5,7 +5,7 @@ class ProjectWiki ...@@ -5,7 +5,7 @@ class ProjectWiki
'Markdown' => :markdown, 'Markdown' => :markdown,
'RDoc' => :rdoc, 'RDoc' => :rdoc,
'AsciiDoc' => :asciidoc 'AsciiDoc' => :asciidoc
} unless defined?(MARKUPS) }.freeze unless defined?(MARKUPS)
class CouldNotCreateWikiError < StandardError; end class CouldNotCreateWikiError < StandardError; end
...@@ -19,6 +19,9 @@ class ProjectWiki ...@@ -19,6 +19,9 @@ class ProjectWiki
@user = user @user = user
end end
delegate :empty?, to: :pages
delegate :repository_storage_path, to: :project
def path def path
@project.path + '.wiki' @project.path + '.wiki'
end end
...@@ -60,10 +63,6 @@ class ProjectWiki ...@@ -60,10 +63,6 @@ class ProjectWiki
!!repository.exists? !!repository.exists?
end end
def empty?
pages.empty?
end
# Returns an Array of Gitlab WikiPage instances or an # Returns an Array of Gitlab WikiPage instances or an
# empty Array if this Wiki has no pages. # empty Array if this Wiki has no pages.
def pages def pages
...@@ -160,10 +159,6 @@ class ProjectWiki ...@@ -160,10 +159,6 @@ class ProjectWiki
} }
end end
def repository_storage_path
project.repository_storage_path
end
private private
def init_repo(path_with_namespace) def init_repo(path_with_namespace)
......
...@@ -8,8 +8,8 @@ class ProtectedBranch < ActiveRecord::Base ...@@ -8,8 +8,8 @@ class ProtectedBranch < ActiveRecord::Base
has_many :merge_access_levels, dependent: :destroy has_many :merge_access_levels, dependent: :destroy
has_many :push_access_levels, dependent: :destroy has_many :push_access_levels, dependent: :destroy
validates_length_of :merge_access_levels, is: 1, message: "are restricted to a single instance per protected branch." validates :merge_access_levels, length: { is: 1, message: "are restricted to a single instance per protected branch." }
validates_length_of :push_access_levels, is: 1, message: "are restricted to a single instance per protected branch." validates :push_access_levels, length: { is: 1, message: "are restricted to a single instance per protected branch." }
accepts_nested_attributes_for :push_access_levels accepts_nested_attributes_for :push_access_levels
accepts_nested_attributes_for :merge_access_levels accepts_nested_attributes_for :merge_access_levels
......
...@@ -18,7 +18,7 @@ class Repository ...@@ -18,7 +18,7 @@ class Repository
CACHED_METHODS = %i(size commit_count readme version contribution_guide CACHED_METHODS = %i(size commit_count readme version contribution_guide
changelog license_blob license_key gitignore koding_yml changelog license_blob license_key gitignore koding_yml
gitlab_ci_yml branch_names tag_names branch_count gitlab_ci_yml branch_names tag_names branch_count
tag_count avatar exists? empty? root_ref) tag_count avatar exists? empty? root_ref).freeze
# Certain method caches should be refreshed when certain types of files are # Certain method caches should be refreshed when certain types of files are
# changed. This Hash maps file types (as returned by Gitlab::FileDetector) to # changed. This Hash maps file types (as returned by Gitlab::FileDetector) to
...@@ -33,7 +33,7 @@ class Repository ...@@ -33,7 +33,7 @@ class Repository
koding: :koding_yml, koding: :koding_yml,
gitlab_ci: :gitlab_ci_yml, gitlab_ci: :gitlab_ci_yml,
avatar: :avatar avatar: :avatar
} }.freeze
# Wraps around the given method and caches its output in Redis and an instance # Wraps around the given method and caches its output in Redis and an instance
# variable. # variable.
...@@ -487,9 +487,7 @@ class Repository ...@@ -487,9 +487,7 @@ class Repository
end end
cache_method :exists? cache_method :exists?
def empty? delegate :empty?, to: :raw_repository
raw_repository.empty?
end
cache_method :empty? cache_method :empty?
# The size of this repository in megabytes. # The size of this repository in megabytes.
...@@ -508,9 +506,7 @@ class Repository ...@@ -508,9 +506,7 @@ class Repository
end end
cache_method :branch_names, fallback: [] cache_method :branch_names, fallback: []
def tag_names delegate :tag_names, to: :raw_repository
raw_repository.tag_names
end
cache_method :tag_names, fallback: [] cache_method :tag_names, fallback: []
def branch_count def branch_count
...@@ -892,7 +888,7 @@ class Repository ...@@ -892,7 +888,7 @@ class Repository
def get_committer_and_author(user, email: nil, name: nil) def get_committer_and_author(user, email: nil, name: nil)
committer = user_to_committer(user) committer = user_to_committer(user)
author = Gitlab::Git::committer_hash(email: email, name: name) || committer author = Gitlab::Git.committer_hash(email: email, name: name) || committer
{ {
author: author, author: author,
......
...@@ -17,7 +17,7 @@ class Todo < ActiveRecord::Base ...@@ -17,7 +17,7 @@ class Todo < ActiveRecord::Base
APPROVAL_REQUIRED => :approval_required, APPROVAL_REQUIRED => :approval_required,
UNMERGEABLE => :unmergeable, UNMERGEABLE => :unmergeable,
DIRECTLY_ADDRESSED => :directly_addressed DIRECTLY_ADDRESSED => :directly_addressed
} }.freeze
belongs_to :author, class_name: "User" belongs_to :author, class_name: "User"
belongs_to :note belongs_to :note
......
...@@ -104,7 +104,7 @@ class User < ActiveRecord::Base ...@@ -104,7 +104,7 @@ class User < ActiveRecord::Base
# #
# Note: devise :validatable above adds validations for :email and :password # Note: devise :validatable above adds validations for :email and :password
validates :name, presence: true validates :name, presence: true
validates_confirmation_of :email validates :email, confirmation: true
validates :notification_email, presence: true validates :notification_email, presence: true
validates :notification_email, email: true, if: ->(user) { user.notification_email != user.email } validates :notification_email, email: true, if: ->(user) { user.notification_email != user.email }
validates :public_email, presence: true, uniqueness: true, email: true, allow_blank: true validates :public_email, presence: true, uniqueness: true, email: true, allow_blank: true
...@@ -580,8 +580,8 @@ class User < ActiveRecord::Base ...@@ -580,8 +580,8 @@ class User < ActiveRecord::Base
if project.repository.branch_exists?(event.branch_name) if project.repository.branch_exists?(event.branch_name)
merge_requests = MergeRequest.where("created_at >= ?", event.created_at). merge_requests = MergeRequest.where("created_at >= ?", event.created_at).
where(source_project_id: project.id, where(source_project_id: project.id,
source_branch: event.branch_name) source_branch: event.branch_name)
merge_requests.empty? merge_requests.empty?
end end
end end
......
...@@ -6,9 +6,7 @@ class BasePolicy ...@@ -6,9 +6,7 @@ class BasePolicy
@cannot_set = cannot_set @cannot_set = cannot_set
end end
def size delegate :size, to: :to_set
to_set.size
end
def self.empty def self.empty
new(Set.new, Set.new) new(Set.new, Set.new)
......
...@@ -2,7 +2,7 @@ module Auth ...@@ -2,7 +2,7 @@ module Auth
class ContainerRegistryAuthenticationService < BaseService class ContainerRegistryAuthenticationService < BaseService
include Gitlab::CurrentSettings include Gitlab::CurrentSettings
AUDIENCE = 'container_registry' AUDIENCE = 'container_registry'.freeze
def execute(authentication_abilities:) def execute(authentication_abilities:)
@authentication_abilities = authentication_abilities @authentication_abilities = authentication_abilities
......
...@@ -28,9 +28,7 @@ class BaseService ...@@ -28,9 +28,7 @@ class BaseService
SystemHooksService.new SystemHooksService.new
end end
def repository delegate :repository, to: :project
project.repository
end
# Add an error to the specified model for restricted visibility levels # Add an error to the specified model for restricted visibility levels
def deny_visibility_level(model, denied_visibility_level = nil) def deny_visibility_level(model, denied_visibility_level = nil)
......
...@@ -10,9 +10,7 @@ module Ci ...@@ -10,9 +10,7 @@ module Ci
end end
end end
def project delegate :project, to: :pipeline
pipeline.project
end
private private
......
...@@ -4,7 +4,7 @@ module Members ...@@ -4,7 +4,7 @@ module Members
attr_accessor :source attr_accessor :source
ALLOWED_SCOPES = %i[members requesters all] ALLOWED_SCOPES = %i[members requesters all].freeze
def initialize(source, current_user, params = {}) def initialize(source, current_user, params = {})
@source = source @source = source
......
...@@ -3,7 +3,7 @@ module Notes ...@@ -3,7 +3,7 @@ module Notes
UPDATE_SERVICES = { UPDATE_SERVICES = {
'Issue' => Issues::UpdateService, 'Issue' => Issues::UpdateService,
'MergeRequest' => MergeRequests::UpdateService 'MergeRequest' => MergeRequests::UpdateService
} }.freeze
def self.noteable_update_service(note) def self.noteable_update_service(note)
UPDATE_SERVICES[note.noteable_type] UPDATE_SERVICES[note.noteable_type]
......
...@@ -4,7 +4,7 @@ module Projects ...@@ -4,7 +4,7 @@ module Projects
class DestroyError < StandardError; end class DestroyError < StandardError; end
DELETED_FLAG = '+deleted' DELETED_FLAG = '+deleted'.freeze
def async_execute def async_execute
project.transaction do project.transaction do
......
...@@ -2,7 +2,7 @@ module Projects ...@@ -2,7 +2,7 @@ module Projects
class DownloadService < BaseService class DownloadService < BaseService
WHITELIST = [ WHITELIST = [
/^[^.]+\.fogbugz.com$/ /^[^.]+\.fogbugz.com$/
] ].freeze
def initialize(project, url) def initialize(project, url)
@project, @url = project, url @project, @url = project, url
...@@ -25,7 +25,7 @@ module Projects ...@@ -25,7 +25,7 @@ module Projects
end end
def http?(url) def http?(url)
url =~ /\A#{URI::regexp(['http', 'https'])}\z/ url =~ /\A#{URI.regexp(%w(http https))}\z/
end end
def valid_domain?(url) def valid_domain?(url)
......
...@@ -2,7 +2,7 @@ module Projects ...@@ -2,7 +2,7 @@ module Projects
class UpdatePagesService < BaseService class UpdatePagesService < BaseService
BLOCK_SIZE = 32.kilobytes BLOCK_SIZE = 32.kilobytes
MAX_SIZE = 1.terabyte MAX_SIZE = 1.terabyte
SITE_PATH = 'public/' SITE_PATH = 'public/'.freeze
attr_reader :build attr_reader :build
......
...@@ -15,16 +15,16 @@ module ProtectedBranches ...@@ -15,16 +15,16 @@ module ProtectedBranches
case @developers_can_push case @developers_can_push
when true when true
params.merge!(push_access_levels_attributes: [{ access_level: Gitlab::Access::DEVELOPER }]) params[:push_access_levels_attributes] = [{ access_level: Gitlab::Access::DEVELOPER }]
when false when false
params.merge!(push_access_levels_attributes: [{ access_level: Gitlab::Access::MASTER }]) params[:push_access_levels_attributes] = [{ access_level: Gitlab::Access::MASTER }]
end end
case @developers_can_merge case @developers_can_merge
when true when true
params.merge!(merge_access_levels_attributes: [{ access_level: Gitlab::Access::DEVELOPER }]) params[:merge_access_levels_attributes] = [{ access_level: Gitlab::Access::DEVELOPER }]
when false when false
params.merge!(merge_access_levels_attributes: [{ access_level: Gitlab::Access::MASTER }]) params[:merge_access_levels_attributes] = [{ access_level: Gitlab::Access::MASTER }]
end end
service = ProtectedBranches::UpdateService.new(@project, @current_user, @params) service = ProtectedBranches::UpdateService.new(@project, @current_user, @params)
......
...@@ -33,9 +33,7 @@ class SystemHooksService ...@@ -33,9 +33,7 @@ class SystemHooksService
data.merge!(project_data(model)) data.merge!(project_data(model))
if event == :rename || event == :transfer if event == :rename || event == :transfer
data.merge!({ data[:old_path_with_namespace] = model.old_path_with_namespace
old_path_with_namespace: model.old_path_with_namespace
})
end end
data data
......
...@@ -356,10 +356,10 @@ module SystemNoteService ...@@ -356,10 +356,10 @@ module SystemNoteService
note: cross_reference_note_content(gfm_reference) note: cross_reference_note_content(gfm_reference)
} }
if noteable.kind_of?(Commit) if noteable.is_a?(Commit)
note_options.merge!(noteable_type: 'Commit', commit_id: noteable.id) note_options.merge!(noteable_type: 'Commit', commit_id: noteable.id)
else else
note_options.merge!(noteable: noteable) note_options[:noteable] = noteable
end end
if noteable.is_a?(ExternalIssue) if noteable.is_a?(ExternalIssue)
...@@ -408,12 +408,13 @@ module SystemNoteService ...@@ -408,12 +408,13 @@ module SystemNoteService
# Initial scope should be system notes of this noteable type # Initial scope should be system notes of this noteable type
notes = Note.system.where(noteable_type: noteable.class) notes = Note.system.where(noteable_type: noteable.class)
if noteable.is_a?(Commit) notes =
# Commits have non-integer IDs, so they're stored in `commit_id` if noteable.is_a?(Commit)
notes = notes.where(commit_id: noteable.id) # Commits have non-integer IDs, so they're stored in `commit_id`
else notes.where(commit_id: noteable.id)
notes = notes.where(noteable_id: noteable.id) else
end notes.where(noteable_id: noteable.id)
end
notes_for_mentioner(mentioner, noteable, notes).exists? notes_for_mentioner(mentioner, noteable, notes).exists?
end end
......
# Extra methods for uploader # Extra methods for uploader
module UploaderHelper module UploaderHelper
IMAGE_EXT = %w[png jpg jpeg gif bmp tiff] IMAGE_EXT = %w[png jpg jpeg gif bmp tiff].freeze
# We recommend using the .mp4 format over .mov. Videos in .mov format can # We recommend using the .mp4 format over .mov. Videos in .mov format can
# still be used but you really need to make sure they are served with the # still be used but you really need to make sure they are served with the
# proper MIME type video/mp4 and not video/quicktime or your videos won't play # proper MIME type video/mp4 and not video/quicktime or your videos won't play
# on IE >= 9. # on IE >= 9.
# http://archive.sublimevideo.info/20150912/docs.sublimevideo.net/troubleshooting.html # http://archive.sublimevideo.info/20150912/docs.sublimevideo.net/troubleshooting.html
VIDEO_EXT = %w[mp4 m4v mov webm ogv] VIDEO_EXT = %w[mp4 m4v mov webm ogv].freeze
# These extension types can contain dangerous code and should only be embedded inline with # These extension types can contain dangerous code and should only be embedded inline with
# proper filtering. They should always be tagged as "Content-Disposition: attachment", not "inline". # proper filtering. They should always be tagged as "Content-Disposition: attachment", not "inline".
DANGEROUS_EXT = %w[svg] DANGEROUS_EXT = %w[svg].freeze
def image? def image?
extension_match?(IMAGE_EXT) extension_match?(IMAGE_EXT)
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
# end # end
# #
class AddressableUrlValidator < ActiveModel::EachValidator class AddressableUrlValidator < ActiveModel::EachValidator
DEFAULT_OPTIONS = { protocols: %w(http https ssh git) } DEFAULT_OPTIONS = { protocols: %w(http https ssh git) }.freeze
def validate_each(record, attribute, value) def validate_each(record, attribute, value)
unless valid_url?(value) unless valid_url?(value)
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
Abuse Reports Abuse Reports
%span.badge.count= number_with_delimiter(AbuseReport.count(:all)) %span.badge.count= number_with_delimiter(AbuseReport.count(:all))
- if askimet_enabled? - if akismet_enabled?
= nav_link(controller: :spam_logs) do = nav_link(controller: :spam_logs) do
= link_to admin_spam_logs_path, title: "Spam Logs" do = link_to admin_spam_logs_path, title: "Spam Logs" do
%span %span
......
...@@ -120,8 +120,8 @@ class IrkerWorker ...@@ -120,8 +120,8 @@ class IrkerWorker
end end
def compare_url(data, repo_path) def compare_url(data, repo_path)
sha1 = Commit::truncate_sha(data['before']) sha1 = Commit.truncate_sha(data['before'])
sha2 = Commit::truncate_sha(data['after']) sha2 = Commit.truncate_sha(data['after'])
compare_url = "#{Gitlab.config.gitlab.url}/#{repo_path}/compare" compare_url = "#{Gitlab.config.gitlab.url}/#{repo_path}/compare"
compare_url += "/#{sha1}...#{sha2}" compare_url += "/#{sha1}...#{sha2}"
colorize_url compare_url colorize_url compare_url
...@@ -129,7 +129,7 @@ class IrkerWorker ...@@ -129,7 +129,7 @@ class IrkerWorker
def send_one_commit(project, hook_attrs, repo_name, branch) def send_one_commit(project, hook_attrs, repo_name, branch)
commit = commit_from_id project, hook_attrs['id'] commit = commit_from_id project, hook_attrs['id']
sha = colorize_sha Commit::truncate_sha(hook_attrs['id']) sha = colorize_sha Commit.truncate_sha(hook_attrs['id'])
author = hook_attrs['author']['name'] author = hook_attrs['author']['name']
files = colorize_nb_files(files_count commit) files = colorize_nb_files(files_count commit)
title = commit.title title = commit.title
......
...@@ -14,12 +14,15 @@ class Settings < Settingslogic ...@@ -14,12 +14,15 @@ class Settings < Settingslogic
end end
def build_gitlab_ci_url def build_gitlab_ci_url
if on_standard_port?(gitlab) custom_port =
custom_port = nil if on_standard_port?(gitlab)
else nil
custom_port = ":#{gitlab.port}" else
end ":#{gitlab.port}"
[ gitlab.protocol, end
[
gitlab.protocol,
"://", "://",
gitlab.host, gitlab.host,
custom_port, custom_port,
...@@ -80,7 +83,9 @@ class Settings < Settingslogic ...@@ -80,7 +83,9 @@ class Settings < Settingslogic
def base_url(config) def base_url(config)
custom_port = on_standard_port?(config) ? nil : ":#{config.port}" custom_port = on_standard_port?(config) ? nil : ":#{config.port}"
[ config.protocol,
[
config.protocol,
"://", "://",
config.host, config.host,
custom_port custom_port
...@@ -160,15 +165,16 @@ if github_settings ...@@ -160,15 +165,16 @@ if github_settings
github_settings["args"] ||= Settingslogic.new({}) github_settings["args"] ||= Settingslogic.new({})
if github_settings["url"].include?(github_default_url) github_settings["args"]["client_options"] =
github_settings["args"]["client_options"] = OmniAuth::Strategies::GitHub.default_options[:client_options] if github_settings["url"].include?(github_default_url)
else OmniAuth::Strategies::GitHub.default_options[:client_options]
github_settings["args"]["client_options"] = { else
"site" => File.join(github_settings["url"], "api/v3"), {
"authorize_url" => File.join(github_settings["url"], "login/oauth/authorize"), "site" => File.join(github_settings["url"], "api/v3"),
"token_url" => File.join(github_settings["url"], "login/oauth/access_token") "authorize_url" => File.join(github_settings["url"], "login/oauth/authorize"),
} "token_url" => File.join(github_settings["url"], "login/oauth/access_token")
end }
end
end end
Settings['shared'] ||= Settingslogic.new({}) Settings['shared'] ||= Settingslogic.new({})
......
...@@ -24,7 +24,7 @@ Devise.setup do |config| ...@@ -24,7 +24,7 @@ Devise.setup do |config|
# session. If you need permissions, you should implement that in a before filter. # session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether # You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present. # or not authentication should be aborted when the value is not present.
config.authentication_keys = [ :login ] config.authentication_keys = [:login]
# Configure parameters from the request object used for authentication. Each entry # Configure parameters from the request object used for authentication. Each entry
# given should be a request method and it will automatically be passed to the # given should be a request method and it will automatically be passed to the
...@@ -36,12 +36,12 @@ Devise.setup do |config| ...@@ -36,12 +36,12 @@ Devise.setup do |config|
# Configure which authentication keys should be case-insensitive. # Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used # These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email. # to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [ :email ] config.case_insensitive_keys = [:email]
# Configure which authentication keys should have whitespace stripped. # Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or # These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email. # modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [ :email ] config.strip_whitespace_keys = [:email]
# Tell if authentication through request.params is enabled. True by default. # Tell if authentication through request.params is enabled. True by default.
# config.params_authenticatable = true # config.params_authenticatable = true
...@@ -124,7 +124,7 @@ Devise.setup do |config| ...@@ -124,7 +124,7 @@ Devise.setup do |config|
config.lock_strategy = :failed_attempts config.lock_strategy = :failed_attempts
# Defines which key will be used when locking and unlocking an account # Defines which key will be used when locking and unlocking an account
config.unlock_keys = [ :email ] config.unlock_keys = [:email]
# Defines which strategy will be used to unlock an account. # Defines which strategy will be used to unlock an account.
# :email = Sends an unlock link to the user email # :email = Sends an unlock link to the user email
......
module Gollum module Gollum
GIT_ADAPTER = "rugged" GIT_ADAPTER = "rugged".freeze
end end
require "gollum-lib" require "gollum-lib"
......
HealthCheck.setup do |config| HealthCheck.setup do |config|
config.standard_checks = ['database', 'migrations', 'cache'] config.standard_checks = %w(database migrations cache)
config.full_checks = ['database', 'migrations', 'cache'] config.full_checks = %w(database migrations cache)
end end
...@@ -20,13 +20,13 @@ def instrument_classes(instrumentation) ...@@ -20,13 +20,13 @@ def instrument_classes(instrumentation)
# Path to search => prefix to strip from constant # Path to search => prefix to strip from constant
paths_to_instrument = { paths_to_instrument = {
['app', 'finders'] => ['app', 'finders'], %w(app finders) => %w(app finders),
['app', 'mailers', 'emails'] => ['app', 'mailers'], %w(app mailers emails) => %w(app mailers),
['app', 'services', '**'] => ['app', 'services'], %w(app services **) => %w(app services),
['lib', 'gitlab', 'conflicts'] => ['lib'], %w(lib gitlab conflicts) => ['lib'],
['lib', 'gitlab', 'diff'] => ['lib'], %w(lib gitlab diff) => ['lib'],
['lib', 'gitlab', 'email', 'message'] => ['lib'], %w(lib gitlab email message) => ['lib'],
['lib', 'gitlab', 'checks'] => ['lib'] %w(lib gitlab checks) => ['lib']
} }
paths_to_instrument.each do |(path, prefix)| paths_to_instrument.each do |(path, prefix)|
......
...@@ -21,4 +21,4 @@ gitlab_trusted_proxies = Array(Gitlab.config.gitlab.trusted_proxies).map do |pro ...@@ -21,4 +21,4 @@ gitlab_trusted_proxies = Array(Gitlab.config.gitlab.trusted_proxies).map do |pro
end.compact end.compact
Rails.application.config.action_dispatch.trusted_proxies = ( Rails.application.config.action_dispatch.trusted_proxies = (
[ '127.0.0.1', '::1' ] + gitlab_trusted_proxies) ['127.0.0.1', '::1'] + gitlab_trusted_proxies)
...@@ -10,7 +10,7 @@ end ...@@ -10,7 +10,7 @@ end
# #
module Gitlab module Gitlab
module StrongParameterScalars module StrongParameterScalars
GITLAB_PERMITTED_SCALAR_TYPES = [::UploadedFile] GITLAB_PERMITTED_SCALAR_TYPES = [::UploadedFile].freeze
def permitted_scalar?(value) def permitted_scalar?(value)
super || GITLAB_PERMITTED_SCALAR_TYPES.any? { |type| value.is_a?(type) } super || GITLAB_PERMITTED_SCALAR_TYPES.any? { |type| value.is_a?(type) }
......
WIKI_SLUG_ID = { id: /\S+/ } unless defined? WIKI_SLUG_ID WIKI_SLUG_ID = { id: /\S+/ }.freeze unless defined? WIKI_SLUG_ID
scope(controller: :wikis) do scope(controller: :wikis) do
scope(path: 'wikis', as: :wikis) do scope(path: 'wikis', as: :wikis) do
......
...@@ -2,6 +2,8 @@ class MigrateUsersNotificationLevel < ActiveRecord::Migration ...@@ -2,6 +2,8 @@ class MigrateUsersNotificationLevel < ActiveRecord::Migration
# Migrates only users who changed their default notification level :participating # Migrates only users who changed their default notification level :participating
# creating a new record on notification settings table # creating a new record on notification settings table
DOWNTIME = false
def up def up
execute(%Q{ execute(%Q{
INSERT INTO notification_settings INSERT INTO notification_settings
......
...@@ -26,7 +26,7 @@ class AddMarkdownCacheColumns < ActiveRecord::Migration ...@@ -26,7 +26,7 @@ class AddMarkdownCacheColumns < ActiveRecord::Migration
projects: [:description], projects: [:description],
releases: [:description], releases: [:description],
snippets: [:title, :content], snippets: [:title, :content],
} }.freeze
def change def change
COLUMNS.each do |table, columns| COLUMNS.each do |table, columns|
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment