summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/api.rb44
-rw-r--r--lib/api/deploy_keys.rb6
-rw-r--r--lib/api/entities.rb43
-rw-r--r--lib/api/helpers/related_resources_helpers.rb2
-rw-r--r--lib/api/issues.rb2
-rw-r--r--lib/api/merge_requests.rb64
-rw-r--r--lib/api/projects.rb7
-rw-r--r--lib/api/runner.rb16
-rw-r--r--lib/api/runners.rb6
-rw-r--r--lib/api/search.rb4
-rw-r--r--lib/api/settings.rb21
-rw-r--r--lib/api/v3/award_emoji.rb130
-rw-r--r--lib/api/v3/boards.rb72
-rw-r--r--lib/api/v3/branches.rb76
-rw-r--r--lib/api/v3/broadcast_messages.rb31
-rw-r--r--lib/api/v3/builds.rb250
-rw-r--r--lib/api/v3/commits.rb199
-rw-r--r--lib/api/v3/deploy_keys.rb143
-rw-r--r--lib/api/v3/deployments.rb43
-rw-r--r--lib/api/v3/entities.rb309
-rw-r--r--lib/api/v3/environments.rb87
-rw-r--r--lib/api/v3/files.rb138
-rw-r--r--lib/api/v3/groups.rb187
-rw-r--r--lib/api/v3/helpers.rb49
-rw-r--r--lib/api/v3/issues.rb240
-rw-r--r--lib/api/v3/labels.rb34
-rw-r--r--lib/api/v3/members.rb136
-rw-r--r--lib/api/v3/merge_request_diffs.rb44
-rw-r--r--lib/api/v3/merge_requests.rb297
-rw-r--r--lib/api/v3/milestones.rb65
-rw-r--r--lib/api/v3/notes.rb148
-rw-r--r--lib/api/v3/pipelines.rb38
-rw-r--r--lib/api/v3/project_hooks.rb111
-rw-r--r--lib/api/v3/project_snippets.rb143
-rw-r--r--lib/api/v3/projects.rb475
-rw-r--r--lib/api/v3/repositories.rb110
-rw-r--r--lib/api/v3/runners.rb66
-rw-r--r--lib/api/v3/services.rb670
-rw-r--r--lib/api/v3/settings.rb147
-rw-r--r--lib/api/v3/snippets.rb141
-rw-r--r--lib/api/v3/subscriptions.rb53
-rw-r--r--lib/api/v3/system_hooks.rb32
-rw-r--r--lib/api/v3/tags.rb40
-rw-r--r--lib/api/v3/templates.rb122
-rw-r--r--lib/api/v3/time_tracking_endpoints.rb116
-rw-r--r--lib/api/v3/todos.rb30
-rw-r--r--lib/api/v3/triggers.rb112
-rw-r--r--lib/api/v3/users.rb204
-rw-r--r--lib/api/v3/variables.rb29
-rw-r--r--lib/bitbucket/representation/issue.rb2
-rw-r--r--lib/feature.rb11
-rw-r--r--lib/gitlab/auth.rb19
-rw-r--r--lib/gitlab/auth/request_authenticator.rb2
-rw-r--r--lib/gitlab/auth/user_auth_finders.rb18
-rw-r--r--lib/gitlab/ci/pipeline/chain/populate.rb3
-rw-r--r--lib/gitlab/ci/trace/http_io.rb2
-rw-r--r--lib/gitlab/contributions_calendar.rb2
-rw-r--r--lib/gitlab/cycle_analytics/summary/commit.rb4
-rw-r--r--lib/gitlab/database/median.rb9
-rw-r--r--lib/gitlab/diff/file.rb9
-rw-r--r--lib/gitlab/diff/line.rb4
-rw-r--r--lib/gitlab/ee_compat_check.rb4
-rw-r--r--lib/gitlab/file_finder.rb26
-rw-r--r--lib/gitlab/git/repository.rb22
-rw-r--r--lib/gitlab/git/storage/checker.rb2
-rw-r--r--lib/gitlab/git/storage/circuit_breaker.rb15
-rw-r--r--lib/gitlab/gitaly_client.rb7
-rw-r--r--lib/gitlab/gitaly_client/commit_service.rb2
-rw-r--r--lib/gitlab/gitaly_client/storage_settings.rb26
-rw-r--r--lib/gitlab/gitlab_import/client.rb10
-rw-r--r--lib/gitlab/gitlab_import/importer.rb2
-rw-r--r--lib/gitlab/gitlab_import/project_creator.rb2
-rw-r--r--lib/gitlab/gon_helper.rb2
-rw-r--r--lib/gitlab/hashed_storage/rake_helper.rb71
-rw-r--r--lib/gitlab/health_checks/fs_shards_check.rb4
-rw-r--r--lib/gitlab/import_export/attribute_cleaner.rb11
-rw-r--r--lib/gitlab/import_export/attributes_finder.rb4
-rw-r--r--lib/gitlab/import_export/import_export.yml3
-rw-r--r--lib/gitlab/import_export/project_tree_restorer.rb23
-rw-r--r--lib/gitlab/import_export/reader.rb2
-rw-r--r--lib/gitlab/import_export/relation_factory.rb24
-rw-r--r--lib/gitlab/import_formatter.rb1
-rw-r--r--lib/gitlab/project_search_results.rb3
-rw-r--r--lib/gitlab/query_limiting/active_support_subscriber.rb2
-rw-r--r--lib/gitlab/slash_commands/command.rb18
-rw-r--r--lib/gitlab/temporarily_allow.rb42
-rw-r--r--lib/gitlab/url_blocker.rb17
-rw-r--r--lib/gitlab/webpack/dev_server_middleware.rb5
-rw-r--r--lib/gitlab/wiki_file_finder.rb23
-rw-r--r--lib/mattermost/command.rb2
-rw-r--r--lib/mattermost/session.rb4
-rw-r--r--lib/mattermost/team.rb6
-rw-r--r--lib/omni_auth/strategies/jwt.rb4
-rw-r--r--lib/peek/rblineprof/custom_controller_helpers.rb4
-rw-r--r--lib/rspec_flaky/listener.rb10
-rw-r--r--lib/rspec_flaky/report.rb4
-rw-r--r--lib/support/nginx/gitlab16
-rw-r--r--lib/support/nginx/gitlab-ssl16
-rw-r--r--lib/tasks/gitlab/storage.rake105
-rw-r--r--lib/tasks/lint.rake20
-rw-r--r--lib/tasks/tokens.rake10
101 files changed, 548 insertions, 5643 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 206fabe5c43..7ea575a9661 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -22,48 +22,14 @@ module API
allow_access_with_scope :api
prefix :api
- version %w(v3 v4), using: :path
-
version 'v3', using: :path do
- helpers ::API::V3::Helpers
- helpers ::API::Helpers::CommonHelpers
-
- mount ::API::V3::AwardEmoji
- mount ::API::V3::Boards
- mount ::API::V3::Branches
- mount ::API::V3::BroadcastMessages
- mount ::API::V3::Builds
- mount ::API::V3::Commits
- mount ::API::V3::DeployKeys
- mount ::API::V3::Environments
- mount ::API::V3::Files
- mount ::API::V3::Groups
- mount ::API::V3::Issues
- mount ::API::V3::Labels
- mount ::API::V3::Members
- mount ::API::V3::MergeRequestDiffs
- mount ::API::V3::MergeRequests
- mount ::API::V3::Notes
- mount ::API::V3::Pipelines
- mount ::API::V3::ProjectHooks
- mount ::API::V3::Milestones
- mount ::API::V3::Projects
- mount ::API::V3::ProjectSnippets
- mount ::API::V3::Repositories
- mount ::API::V3::Runners
- mount ::API::V3::Services
- mount ::API::V3::Settings
- mount ::API::V3::Snippets
- mount ::API::V3::Subscriptions
- mount ::API::V3::SystemHooks
- mount ::API::V3::Tags
- mount ::API::V3::Templates
- mount ::API::V3::Todos
- mount ::API::V3::Triggers
- mount ::API::V3::Users
- mount ::API::V3::Variables
+ route :any, '*path' do
+ error!('API V3 is no longer supported. Use API V4 instead.', 410)
+ end
end
+ version 'v4', using: :path
+
before do
header['X-Frame-Options'] = 'SAMEORIGIN'
header['X-Content-Type-Options'] = 'nosniff'
diff --git a/lib/api/deploy_keys.rb b/lib/api/deploy_keys.rb
index 70d43ac1d79..b7aadc27e71 100644
--- a/lib/api/deploy_keys.rb
+++ b/lib/api/deploy_keys.rb
@@ -148,10 +148,10 @@ module API
requires :key_id, type: Integer, desc: 'The ID of the deploy key'
end
delete ":id/deploy_keys/:key_id" do
- key = user_project.deploy_keys.find(params[:key_id])
- not_found!('Deploy Key') unless key
+ deploy_key_project = user_project.deploy_keys_projects.find_by(deploy_key_id: params[:key_id])
+ not_found!('Deploy Key') unless deploy_key_project
- destroy_conditionally!(key)
+ destroy_conditionally!(deploy_key_project)
end
end
end
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 3e615f7ac05..c4537036a3a 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -568,6 +568,8 @@ module API
expose :time_stats, using: 'API::Entities::IssuableTimeStats' do |merge_request|
merge_request
end
+
+ expose :squash
end
class MergeRequest < MergeRequestBasic
@@ -830,8 +832,8 @@ module API
class ProjectWithAccess < Project
expose :permissions do
expose :project_access, using: Entities::ProjectAccess do |project, options|
- if options.key?(:project_members)
- (options[:project_members] || []).find { |member| member.source_id == project.id }
+ if options[:project_members]
+ options[:project_members].find { |member| member.source_id == project.id }
else
project.project_member(options[:current_user])
end
@@ -839,8 +841,8 @@ module API
expose :group_access, using: Entities::GroupAccess do |project, options|
if project.group
- if options.key?(:group_members)
- (options[:group_members] || []).find { |member| member.source_id == project.namespace_id }
+ if options[:group_members]
+ options[:group_members].find { |member| member.source_id == project.namespace_id }
else
project.group.group_member(options[:current_user])
end
@@ -851,13 +853,24 @@ module API
def self.preload_relation(projects_relation, options = {})
relation = super(projects_relation, options)
- unless options.key?(:group_members)
- relation = relation.preload(group: [group_members: [:source, user: [notification_settings: :source]]])
+ # MySQL doesn't support LIMIT inside an IN subquery
+ if Gitlab::Database.mysql?
+ project_ids = relation.pluck('projects.id')
+ namespace_ids = relation.pluck(:namespace_id)
+ else
+ project_ids = relation.select('projects.id')
+ namespace_ids = relation.select(:namespace_id)
end
- unless options.key?(:project_members)
- relation = relation.preload(project_members: [:source, user: [notification_settings: :source]])
- end
+ options[:project_members] = options[:current_user]
+ .project_members
+ .where(source_id: project_ids)
+ .preload(:source, user: [notification_settings: :source])
+
+ options[:group_members] = options[:current_user]
+ .group_members
+ .where(source_id: namespace_ids)
+ .preload(:source, user: [notification_settings: :source])
relation
end
@@ -933,8 +946,16 @@ module API
end
class ApplicationSetting < Grape::Entity
- expose :id
- expose(*::ApplicationSettingsHelper.visible_attributes)
+ def self.exposed_attributes
+ attributes = ::ApplicationSettingsHelper.visible_attributes
+ attributes.delete(:performance_bar_allowed_group_path)
+ attributes.delete(:performance_bar_enabled)
+
+ attributes
+ end
+
+ expose :id, :performance_bar_allowed_group_id
+ expose(*exposed_attributes)
expose(:restricted_visibility_levels) do |setting, _options|
setting.restricted_visibility_levels.map { |level| Gitlab::VisibilityLevel.string_level(level) }
end
diff --git a/lib/api/helpers/related_resources_helpers.rb b/lib/api/helpers/related_resources_helpers.rb
index a2cbed30229..bc7333ca4b3 100644
--- a/lib/api/helpers/related_resources_helpers.rb
+++ b/lib/api/helpers/related_resources_helpers.rb
@@ -1,7 +1,7 @@
module API
module Helpers
module RelatedResourcesHelpers
- include GrapeRouteHelpers::NamedRouteMatcher
+ include GrapePathHelpers::NamedRouteMatcher
def issues_available?(project, options)
available?(:issues, project, options[:current_user])
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index 6d75e8817c4..b64f465ce56 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -16,7 +16,7 @@ module API
args[:scope] = args[:scope].underscore if args[:scope]
issues = IssuesFinder.new(current_user, args).execute
- .preload(:assignees, :labels, :notes, :timelogs)
+ .preload(:assignees, :labels, :notes, :timelogs, :project)
issues.reorder(args[:order_by] => args[:sort])
end
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index bc4df16e3a8..278d53427f0 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -10,12 +10,6 @@ module API
helpers do
params :optional_params_ee do
end
-
- params :merge_params_ee do
- end
-
- def update_merge_request_ee(merge_request)
- end
end
def self.update_params_at_least_one_of
@@ -29,6 +23,7 @@ module API
target_branch
title
discussion_locked
+ squash
]
end
@@ -43,7 +38,7 @@ module API
merge_requests = MergeRequestsFinder.new(current_user, args).execute
.reorder(args[:order_by] => args[:sort])
merge_requests = paginate(merge_requests)
- .preload(:target_project)
+ .preload(:source_project, :target_project)
return merge_requests if args[:view] == 'simple'
@@ -64,6 +59,18 @@ module API
end
end
+ def serializer_options_for(merge_requests)
+ options = { with: Entities::MergeRequestBasic, current_user: current_user }
+
+ if params[:view] == 'simple'
+ options[:with] = Entities::MergeRequestSimple
+ else
+ options[:issuable_metadata] = issuable_meta_data(merge_requests, 'MergeRequest')
+ end
+
+ options
+ end
+
params :merge_requests_params do
optional :state, type: String, values: %w[opened closed merged all], default: 'all',
desc: 'Return opened, closed, merged, or all merge requests'
@@ -103,16 +110,26 @@ module API
authenticate! unless params[:scope] == 'all'
merge_requests = find_merge_requests
- options = { with: Entities::MergeRequestBasic,
- current_user: current_user }
+ present merge_requests, serializer_options_for(merge_requests)
+ end
+ end
- if params[:view] == 'simple'
- options[:with] = Entities::MergeRequestSimple
- else
- options[:issuable_metadata] = issuable_meta_data(merge_requests, 'MergeRequest')
- end
+ params do
+ requires :id, type: String, desc: 'The ID of a group'
+ end
+ resource :groups, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
+ desc 'Get a list of group merge requests' do
+ success Entities::MergeRequestBasic
+ end
+ params do
+ use :merge_requests_params
+ end
+ get ":id/merge_requests" do
+ group = find_group!(params[:id])
- present merge_requests, options
+ merge_requests = find_merge_requests(group_id: group.id, include_subgroups: true)
+
+ present merge_requests, serializer_options_for(merge_requests)
end
end
@@ -146,6 +163,7 @@ module API
optional :labels, type: String, desc: 'Comma-separated list of label names'
optional :remove_source_branch, type: Boolean, desc: 'Remove source branch when merging'
optional :allow_maintainer_to_push, type: Boolean, desc: 'Whether a maintainer of the target project can push to the source project'
+ optional :squash, type: Grape::API::Boolean, desc: 'When true, the commits will be squashed into a single commit on merge'
use :optional_params_ee
end
@@ -163,15 +181,8 @@ module API
merge_requests = find_merge_requests(project_id: user_project.id)
- options = { with: Entities::MergeRequestBasic,
- current_user: current_user,
- project: user_project }
-
- if params[:view] == 'simple'
- options[:with] = Entities::MergeRequestSimple
- else
- options[:issuable_metadata] = issuable_meta_data(merge_requests, 'MergeRequest')
- end
+ options = serializer_options_for(merge_requests)
+ options[:project] = user_project
present merge_requests, options
end
@@ -308,8 +319,7 @@ module API
optional :merge_when_pipeline_succeeds, type: Boolean,
desc: 'When true, this merge request will be merged when the pipeline succeeds'
optional :sha, type: String, desc: 'When present, must have the HEAD SHA of the source branch'
-
- use :merge_params_ee
+ optional :squash, type: Grape::API::Boolean, desc: 'When true, the commits will be squashed into a single commit on merge'
end
put ':id/merge_requests/:merge_request_iid/merge' do
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42317')
@@ -327,7 +337,7 @@ module API
check_sha_param!(params, merge_request)
- update_merge_request_ee(merge_request)
+ merge_request.update(squash: params[:squash]) if params[:squash]
merge_params = {
commit_message: params[:merge_commit_message],
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 8871792060b..3ef3680c5d9 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -58,16 +58,9 @@ module API
projects = paginate(projects)
projects, options = with_custom_attributes(projects, options)
- if current_user
- project_members = current_user.project_members.preload(:source, user: [notification_settings: :source])
- group_members = current_user.group_members.preload(:source, user: [notification_settings: :source])
- end
-
options = options.reverse_merge(
with: current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails,
statistics: params[:statistics],
- project_members: project_members,
- group_members: group_members,
current_user: current_user
)
options[:with] = Entities::BasicProjectDetails if params[:simple]
diff --git a/lib/api/runner.rb b/lib/api/runner.rb
index 5b7ae89440c..e9886c76870 100644
--- a/lib/api/runner.rb
+++ b/lib/api/runner.rb
@@ -21,24 +21,26 @@ module API
attributes = attributes_for_keys([:description, :active, :locked, :run_untagged, :tag_list, :maximum_timeout])
.merge(get_runner_details_from_request)
- runner =
+ attributes =
if runner_registration_token_valid?
# Create shared runner. Requires admin access
- Ci::Runner.create(attributes.merge(is_shared: true, runner_type: :instance_type))
+ attributes.merge(is_shared: true, runner_type: :instance_type)
elsif project = Project.find_by(runners_token: params[:token])
# Create a specific runner for the project
- project.runners.create(attributes.merge(runner_type: :project_type))
+ attributes.merge(is_shared: false, runner_type: :project_type, projects: [project])
elsif group = Group.find_by(runners_token: params[:token])
# Create a specific runner for the group
- group.runners.create(attributes.merge(runner_type: :group_type))
+ attributes.merge(is_shared: false, runner_type: :group_type, groups: [group])
+ else
+ forbidden!
end
- break forbidden! unless runner
+ runner = Ci::Runner.create(attributes)
- if runner.id
+ if runner.persisted?
present runner, with: Entities::RunnerRegistrationDetails
else
- not_found!
+ render_validation_error!(runner)
end
end
diff --git a/lib/api/runners.rb b/lib/api/runners.rb
index 5cb96d467c0..2b78075ddbf 100644
--- a/lib/api/runners.rb
+++ b/lib/api/runners.rb
@@ -133,12 +133,10 @@ module API
runner = get_runner(params[:runner_id])
authenticate_enable_runner!(runner)
- runner_project = runner.assign_to(user_project)
-
- if runner_project.persisted?
+ if runner.assign_to(user_project)
present runner, with: Entities::Runner
else
- conflict!("Runner was already enabled for this project")
+ render_validation_error!(runner)
end
end
diff --git a/lib/api/search.rb b/lib/api/search.rb
index 5d9ec617cb7..37fbabe419c 100644
--- a/lib/api/search.rb
+++ b/lib/api/search.rb
@@ -34,9 +34,7 @@ module API
def process_results(results)
case params[:scope]
- when 'wiki_blobs'
- paginate(results).map { |blob| Gitlab::ProjectSearchResults.parse_search_result(blob, user_project) }
- when 'blobs'
+ when 'blobs', 'wiki_blobs'
paginate(results).map { |blob| blob[1] }
else
paginate(results)
diff --git a/lib/api/settings.rb b/lib/api/settings.rb
index d727ad59367..02ef89f997f 100644
--- a/lib/api/settings.rb
+++ b/lib/api/settings.rb
@@ -49,6 +49,9 @@ module API
optional :signin_enabled, type: Boolean, desc: 'Flag indicating if password authentication is enabled for the web interface' # support legacy names, can be removed in v5
mutually_exclusive :password_authentication_enabled_for_web, :password_authentication_enabled, :signin_enabled
optional :password_authentication_enabled_for_git, type: Boolean, desc: 'Flag indicating if password authentication is enabled for Git over HTTP(S)'
+ optional :performance_bar_allowed_group_path, type: String, desc: 'Path of the group that is allowed to toggle the performance bar.'
+ optional :performance_bar_allowed_group_id, type: String, desc: 'Depreated: Use :performance_bar_allowed_group_path instead. Path of the group that is allowed to toggle the performance bar.' # support legacy names, can be removed in v6
+ optional :performance_bar_enabled, type: String, desc: 'Deprecated: Pass `performance_bar_allowed_group_path: nil` instead. Allow enabling the performance.' # support legacy names, can be removed in v6
optional :require_two_factor_authentication, type: Boolean, desc: 'Require all users to setup Two-factor authentication'
given require_two_factor_authentication: ->(val) { val } do
requires :two_factor_grace_period, type: Integer, desc: 'Amount of time (in hours) that users are allowed to skip forced configuration of two-factor authentication'
@@ -126,6 +129,7 @@ module API
optional :gitaly_timeout_default, type: Integer, desc: 'Default Gitaly timeout, in seconds. Set to 0 to disable timeouts.'
optional :gitaly_timeout_medium, type: Integer, desc: 'Medium Gitaly timeout, in seconds. Set to 0 to disable timeouts.'
optional :gitaly_timeout_fast, type: Integer, desc: 'Gitaly fast operation timeout, in seconds. Set to 0 to disable timeouts.'
+ optional :usage_ping_enabled, type: Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.'
ApplicationSetting::SUPPORTED_KEY_TYPES.each do |type|
optional :"#{type}_key_restriction",
@@ -134,12 +138,25 @@ module API
desc: "Restrictions on the complexity of uploaded #{type.upcase} keys. A value of #{ApplicationSetting::FORBIDDEN_KEY_VALUE} disables all #{type.upcase} keys."
end
- optional(*::ApplicationSettingsHelper.visible_attributes)
- at_least_one_of(*::ApplicationSettingsHelper.visible_attributes)
+ optional_attributes = ::ApplicationSettingsHelper.visible_attributes << :performance_bar_allowed_group_id
+
+ optional(*optional_attributes)
+ at_least_one_of(*optional_attributes)
end
put "application/settings" do
attrs = declared_params(include_missing: false)
+ # support legacy names, can be removed in v6
+ if attrs.has_key?(:performance_bar_allowed_group_id)
+ attrs[:performance_bar_allowed_group_path] = attrs.delete(:performance_bar_allowed_group_id)
+ end
+
+ # support legacy names, can be removed in v6
+ if attrs.has_key?(:performance_bar_enabled)
+ performance_bar_enabled = attrs.delete(:performance_bar_allowed_group_id)
+ attrs[:performance_bar_allowed_group_path] = nil unless performance_bar_enabled
+ end
+
# support legacy names, can be removed in v5
if attrs.has_key?(:signin_enabled)
attrs[:password_authentication_enabled_for_web] = attrs.delete(:signin_enabled)
diff --git a/lib/api/v3/award_emoji.rb b/lib/api/v3/award_emoji.rb
deleted file mode 100644
index b96b2d70b12..00000000000
--- a/lib/api/v3/award_emoji.rb
+++ /dev/null
@@ -1,130 +0,0 @@
-module API
- module V3
- class AwardEmoji < Grape::API
- include PaginationParams
-
- before { authenticate! }
- AWARDABLES = %w[issue merge_request snippet].freeze
-
- resource :projects, requirements: { id: %r{[^/]+} } do
- AWARDABLES.each do |awardable_type|
- awardable_string = awardable_type.pluralize
- awardable_id_string = "#{awardable_type}_id"
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- requires :"#{awardable_id_string}", type: Integer, desc: "The ID of an Issue, Merge Request or Snippet"
- end
-
- [
- ":id/#{awardable_string}/:#{awardable_id_string}/award_emoji",
- ":id/#{awardable_string}/:#{awardable_id_string}/notes/:note_id/award_emoji"
- ].each do |endpoint|
-
- desc 'Get a list of project +awardable+ award emoji' do
- detail 'This feature was introduced in 8.9'
- success Entities::AwardEmoji
- end
- params do
- use :pagination
- end
- get endpoint do
- if can_read_awardable?
- awards = awardable.award_emoji
- present paginate(awards), with: Entities::AwardEmoji
- else
- not_found!("Award Emoji")
- end
- end
-
- desc 'Get a specific award emoji' do
- detail 'This feature was introduced in 8.9'
- success Entities::AwardEmoji
- end
- params do
- requires :award_id, type: Integer, desc: 'The ID of the award'
- end
- get "#{endpoint}/:award_id" do
- if can_read_awardable?
- present awardable.award_emoji.find(params[:award_id]), with: Entities::AwardEmoji
- else
- not_found!("Award Emoji")
- end
- end
-
- desc 'Award a new Emoji' do
- detail 'This feature was introduced in 8.9'
- success Entities::AwardEmoji
- end
- params do
- requires :name, type: String, desc: 'The name of a award_emoji (without colons)'
- end
- post endpoint do
- not_found!('Award Emoji') unless can_read_awardable? && can_award_awardable?
-
- award = awardable.create_award_emoji(params[:name], current_user)
-
- if award.persisted?
- present award, with: Entities::AwardEmoji
- else
- not_found!("Award Emoji #{award.errors.messages}")
- end
- end
-
- desc 'Delete a +awardables+ award emoji' do
- detail 'This feature was introduced in 8.9'
- success Entities::AwardEmoji
- end
- params do
- requires :award_id, type: Integer, desc: 'The ID of an award emoji'
- end
- delete "#{endpoint}/:award_id" do
- award = awardable.award_emoji.find(params[:award_id])
-
- unauthorized! unless award.user == current_user || current_user.admin?
-
- award.destroy
- present award, with: Entities::AwardEmoji
- end
- end
- end
- end
-
- helpers do
- def can_read_awardable?
- can?(current_user, read_ability(awardable), awardable)
- end
-
- def can_award_awardable?
- awardable.user_can_award?(current_user, params[:name])
- end
-
- def awardable
- @awardable ||=
- begin
- if params.include?(:note_id)
- note_id = params.delete(:note_id)
-
- awardable.notes.find(note_id)
- elsif params.include?(:issue_id)
- user_project.issues.find(params[:issue_id])
- elsif params.include?(:merge_request_id)
- user_project.merge_requests.find(params[:merge_request_id])
- else
- user_project.snippets.find(params[:snippet_id])
- end
- end
- end
-
- def read_ability(awardable)
- case awardable
- when Note
- read_ability(awardable.noteable)
- else
- :"read_#{awardable.class.to_s.underscore}"
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/boards.rb b/lib/api/v3/boards.rb
deleted file mode 100644
index 94acc67171e..00000000000
--- a/lib/api/v3/boards.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-module API
- module V3
- class Boards < Grape::API
- before { authenticate! }
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Get all project boards' do
- detail 'This feature was introduced in 8.13'
- success ::API::Entities::Board
- end
- get ':id/boards' do
- authorize!(:read_board, user_project)
- present user_project.boards, with: ::API::Entities::Board
- end
-
- params do
- requires :board_id, type: Integer, desc: 'The ID of a board'
- end
- segment ':id/boards/:board_id' do
- helpers do
- def project_board
- board = user_project.boards.first
-
- if params[:board_id] == board.id
- board
- else
- not_found!('Board')
- end
- end
-
- def board_lists
- project_board.lists.destroyable
- end
- end
-
- desc 'Get the lists of a project board' do
- detail 'Does not include `done` list. This feature was introduced in 8.13'
- success ::API::Entities::List
- end
- get '/lists' do
- authorize!(:read_board, user_project)
- present board_lists, with: ::API::Entities::List
- end
-
- desc 'Delete a board list' do
- detail 'This feature was introduced in 8.13'
- success ::API::Entities::List
- end
- params do
- requires :list_id, type: Integer, desc: 'The ID of a board list'
- end
- delete "/lists/:list_id" do
- authorize!(:admin_list, user_project)
-
- list = board_lists.find(params[:list_id])
-
- service = ::Boards::Lists::DestroyService.new(user_project, current_user)
-
- if service.execute(list)
- present list, with: ::API::Entities::List
- else
- render_api_error!({ error: 'List could not be deleted!' }, 400)
- end
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/branches.rb b/lib/api/v3/branches.rb
deleted file mode 100644
index 25176c5b38e..00000000000
--- a/lib/api/v3/branches.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-require 'mime/types'
-
-module API
- module V3
- class Branches < Grape::API
- before { authenticate! }
- before { authorize! :download_code, user_project }
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Get a project repository branches' do
- success ::API::Entities::Branch
- end
- get ":id/repository/branches" do
- Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42276')
-
- repository = user_project.repository
- branches = repository.branches.sort_by(&:name)
- merged_branch_names = repository.merged_branch_names(branches.map(&:name))
-
- present branches, with: ::API::Entities::Branch, project: user_project, merged_branch_names: merged_branch_names
- end
-
- desc 'Delete a branch'
- params do
- requires :branch, type: String, desc: 'The name of the branch'
- end
- delete ":id/repository/branches/:branch", requirements: { branch: /.+/ } do
- authorize_push_project
-
- result = DeleteBranchService.new(user_project, current_user)
- .execute(params[:branch])
-
- if result[:status] == :success
- status(200)
- {
- branch_name: params[:branch]
- }
- else
- render_api_error!(result[:message], result[:return_code])
- end
- end
-
- desc 'Delete all merged branches'
- delete ":id/repository/merged_branches" do
- DeleteMergedBranchesService.new(user_project, current_user).async_execute
-
- status(200)
- end
-
- desc 'Create branch' do
- success ::API::Entities::Branch
- end
- params do
- requires :branch_name, type: String, desc: 'The name of the branch'
- requires :ref, type: String, desc: 'Create branch from commit sha or existing branch'
- end
- post ":id/repository/branches" do
- authorize_push_project
- result = CreateBranchService.new(user_project, current_user)
- .execute(params[:branch_name], params[:ref])
-
- if result[:status] == :success
- present result[:branch],
- with: ::API::Entities::Branch,
- project: user_project
- else
- render_api_error!(result[:message], 400)
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/broadcast_messages.rb b/lib/api/v3/broadcast_messages.rb
deleted file mode 100644
index 417e4ad0b26..00000000000
--- a/lib/api/v3/broadcast_messages.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-module API
- module V3
- class BroadcastMessages < Grape::API
- include PaginationParams
-
- before { authenticate! }
- before { authenticated_as_admin! }
-
- resource :broadcast_messages do
- helpers do
- def find_message
- BroadcastMessage.find(params[:id])
- end
- end
-
- desc 'Delete a broadcast message' do
- detail 'This feature was introduced in GitLab 8.12.'
- success ::API::Entities::BroadcastMessage
- end
- params do
- requires :id, type: Integer, desc: 'Broadcast message ID'
- end
- delete ':id' do
- message = find_message
-
- present message.destroy, with: ::API::Entities::BroadcastMessage
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/builds.rb b/lib/api/v3/builds.rb
deleted file mode 100644
index b49448e1e67..00000000000
--- a/lib/api/v3/builds.rb
+++ /dev/null
@@ -1,250 +0,0 @@
-module API
- module V3
- class Builds < Grape::API
- include PaginationParams
-
- before { authenticate! }
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
- helpers do
- params :optional_scope do
- optional :scope, types: [String, Array[String]], desc: 'The scope of builds to show',
- values: %w(pending running failed success canceled skipped),
- coerce_with: ->(scope) {
- if scope.is_a?(String)
- [scope]
- elsif scope.is_a?(::Hash)
- scope.values
- else
- ['unknown']
- end
- }
- end
- end
-
- desc 'Get a project builds' do
- success ::API::V3::Entities::Build
- end
- params do
- use :optional_scope
- use :pagination
- end
- get ':id/builds' do
- builds = user_project.builds.order('id DESC')
- builds = filter_builds(builds, params[:scope])
-
- builds = builds.preload(:user, :job_artifacts_archive, :runner, pipeline: :project)
- present paginate(builds), with: ::API::V3::Entities::Build
- end
-
- desc 'Get builds for a specific commit of a project' do
- success ::API::V3::Entities::Build
- end
- params do
- requires :sha, type: String, desc: 'The SHA id of a commit'
- use :optional_scope
- use :pagination
- end
- get ':id/repository/commits/:sha/builds' do
- authorize_read_builds!
-
- break not_found! unless user_project.commit(params[:sha])
-
- pipelines = user_project.pipelines.where(sha: params[:sha])
- builds = user_project.builds.where(pipeline: pipelines).order('id DESC')
- builds = filter_builds(builds, params[:scope])
-
- present paginate(builds), with: ::API::V3::Entities::Build
- end
-
- desc 'Get a specific build of a project' do
- success ::API::V3::Entities::Build
- end
- params do
- requires :build_id, type: Integer, desc: 'The ID of a build'
- end
- get ':id/builds/:build_id' do
- authorize_read_builds!
-
- build = get_build!(params[:build_id])
-
- present build, with: ::API::V3::Entities::Build
- end
-
- desc 'Download the artifacts file from build' do
- detail 'This feature was introduced in GitLab 8.5'
- end
- params do
- requires :build_id, type: Integer, desc: 'The ID of a build'
- end
- get ':id/builds/:build_id/artifacts' do
- authorize_read_builds!
-
- build = get_build!(params[:build_id])
-
- present_carrierwave_file!(build.artifacts_file)
- end
-
- desc 'Download the artifacts file from build' do
- detail 'This feature was introduced in GitLab 8.10'
- end
- params do
- requires :ref_name, type: String, desc: 'The ref from repository'
- requires :job, type: String, desc: 'The name for the build'
- end
- get ':id/builds/artifacts/:ref_name/download',
- requirements: { ref_name: /.+/ } do
- authorize_read_builds!
-
- builds = user_project.latest_successful_builds_for(params[:ref_name])
- latest_build = builds.find_by!(name: params[:job])
-
- present_carrierwave_file!(latest_build.artifacts_file)
- end
-
- # TODO: We should use `present_disk_file!` and leave this implementation for backward compatibility (when build trace
- # is saved in the DB instead of file). But before that, we need to consider how to replace the value of
- # `runners_token` with some mask (like `xxxxxx`) when sending trace file directly by workhorse.
- desc 'Get a trace of a specific build of a project'
- params do
- requires :build_id, type: Integer, desc: 'The ID of a build'
- end
- get ':id/builds/:build_id/trace' do
- authorize_read_builds!
-
- build = get_build!(params[:build_id])
-
- header 'Content-Disposition', "infile; filename=\"#{build.id}.log\""
- content_type 'text/plain'
- env['api.format'] = :binary
-
- trace = build.trace.raw
- body trace
- end
-
- desc 'Cancel a specific build of a project' do
- success ::API::V3::Entities::Build
- end
- params do
- requires :build_id, type: Integer, desc: 'The ID of a build'
- end
- post ':id/builds/:build_id/cancel' do
- authorize_update_builds!
-
- build = get_build!(params[:build_id])
- authorize!(:update_build, build)
-
- build.cancel
-
- present build, with: ::API::V3::Entities::Build
- end
-
- desc 'Retry a specific build of a project' do
- success ::API::V3::Entities::Build
- end
- params do
- requires :build_id, type: Integer, desc: 'The ID of a build'
- end
- post ':id/builds/:build_id/retry' do
- authorize_update_builds!
-
- build = get_build!(params[:build_id])
- authorize!(:update_build, build)
- break forbidden!('Build is not retryable') unless build.retryable?
-
- build = Ci::Build.retry(build, current_user)
-
- present build, with: ::API::V3::Entities::Build
- end
-
- desc 'Erase build (remove artifacts and build trace)' do
- success ::API::V3::Entities::Build
- end
- params do
- requires :build_id, type: Integer, desc: 'The ID of a build'
- end
- post ':id/builds/:build_id/erase' do
- authorize_update_builds!
-
- build = get_build!(params[:build_id])
- authorize!(:erase_build, build)
- break forbidden!('Build is not erasable!') unless build.erasable?
-
- build.erase(erased_by: current_user)
- present build, with: ::API::V3::Entities::Build
- end
-
- desc 'Keep the artifacts to prevent them from being deleted' do
- success ::API::V3::Entities::Build
- end
- params do
- requires :build_id, type: Integer, desc: 'The ID of a build'
- end
- post ':id/builds/:build_id/artifacts/keep' do
- authorize_update_builds!
-
- build = get_build!(params[:build_id])
- authorize!(:update_build, build)
- break not_found!(build) unless build.artifacts?
-
- build.keep_artifacts!
-
- status 200
- present build, with: ::API::V3::Entities::Build
- end
-
- desc 'Trigger a manual build' do
- success ::API::V3::Entities::Build
- detail 'This feature was added in GitLab 8.11'
- end
- params do
- requires :build_id, type: Integer, desc: 'The ID of a Build'
- end
- post ":id/builds/:build_id/play" do
- authorize_read_builds!
-
- build = get_build!(params[:build_id])
- authorize!(:update_build, build)
- bad_request!("Unplayable Job") unless build.playable?
-
- build.play(current_user)
-
- status 200
- present build, with: ::API::V3::Entities::Build
- end
- end
-
- helpers do
- def find_build(id)
- user_project.builds.find_by(id: id.to_i)
- end
-
- def get_build!(id)
- find_build(id) || not_found!
- end
-
- def filter_builds(builds, scope)
- return builds if scope.nil? || scope.empty?
-
- available_statuses = ::CommitStatus::AVAILABLE_STATUSES
-
- unknown = scope - available_statuses
- render_api_error!('Scope contains invalid value(s)', 400) unless unknown.empty?
-
- builds.where(status: available_statuses && scope)
- end
-
- def authorize_read_builds!
- authorize! :read_build, user_project
- end
-
- def authorize_update_builds!
- authorize! :update_build, user_project
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/commits.rb b/lib/api/v3/commits.rb
deleted file mode 100644
index 4f6ea8f502e..00000000000
--- a/lib/api/v3/commits.rb
+++ /dev/null
@@ -1,199 +0,0 @@
-require 'mime/types'
-
-module API
- module V3
- class Commits < Grape::API
- include PaginationParams
-
- before { authenticate! }
- before { authorize! :download_code, user_project }
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
- desc 'Get a project repository commits' do
- success ::API::Entities::Commit
- end
- params do
- optional :ref_name, type: String, desc: 'The name of a repository branch or tag, if not given the default branch is used'
- optional :since, type: DateTime, desc: 'Only commits after or in this date will be returned'
- optional :until, type: DateTime, desc: 'Only commits before or in this date will be returned'
- optional :page, type: Integer, default: 0, desc: 'The page for pagination'
- optional :per_page, type: Integer, default: 20, desc: 'The number of results per page'
- optional :path, type: String, desc: 'The file path'
- end
- get ":id/repository/commits" do
- ref = params[:ref_name] || user_project.try(:default_branch) || 'master'
- offset = params[:page] * params[:per_page]
-
- commits = user_project.repository.commits(ref,
- path: params[:path],
- limit: params[:per_page],
- offset: offset,
- after: params[:since],
- before: params[:until])
-
- present commits, with: ::API::Entities::Commit
- end
-
- desc 'Commit multiple file changes as one commit' do
- success ::API::Entities::CommitDetail
- detail 'This feature was introduced in GitLab 8.13'
- end
- params do
- requires :branch_name, type: String, desc: 'The name of branch'
- requires :commit_message, type: String, desc: 'Commit message'
- requires :actions, type: Array[Hash], desc: 'Actions to perform in commit'
- optional :author_email, type: String, desc: 'Author email for commit'
- optional :author_name, type: String, desc: 'Author name for commit'
- end
- post ":id/repository/commits" do
- authorize! :push_code, user_project
-
- attrs = declared_params.dup
- branch = attrs.delete(:branch_name)
- attrs.merge!(start_branch: branch, branch_name: branch)
-
- result = ::Files::MultiService.new(user_project, current_user, attrs).execute
-
- if result[:status] == :success
- commit_detail = user_project.repository.commits(result[:result], limit: 1).first
- present commit_detail, with: ::API::Entities::CommitDetail
- else
- render_api_error!(result[:message], 400)
- end
- end
-
- desc 'Get a specific commit of a project' do
- success ::API::Entities::CommitDetail
- failure [[404, 'Not Found']]
- end
- params do
- requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag'
- optional :stats, type: Boolean, default: true, desc: 'Include commit stats'
- end
- get ":id/repository/commits/:sha", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
- commit = user_project.commit(params[:sha])
-
- not_found! "Commit" unless commit
-
- present commit, with: ::API::Entities::CommitDetail, stats: params[:stats]
- end
-
- desc 'Get the diff for a specific commit of a project' do
- failure [[404, 'Not Found']]
- end
- params do
- requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag'
- end
- get ":id/repository/commits/:sha/diff", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
- commit = user_project.commit(params[:sha])
-
- not_found! "Commit" unless commit
-
- commit.raw_diffs.to_a
- end
-
- desc "Get a commit's comments" do
- success ::API::Entities::CommitNote
- failure [[404, 'Not Found']]
- end
- params do
- use :pagination
- requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag'
- end
- get ':id/repository/commits/:sha/comments', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
- commit = user_project.commit(params[:sha])
-
- not_found! 'Commit' unless commit
- notes = commit.notes.order(:created_at)
-
- present paginate(notes), with: ::API::Entities::CommitNote
- end
-
- desc 'Cherry pick commit into a branch' do
- detail 'This feature was introduced in GitLab 8.15'
- success ::API::Entities::Commit
- end
- params do
- requires :sha, type: String, desc: 'A commit sha to be cherry picked'
- requires :branch, type: String, desc: 'The name of the branch'
- end
- post ':id/repository/commits/:sha/cherry_pick', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
- authorize! :push_code, user_project
-
- commit = user_project.commit(params[:sha])
- not_found!('Commit') unless commit
-
- branch = user_project.repository.find_branch(params[:branch])
- not_found!('Branch') unless branch
-
- commit_params = {
- commit: commit,
- start_branch: params[:branch],
- branch_name: params[:branch]
- }
-
- result = ::Commits::CherryPickService.new(user_project, current_user, commit_params).execute
-
- if result[:status] == :success
- branch = user_project.repository.find_branch(params[:branch])
- present user_project.repository.commit(branch.dereferenced_target), with: ::API::Entities::Commit
- else
- render_api_error!(result[:message], 400)
- end
- end
-
- desc 'Post comment to commit' do
- success ::API::Entities::CommitNote
- end
- params do
- requires :sha, type: String, regexp: /\A\h{6,40}\z/, desc: "The commit's SHA"
- requires :note, type: String, desc: 'The text of the comment'
- optional :path, type: String, desc: 'The file path'
- given :path do
- requires :line, type: Integer, desc: 'The line number'
- requires :line_type, type: String, values: %w(new old), default: 'new', desc: 'The type of the line'
- end
- end
- post ':id/repository/commits/:sha/comments', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
- commit = user_project.commit(params[:sha])
- not_found! 'Commit' unless commit
-
- opts = {
- note: params[:note],
- noteable_type: 'Commit',
- commit_id: commit.id
- }
-
- if params[:path]
- commit.raw_diffs(limits: false).each do |diff|
- next unless diff.new_path == params[:path]
-
- lines = Gitlab::Diff::Parser.new.parse(diff.diff.each_line)
-
- lines.each do |line|
- next unless line.new_pos == params[:line] && line.type == params[:line_type]
-
- break opts[:line_code] = Gitlab::Git.diff_line_code(diff.new_path, line.new_pos, line.old_pos)
- end
-
- break if opts[:line_code]
- end
-
- opts[:type] = LegacyDiffNote.name if opts[:line_code]
- end
-
- note = ::Notes::CreateService.new(user_project, current_user, opts).execute
-
- if note.save
- present note, with: ::API::Entities::CommitNote
- else
- render_api_error!("Failed to save note #{note.errors.messages}", 400)
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/deploy_keys.rb b/lib/api/v3/deploy_keys.rb
deleted file mode 100644
index 47e54ca85a5..00000000000
--- a/lib/api/v3/deploy_keys.rb
+++ /dev/null
@@ -1,143 +0,0 @@
-module API
- module V3
- class DeployKeys < Grape::API
- before { authenticate! }
-
- helpers do
- def add_deploy_keys_project(project, attrs = {})
- project.deploy_keys_projects.create(attrs)
- end
-
- def find_by_deploy_key(project, key_id)
- project.deploy_keys_projects.find_by!(deploy_key: key_id)
- end
- end
-
- get "deploy_keys" do
- authenticated_as_admin!
-
- keys = DeployKey.all
- present keys, with: ::API::Entities::SSHKey
- end
-
- params do
- requires :id, type: String, desc: 'The ID of the project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- before { authorize_admin_project }
-
- %w(keys deploy_keys).each do |path|
- desc "Get a specific project's deploy keys" do
- success ::API::Entities::DeployKeysProject
- end
- get ":id/#{path}" do
- keys = user_project.deploy_keys_projects.preload(:deploy_key)
-
- present keys, with: ::API::Entities::DeployKeysProject
- end
-
- desc 'Get single deploy key' do
- success ::API::Entities::DeployKeysProject
- end
- params do
- requires :key_id, type: Integer, desc: 'The ID of the deploy key'
- end
- get ":id/#{path}/:key_id" do
- key = find_by_deploy_key(user_project, params[:key_id])
-
- present key, with: ::API::Entities::DeployKeysProject
- end
-
- desc 'Add new deploy key to currently authenticated user' do
- success ::API::Entities::DeployKeysProject
- end
- params do
- requires :key, type: String, desc: 'The new deploy key'
- requires :title, type: String, desc: 'The name of the deploy key'
- optional :can_push, type: Boolean, desc: "Can deploy key push to the project's repository"
- end
- post ":id/#{path}" do
- params[:key].strip!
-
- # Check for an existing key joined to this project
- key = user_project.deploy_keys_projects
- .joins(:deploy_key)
- .find_by(keys: { key: params[:key] })
-
- if key
- present key, with: ::API::Entities::DeployKeysProject
- break
- end
-
- # Check for available deploy keys in other projects
- key = current_user.accessible_deploy_keys.find_by(key: params[:key])
- if key
- added_key = add_deploy_keys_project(user_project, deploy_key: key, can_push: !!params[:can_push])
-
- present added_key, with: ::API::Entities::DeployKeysProject
- break
- end
-
- # Create a new deploy key
- key_attributes = { can_push: !!params[:can_push],
- deploy_key_attributes: declared_params.except(:can_push) }
- key = add_deploy_keys_project(user_project, key_attributes)
-
- if key.valid?
- present key, with: ::API::Entities::DeployKeysProject
- else
- render_validation_error!(key)
- end
- end
-
- desc 'Enable a deploy key for a project' do
- detail 'This feature was added in GitLab 8.11'
- success ::API::Entities::SSHKey
- end
- params do
- requires :key_id, type: Integer, desc: 'The ID of the deploy key'
- end
- post ":id/#{path}/:key_id/enable" do
- key = ::Projects::EnableDeployKeyService.new(user_project,
- current_user, declared_params).execute
-
- if key
- present key, with: ::API::Entities::SSHKey
- else
- not_found!('Deploy Key')
- end
- end
-
- desc 'Disable a deploy key for a project' do
- detail 'This feature was added in GitLab 8.11'
- success ::API::Entities::SSHKey
- end
- params do
- requires :key_id, type: Integer, desc: 'The ID of the deploy key'
- end
- delete ":id/#{path}/:key_id/disable" do
- key = user_project.deploy_keys_projects.find_by(deploy_key_id: params[:key_id])
- key.destroy
-
- present key.deploy_key, with: ::API::Entities::SSHKey
- end
-
- desc 'Delete deploy key for a project' do
- success Key
- end
- params do
- requires :key_id, type: Integer, desc: 'The ID of the deploy key'
- end
- delete ":id/#{path}/:key_id" do
- key = user_project.deploy_keys_projects.find_by(deploy_key_id: params[:key_id])
- if key
- key.destroy
- else
- not_found!('Deploy Key')
- end
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/deployments.rb b/lib/api/v3/deployments.rb
deleted file mode 100644
index 1d4972eda26..00000000000
--- a/lib/api/v3/deployments.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-module API
- module V3
- # Deployments RESTful API endpoints
- class Deployments < Grape::API
- include PaginationParams
-
- before { authenticate! }
-
- params do
- requires :id, type: String, desc: 'The project ID'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Get all deployments of the project' do
- detail 'This feature was introduced in GitLab 8.11.'
- success ::API::V3::Deployments
- end
- params do
- use :pagination
- end
- get ':id/deployments' do
- authorize! :read_deployment, user_project
-
- present paginate(user_project.deployments), with: ::API::V3::Deployments
- end
-
- desc 'Gets a specific deployment' do
- detail 'This feature was introduced in GitLab 8.11.'
- success ::API::V3::Deployments
- end
- params do
- requires :deployment_id, type: Integer, desc: 'The deployment ID'
- end
- get ':id/deployments/:deployment_id' do
- authorize! :read_deployment, user_project
-
- deployment = user_project.deployments.find(params[:deployment_id])
-
- present deployment, with: ::API::V3::Deployments
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/entities.rb b/lib/api/v3/entities.rb
deleted file mode 100644
index 68b4d7c3982..00000000000
--- a/lib/api/v3/entities.rb
+++ /dev/null
@@ -1,309 +0,0 @@
-module API
- module V3
- module Entities
- class ProjectSnippet < Grape::Entity
- expose :id, :title, :file_name
- expose :author, using: ::API::Entities::UserBasic
- expose :updated_at, :created_at
- expose(:expires_at) { |snippet| nil }
-
- expose :web_url do |snippet, options|
- Gitlab::UrlBuilder.build(snippet)
- end
- end
-
- class Note < Grape::Entity
- expose :id
- expose :note, as: :body
- expose :attachment_identifier, as: :attachment
- expose :author, using: ::API::Entities::UserBasic
- expose :created_at, :updated_at
- expose :system?, as: :system
- expose :noteable_id, :noteable_type
- # upvote? and downvote? are deprecated, always return false
- expose(:upvote?) { |note| false }
- expose(:downvote?) { |note| false }
- end
-
- class PushEventPayload < Grape::Entity
- expose :commit_count, :action, :ref_type, :commit_from, :commit_to
- expose :ref, :commit_title
- end
-
- class Event < Grape::Entity
- expose :project_id, :action_name
- expose :target_id, :target_type, :author_id
- expose :target_title
- expose :created_at
- expose :note, using: Entities::Note, if: ->(event, options) { event.note? }
- expose :author, using: ::API::Entities::UserBasic, if: ->(event, options) { event.author }
-
- expose :push_event_payload,
- as: :push_data,
- using: PushEventPayload,
- if: -> (event, _) { event.push? }
-
- expose :author_username do |event, options|
- event.author&.username
- end
- end
-
- class AwardEmoji < Grape::Entity
- expose :id
- expose :name
- expose :user, using: ::API::Entities::UserBasic
- expose :created_at, :updated_at
- expose :awardable_id, :awardable_type
- end
-
- class Project < Grape::Entity
- expose :id, :description, :default_branch, :tag_list
- expose :public?, as: :public
- expose :archived?, as: :archived
- expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url
- expose :owner, using: ::API::Entities::UserBasic, unless: ->(project, options) { project.group }
- expose :name, :name_with_namespace
- expose :path, :path_with_namespace
- expose :resolve_outdated_diff_discussions
- expose :container_registry_enabled
-
- # Expose old field names with the new permissions methods to keep API compatible
- expose(:issues_enabled) { |project, options| project.feature_available?(:issues, options[:current_user]) }
- expose(:merge_requests_enabled) { |project, options| project.feature_available?(:merge_requests, options[:current_user]) }
- expose(:wiki_enabled) { |project, options| project.feature_available?(:wiki, options[:current_user]) }
- expose(:builds_enabled) { |project, options| project.feature_available?(:builds, options[:current_user]) }
- expose(:snippets_enabled) { |project, options| project.feature_available?(:snippets, options[:current_user]) }
-
- expose :created_at, :last_activity_at
- expose :shared_runners_enabled
- expose :lfs_enabled?, as: :lfs_enabled
- expose :creator_id
- expose :namespace, using: 'API::Entities::Namespace'
- expose :forked_from_project, using: ::API::Entities::BasicProjectDetails, if: lambda { |project, options| project.forked? }
- expose :avatar_url do |user, options|
- user.avatar_url(only_path: false)
- end
- expose :star_count, :forks_count
- expose :open_issues_count, if: lambda { |project, options| project.feature_available?(:issues, options[:current_user]) && project.default_issues_tracker? }
- expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] }
- expose :public_builds
- expose :shared_with_groups do |project, options|
- ::API::Entities::SharedGroup.represent(project.project_group_links.all, options)
- end
- expose :only_allow_merge_if_pipeline_succeeds, as: :only_allow_merge_if_build_succeeds
- expose :request_access_enabled
- expose :only_allow_merge_if_all_discussions_are_resolved
-
- expose :statistics, using: '::API::V3::Entities::ProjectStatistics', if: :statistics
- end
-
- class ProjectWithAccess < Project
- expose :permissions do
- expose :project_access, using: ::API::Entities::ProjectAccess do |project, options|
- project.project_members.find_by(user_id: options[:current_user].id)
- end
-
- expose :group_access, using: ::API::Entities::GroupAccess do |project, options|
- if project.group
- project.group.group_members.find_by(user_id: options[:current_user].id)
- end
- end
- end
- end
-
- class MergeRequest < Grape::Entity
- expose :id, :iid
- expose(:project_id) { |entity| entity.project.id }
- expose :title, :description
- expose :state, :created_at, :updated_at
- expose :target_branch, :source_branch
- expose :upvotes, :downvotes
- expose :author, :assignee, using: ::API::Entities::UserBasic
- expose :source_project_id, :target_project_id
- expose :label_names, as: :labels
- expose :work_in_progress?, as: :work_in_progress
- expose :milestone, using: ::API::Entities::Milestone
- expose :merge_when_pipeline_succeeds, as: :merge_when_build_succeeds
- expose :merge_status
- expose :diff_head_sha, as: :sha
- expose :merge_commit_sha
- expose :subscribed do |merge_request, options|
- merge_request.subscribed?(options[:current_user], options[:project])
- end
- expose :user_notes_count
- expose :should_remove_source_branch?, as: :should_remove_source_branch
- expose :force_remove_source_branch?, as: :force_remove_source_branch
-
- expose :web_url do |merge_request, options|
- Gitlab::UrlBuilder.build(merge_request)
- end
- end
-
- class Group < Grape::Entity
- expose :id, :name, :path, :description, :visibility_level
- expose :lfs_enabled?, as: :lfs_enabled
- expose :avatar_url do |user, options|
- user.avatar_url(only_path: false)
- end
- expose :web_url
- expose :request_access_enabled
- expose :full_name, :full_path
-
- if ::Group.supports_nested_groups?
- expose :parent_id
- end
-
- expose :statistics, if: :statistics do
- with_options format_with: -> (value) { value.to_i } do
- expose :storage_size
- expose :repository_size
- expose :lfs_objects_size
- expose :build_artifacts_size
- end
- end
- end
-
- class GroupDetail < Group
- expose :projects, using: Entities::Project
- expose :shared_projects, using: Entities::Project
- end
-
- class ApplicationSetting < Grape::Entity
- expose :id
- expose :default_projects_limit
- expose :signup_enabled
- expose :password_authentication_enabled_for_web, as: :password_authentication_enabled
- expose :password_authentication_enabled_for_web, as: :signin_enabled
- expose :gravatar_enabled
- expose :sign_in_text
- expose :after_sign_up_text
- expose :created_at
- expose :updated_at
- expose :home_page_url
- expose :default_branch_protection
- expose :restricted_visibility_levels
- expose :max_attachment_size
- expose :session_expire_delay
- expose :default_project_visibility
- expose :default_snippet_visibility
- expose :default_group_visibility
- expose :domain_whitelist
- expose :domain_blacklist_enabled
- expose :domain_blacklist
- expose :user_oauth_applications
- expose :after_sign_out_path
- expose :container_registry_token_expire_delay
- expose :repository_storage
- expose :repository_storages
- expose :koding_enabled
- expose :koding_url
- expose :plantuml_enabled
- expose :plantuml_url
- expose :terminal_max_session_time
- end
-
- class Environment < ::API::Entities::EnvironmentBasic
- expose :project, using: Entities::Project
- end
-
- class Trigger < Grape::Entity
- expose :token, :created_at, :updated_at, :last_used
- expose :owner, using: ::API::Entities::UserBasic
- end
-
- class TriggerRequest < Grape::Entity
- expose :id, :variables
- end
-
- class Build < Grape::Entity
- expose :id, :status, :stage, :name, :ref, :tag, :coverage
- expose :created_at, :started_at, :finished_at
- expose :user, with: ::API::Entities::User
- expose :artifacts_file, using: ::API::Entities::JobArtifactFile, if: -> (build, opts) { build.artifacts? }
- expose :commit, with: ::API::Entities::Commit
- expose :runner, with: ::API::Entities::Runner
- expose :pipeline, with: ::API::Entities::PipelineBasic
- end
-
- class BuildArtifactFile < Grape::Entity
- expose :filename, :size
- end
-
- class Deployment < Grape::Entity
- expose :id, :iid, :ref, :sha, :created_at
- expose :user, using: ::API::Entities::UserBasic
- expose :environment, using: ::API::Entities::EnvironmentBasic
- expose :deployable, using: Entities::Build
- end
-
- class MergeRequestChanges < MergeRequest
- expose :diffs, as: :changes, using: ::API::Entities::Diff do |compare, _|
- compare.raw_diffs(limits: false).to_a
- end
- end
-
- class ProjectStatistics < Grape::Entity
- expose :commit_count
- expose :storage_size
- expose :repository_size
- expose :lfs_objects_size
- expose :build_artifacts_size
- end
-
- class ProjectService < Grape::Entity
- expose :id, :title, :created_at, :updated_at, :active
- expose :push_events, :issues_events, :confidential_issues_events
- expose :merge_requests_events, :tag_push_events, :note_events
- expose :pipeline_events
- expose :job_events, as: :build_events
- # Expose serialized properties
- expose :properties do |service, options|
- service.properties.slice(*service.api_field_names)
- end
- end
-
- class ProjectHook < ::API::Entities::Hook
- expose :project_id, :issues_events, :confidential_issues_events
- expose :merge_requests_events, :note_events, :pipeline_events
- expose :wiki_page_events
- expose :job_events, as: :build_events
- end
-
- class ProjectEntity < Grape::Entity
- expose :id, :iid
- expose(:project_id) { |entity| entity&.project.try(:id) }
- expose :title, :description
- expose :state, :created_at, :updated_at
- end
-
- class IssueBasic < ProjectEntity
- expose :label_names, as: :labels
- expose :milestone, using: ::API::Entities::Milestone
- expose :assignees, :author, using: ::API::Entities::UserBasic
-
- expose :assignee, using: ::API::Entities::UserBasic do |issue, options|
- issue.assignees.first
- end
-
- expose :user_notes_count
- expose :upvotes, :downvotes
- expose :due_date
- expose :confidential
-
- expose :web_url do |issue, options|
- Gitlab::UrlBuilder.build(issue)
- end
- end
-
- class Issue < IssueBasic
- unexpose :assignees
- expose :assignee do |issue, options|
- ::API::Entities::UserBasic.represent(issue.assignees.first, options)
- end
- expose :subscribed do |issue, options|
- issue.subscribed?(options[:current_user], options[:project] || issue.project)
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/environments.rb b/lib/api/v3/environments.rb
deleted file mode 100644
index 6bb4e016a01..00000000000
--- a/lib/api/v3/environments.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-module API
- module V3
- class Environments < Grape::API
- include ::API::Helpers::CustomValidators
- include PaginationParams
-
- before { authenticate! }
-
- params do
- requires :id, type: String, desc: 'The project ID'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Get all environments of the project' do
- detail 'This feature was introduced in GitLab 8.11.'
- success Entities::Environment
- end
- params do
- use :pagination
- end
- get ':id/environments' do
- authorize! :read_environment, user_project
-
- present paginate(user_project.environments), with: Entities::Environment
- end
-
- desc 'Creates a new environment' do
- detail 'This feature was introduced in GitLab 8.11.'
- success Entities::Environment
- end
- params do
- requires :name, type: String, desc: 'The name of the environment to be created'
- optional :external_url, type: String, desc: 'URL on which this deployment is viewable'
- optional :slug, absence: { message: "is automatically generated and cannot be changed" }
- end
- post ':id/environments' do
- authorize! :create_environment, user_project
-
- environment = user_project.environments.create(declared_params)
-
- if environment.persisted?
- present environment, with: Entities::Environment
- else
- render_validation_error!(environment)
- end
- end
-
- desc 'Updates an existing environment' do
- detail 'This feature was introduced in GitLab 8.11.'
- success Entities::Environment
- end
- params do
- requires :environment_id, type: Integer, desc: 'The environment ID'
- optional :name, type: String, desc: 'The new environment name'
- optional :external_url, type: String, desc: 'The new URL on which this deployment is viewable'
- optional :slug, absence: { message: "is automatically generated and cannot be changed" }
- end
- put ':id/environments/:environment_id' do
- authorize! :update_environment, user_project
-
- environment = user_project.environments.find(params[:environment_id])
-
- update_params = declared_params(include_missing: false).extract!(:name, :external_url)
- if environment.update(update_params)
- present environment, with: Entities::Environment
- else
- render_validation_error!(environment)
- end
- end
-
- desc 'Deletes an existing environment' do
- detail 'This feature was introduced in GitLab 8.11.'
- success Entities::Environment
- end
- params do
- requires :environment_id, type: Integer, desc: 'The environment ID'
- end
- delete ':id/environments/:environment_id' do
- authorize! :update_environment, user_project
-
- environment = user_project.environments.find(params[:environment_id])
-
- present environment.destroy, with: Entities::Environment
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/files.rb b/lib/api/v3/files.rb
deleted file mode 100644
index 7b4b3448b6d..00000000000
--- a/lib/api/v3/files.rb
+++ /dev/null
@@ -1,138 +0,0 @@
-module API
- module V3
- class Files < Grape::API
- helpers do
- def commit_params(attrs)
- {
- file_path: attrs[:file_path],
- start_branch: attrs[:branch],
- branch_name: attrs[:branch],
- commit_message: attrs[:commit_message],
- file_content: attrs[:content],
- file_content_encoding: attrs[:encoding],
- author_email: attrs[:author_email],
- author_name: attrs[:author_name]
- }
- end
-
- def commit_response(attrs)
- {
- file_path: attrs[:file_path],
- branch: attrs[:branch]
- }
- end
-
- params :simple_file_params do
- requires :file_path, type: String, desc: 'The path to new file. Ex. lib/class.rb'
- requires :branch_name, type: String, desc: 'The name of branch'
- requires :commit_message, type: String, desc: 'Commit Message'
- optional :author_email, type: String, desc: 'The email of the author'
- optional :author_name, type: String, desc: 'The name of the author'
- end
-
- params :extended_file_params do
- use :simple_file_params
- requires :content, type: String, desc: 'File content'
- optional :encoding, type: String, values: %w[base64], desc: 'File encoding'
- end
- end
-
- params do
- requires :id, type: String, desc: 'The project ID'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Get a file from repository'
- params do
- requires :file_path, type: String, desc: 'The path to the file. Ex. lib/class.rb'
- requires :ref, type: String, desc: 'The name of branch, tag, or commit'
- end
- get ":id/repository/files" do
- authorize! :download_code, user_project
-
- commit = user_project.commit(params[:ref])
- not_found!('Commit') unless commit
-
- repo = user_project.repository
- blob = repo.blob_at(commit.sha, params[:file_path])
- not_found!('File') unless blob
-
- blob.load_all_data!
- status(200)
-
- {
- file_name: blob.name,
- file_path: blob.path,
- size: blob.size,
- encoding: "base64",
- content: Base64.strict_encode64(blob.data),
- ref: params[:ref],
- blob_id: blob.id,
- commit_id: commit.id,
- last_commit_id: repo.last_commit_id_for_path(commit.sha, params[:file_path])
- }
- end
-
- desc 'Create new file in repository'
- params do
- use :extended_file_params
- end
- post ":id/repository/files" do
- authorize! :push_code, user_project
-
- file_params = declared_params(include_missing: false)
- file_params[:branch] = file_params.delete(:branch_name)
-
- result = ::Files::CreateService.new(user_project, current_user, commit_params(file_params)).execute
-
- if result[:status] == :success
- status(201)
- commit_response(file_params)
- else
- render_api_error!(result[:message], 400)
- end
- end
-
- desc 'Update existing file in repository'
- params do
- use :extended_file_params
- end
- put ":id/repository/files" do
- authorize! :push_code, user_project
-
- file_params = declared_params(include_missing: false)
- file_params[:branch] = file_params.delete(:branch_name)
-
- result = ::Files::UpdateService.new(user_project, current_user, commit_params(file_params)).execute
-
- if result[:status] == :success
- status(200)
- commit_response(file_params)
- else
- http_status = result[:http_status] || 400
- render_api_error!(result[:message], http_status)
- end
- end
-
- desc 'Delete an existing file in repository'
- params do
- use :simple_file_params
- end
- delete ":id/repository/files" do
- authorize! :push_code, user_project
-
- file_params = declared_params(include_missing: false)
- file_params[:branch] = file_params.delete(:branch_name)
-
- result = ::Files::DeleteService.new(user_project, current_user, commit_params(file_params)).execute
-
- if result[:status] == :success
- status(200)
- commit_response(file_params)
- else
- render_api_error!(result[:message], 400)
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/groups.rb b/lib/api/v3/groups.rb
deleted file mode 100644
index 4fa7d196e50..00000000000
--- a/lib/api/v3/groups.rb
+++ /dev/null
@@ -1,187 +0,0 @@
-module API
- module V3
- class Groups < Grape::API
- include PaginationParams
-
- before { authenticate! }
-
- helpers do
- params :optional_params do
- optional :description, type: String, desc: 'The description of the group'
- optional :visibility_level, type: Integer, desc: 'The visibility level of the group'
- optional :lfs_enabled, type: Boolean, desc: 'Enable/disable LFS for the projects in this group'
- optional :request_access_enabled, type: Boolean, desc: 'Allow users to request member access'
- end
-
- params :statistics_params do
- optional :statistics, type: Boolean, default: false, desc: 'Include project statistics'
- end
-
- def present_groups(groups, options = {})
- options = options.reverse_merge(
- with: Entities::Group,
- current_user: current_user
- )
-
- groups = groups.with_statistics if options[:statistics]
- present paginate(groups), options
- end
- end
-
- resource :groups do
- desc 'Get a groups list' do
- success Entities::Group
- end
- params do
- use :statistics_params
- optional :skip_groups, type: Array[Integer], desc: 'Array of group ids to exclude from list'
- optional :all_available, type: Boolean, desc: 'Show all group that you have access to'
- optional :search, type: String, desc: 'Search for a specific group'
- optional :order_by, type: String, values: %w[name path], default: 'name', desc: 'Order by name or path'
- optional :sort, type: String, values: %w[asc desc], default: 'asc', desc: 'Sort by asc (ascending) or desc (descending)'
- use :pagination
- end
- get do
- groups = if current_user.admin
- Group.all
- elsif params[:all_available]
- GroupsFinder.new(current_user).execute
- else
- current_user.groups
- end
-
- groups = groups.search(params[:search]) if params[:search].present?
- groups = groups.where.not(id: params[:skip_groups]) if params[:skip_groups].present?
- groups = groups.reorder(params[:order_by] => params[:sort])
-
- present_groups groups, statistics: params[:statistics] && current_user.admin?
- end
-
- desc 'Get list of owned groups for authenticated user' do
- success Entities::Group
- end
- params do
- use :pagination
- use :statistics_params
- end
- get '/owned' do
- present_groups current_user.owned_groups, statistics: params[:statistics]
- end
-
- desc 'Create a group. Available only for users who can create groups.' do
- success Entities::Group
- end
- params do
- requires :name, type: String, desc: 'The name of the group'
- requires :path, type: String, desc: 'The path of the group'
-
- if ::Group.supports_nested_groups?
- optional :parent_id, type: Integer, desc: 'The parent group id for creating nested group'
- end
-
- use :optional_params
- end
- post do
- authorize! :create_group
-
- group = ::Groups::CreateService.new(current_user, declared_params(include_missing: false)).execute
-
- if group.persisted?
- present group, with: Entities::Group, current_user: current_user
- else
- render_api_error!("Failed to save group #{group.errors.messages}", 400)
- end
- end
- end
-
- params do
- requires :id, type: String, desc: 'The ID of a group'
- end
- resource :groups, requirements: { id: %r{[^/]+} } do
- desc 'Update a group. Available only for users who can administrate groups.' do
- success Entities::Group
- end
- params do
- optional :name, type: String, desc: 'The name of the group'
- optional :path, type: String, desc: 'The path of the group'
- use :optional_params
- at_least_one_of :name, :path, :description, :visibility_level,
- :lfs_enabled, :request_access_enabled
- end
- put ':id' do
- group = find_group!(params[:id])
- authorize! :admin_group, group
-
- if ::Groups::UpdateService.new(group, current_user, declared_params(include_missing: false)).execute
- present group, with: Entities::GroupDetail, current_user: current_user
- else
- render_validation_error!(group)
- end
- end
-
- desc 'Get a single group, with containing projects.' do
- success Entities::GroupDetail
- end
- get ":id" do
- group = find_group!(params[:id])
- present group, with: Entities::GroupDetail, current_user: current_user
- end
-
- desc 'Remove a group.'
- delete ":id" do
- group = find_group!(params[:id])
- authorize! :admin_group, group
- ::Groups::DestroyService.new(group, current_user).async_execute
-
- accepted!
- end
-
- desc 'Get a list of projects in this group.' do
- success Entities::Project
- end
- params do
- optional :archived, type: Boolean, default: false, desc: 'Limit by archived status'
- optional :visibility, type: String, values: %w[public internal private],
- desc: 'Limit by visibility'
- optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria'
- optional :order_by, type: String, values: %w[id name path created_at updated_at last_activity_at],
- default: 'created_at', desc: 'Return projects ordered by field'
- optional :sort, type: String, values: %w[asc desc], default: 'desc',
- desc: 'Return projects sorted in ascending and descending order'
- optional :simple, type: Boolean, default: false,
- desc: 'Return only the ID, URL, name, and path of each project'
- optional :owned, type: Boolean, default: false, desc: 'Limit by owned by authenticated user'
- optional :starred, type: Boolean, default: false, desc: 'Limit by starred status'
-
- use :pagination
- end
- get ":id/projects" do
- group = find_group!(params[:id])
- projects = GroupProjectsFinder.new(group: group, current_user: current_user).execute
- projects = filter_projects(projects)
- entity = params[:simple] ? ::API::Entities::BasicProjectDetails : Entities::Project
- present paginate(projects), with: entity, current_user: current_user
- end
-
- desc 'Transfer a project to the group namespace. Available only for admin.' do
- success Entities::GroupDetail
- end
- params do
- requires :project_id, type: String, desc: 'The ID or path of the project'
- end
- post ":id/projects/:project_id", requirements: { project_id: /.+/ } do
- authenticated_as_admin!
- group = find_group!(params[:id])
- project = find_project!(params[:project_id])
- result = ::Projects::TransferService.new(project, current_user).execute(group)
-
- if result
- present group, with: Entities::GroupDetail, current_user: current_user
- else
- render_api_error!("Failed to transfer project #{project.errors.messages}", 400)
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/helpers.rb b/lib/api/v3/helpers.rb
deleted file mode 100644
index 4e63aa01c1a..00000000000
--- a/lib/api/v3/helpers.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-module API
- module V3
- module Helpers
- def find_project_issue(id)
- IssuesFinder.new(current_user, project_id: user_project.id).find(id)
- end
-
- def find_project_merge_request(id)
- MergeRequestsFinder.new(current_user, project_id: user_project.id).find(id)
- end
-
- def find_merge_request_with_access(id, access_level = :read_merge_request)
- merge_request = user_project.merge_requests.find(id)
- authorize! access_level, merge_request
- merge_request
- end
-
- # project helpers
-
- def filter_projects(projects)
- if params[:membership]
- projects = projects.merge(current_user.authorized_projects)
- end
-
- if params[:owned]
- projects = projects.merge(current_user.owned_projects)
- end
-
- if params[:starred]
- projects = projects.merge(current_user.starred_projects)
- end
-
- if params[:search].present?
- projects = projects.search(params[:search])
- end
-
- if params[:visibility].present?
- projects = projects.where(visibility_level: Gitlab::VisibilityLevel.level_value(params[:visibility]))
- end
-
- unless params[:archived].nil?
- projects = projects.where(archived: to_boolean(params[:archived]))
- end
-
- projects.reorder(params[:order_by] => params[:sort])
- end
- end
- end
-end
diff --git a/lib/api/v3/issues.rb b/lib/api/v3/issues.rb
deleted file mode 100644
index b59947d81d9..00000000000
--- a/lib/api/v3/issues.rb
+++ /dev/null
@@ -1,240 +0,0 @@
-module API
- module V3
- class Issues < Grape::API
- include PaginationParams
-
- before { authenticate! }
-
- helpers do
- def find_issues(args = {})
- args = params.merge(args)
- args = convert_parameters_from_legacy_format(args)
-
- args.delete(:id)
- args[:milestone_title] = args.delete(:milestone)
-
- match_all_labels = args.delete(:match_all_labels)
- labels = args.delete(:labels)
- args[:label_name] = labels if match_all_labels
-
- # IssuesFinder expects iids
- args[:iids] = args.delete(:iid) if args.key?(:iid)
-
- issues = IssuesFinder.new(current_user, args).execute.inc_notes_with_associations
-
- if !match_all_labels && labels.present?
- issues = issues.includes(:labels).where('labels.title' => labels.split(','))
- end
-
- issues.reorder(args[:order_by] => args[:sort])
- end
-
- params :issues_params do
- optional :labels, type: String, desc: 'Comma-separated list of label names'
- optional :milestone, type: String, desc: 'Milestone title'
- optional :order_by, type: String, values: %w[created_at updated_at], default: 'created_at',
- desc: 'Return issues ordered by `created_at` or `updated_at` fields.'
- optional :sort, type: String, values: %w[asc desc], default: 'desc',
- desc: 'Return issues sorted in `asc` or `desc` order.'
- optional :milestone, type: String, desc: 'Return issues for a specific milestone'
- use :pagination
- end
-
- params :issue_params do
- optional :description, type: String, desc: 'The description of an issue'
- optional :assignee_id, type: Integer, desc: 'The ID of a user to assign issue'
- optional :milestone_id, type: Integer, desc: 'The ID of a milestone to assign issue'
- optional :labels, type: String, desc: 'Comma-separated list of label names'
- optional :due_date, type: String, desc: 'Date time string in the format YEAR-MONTH-DAY'
- optional :confidential, type: Boolean, desc: 'Boolean parameter if the issue should be confidential'
- end
- end
-
- resource :issues do
- desc "Get currently authenticated user's issues" do
- success ::API::V3::Entities::Issue
- end
- params do
- optional :state, type: String, values: %w[opened closed all], default: 'all',
- desc: 'Return opened, closed, or all issues'
- use :issues_params
- end
- get do
- issues = find_issues(scope: 'authored')
-
- present paginate(issues), with: ::API::V3::Entities::Issue, current_user: current_user
- end
- end
-
- params do
- requires :id, type: String, desc: 'The ID of a group'
- end
- resource :groups, requirements: { id: %r{[^/]+} } do
- desc 'Get a list of group issues' do
- success ::API::V3::Entities::Issue
- end
- params do
- optional :state, type: String, values: %w[opened closed all], default: 'all',
- desc: 'Return opened, closed, or all issues'
- use :issues_params
- end
- get ":id/issues" do
- group = find_group!(params[:id])
-
- issues = find_issues(group_id: group.id, match_all_labels: true)
-
- present paginate(issues), with: ::API::V3::Entities::Issue, current_user: current_user
- end
- end
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- include TimeTrackingEndpoints
-
- desc 'Get a list of project issues' do
- detail 'iid filter is deprecated have been removed on V4'
- success ::API::V3::Entities::Issue
- end
- params do
- optional :state, type: String, values: %w[opened closed all], default: 'all',
- desc: 'Return opened, closed, or all issues'
- optional :iid, type: Integer, desc: 'Return the issue having the given `iid`'
- use :issues_params
- end
- get ":id/issues" do
- project = find_project!(params[:id])
-
- issues = find_issues(project_id: project.id)
-
- present paginate(issues), with: ::API::V3::Entities::Issue, current_user: current_user, project: user_project
- end
-
- desc 'Get a single project issue' do
- success ::API::V3::Entities::Issue
- end
- params do
- requires :issue_id, type: Integer, desc: 'The ID of a project issue'
- end
- get ":id/issues/:issue_id" do
- issue = find_project_issue(params[:issue_id])
- present issue, with: ::API::V3::Entities::Issue, current_user: current_user, project: user_project
- end
-
- desc 'Create a new project issue' do
- success ::API::V3::Entities::Issue
- end
- params do
- requires :title, type: String, desc: 'The title of an issue'
- optional :created_at, type: DateTime,
- desc: 'Date time when the issue was created. Available only for admins and project owners.'
- optional :merge_request_for_resolving_discussions, type: Integer,
- desc: 'The IID of a merge request for which to resolve discussions'
- use :issue_params
- end
- post ':id/issues' do
- Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42131')
-
- # Setting created_at time only allowed for admins and project owners
- unless current_user.admin? || user_project.owner == current_user
- params.delete(:created_at)
- end
-
- issue_params = declared_params(include_missing: false)
- issue_params = issue_params.merge(merge_request_to_resolve_discussions_of: issue_params.delete(:merge_request_for_resolving_discussions))
- issue_params = convert_parameters_from_legacy_format(issue_params)
-
- issue = ::Issues::CreateService.new(user_project,
- current_user,
- issue_params.merge(request: request, api: true)).execute
- render_spam_error! if issue.spam?
-
- if issue.valid?
- present issue, with: ::API::V3::Entities::Issue, current_user: current_user, project: user_project
- else
- render_validation_error!(issue)
- end
- end
-
- desc 'Update an existing issue' do
- success ::API::V3::Entities::Issue
- end
- params do
- requires :issue_id, type: Integer, desc: 'The ID of a project issue'
- optional :title, type: String, desc: 'The title of an issue'
- optional :updated_at, type: DateTime,
- desc: 'Date time when the issue was updated. Available only for admins and project owners.'
- optional :state_event, type: String, values: %w[reopen close], desc: 'State of the issue'
- use :issue_params
- at_least_one_of :title, :description, :assignee_id, :milestone_id,
- :labels, :created_at, :due_date, :confidential, :state_event
- end
- put ':id/issues/:issue_id' do
- Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42132')
-
- issue = user_project.issues.find(params.delete(:issue_id))
- authorize! :update_issue, issue
-
- # Setting created_at time only allowed for admins and project owners
- unless current_user.admin? || user_project.owner == current_user
- params.delete(:updated_at)
- end
-
- update_params = declared_params(include_missing: false).merge(request: request, api: true)
- update_params = convert_parameters_from_legacy_format(update_params)
-
- issue = ::Issues::UpdateService.new(user_project,
- current_user,
- update_params).execute(issue)
-
- render_spam_error! if issue.spam?
-
- if issue.valid?
- present issue, with: ::API::V3::Entities::Issue, current_user: current_user, project: user_project
- else
- render_validation_error!(issue)
- end
- end
-
- desc 'Move an existing issue' do
- success ::API::V3::Entities::Issue
- end
- params do
- requires :issue_id, type: Integer, desc: 'The ID of a project issue'
- requires :to_project_id, type: Integer, desc: 'The ID of the new project'
- end
- post ':id/issues/:issue_id/move' do
- Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42133')
-
- issue = user_project.issues.find_by(id: params[:issue_id])
- not_found!('Issue') unless issue
-
- new_project = Project.find_by(id: params[:to_project_id])
- not_found!('Project') unless new_project
-
- begin
- issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project)
- present issue, with: ::API::V3::Entities::Issue, current_user: current_user, project: user_project
- rescue ::Issues::MoveService::MoveError => error
- render_api_error!(error.message, 400)
- end
- end
-
- desc 'Delete a project issue'
- params do
- requires :issue_id, type: Integer, desc: 'The ID of a project issue'
- end
- delete ":id/issues/:issue_id" do
- issue = user_project.issues.find_by(id: params[:issue_id])
- not_found!('Issue') unless issue
-
- authorize!(:destroy_issue, issue)
-
- status(200)
- issue.destroy
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/labels.rb b/lib/api/v3/labels.rb
deleted file mode 100644
index 4157462ec2a..00000000000
--- a/lib/api/v3/labels.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-module API
- module V3
- class Labels < Grape::API
- before { authenticate! }
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Get all labels of the project' do
- success ::API::Entities::Label
- end
- get ':id/labels' do
- present available_labels_for(user_project), with: ::API::Entities::Label, current_user: current_user, project: user_project
- end
-
- desc 'Delete an existing label' do
- success ::API::Entities::Label
- end
- params do
- requires :name, type: String, desc: 'The name of the label to be deleted'
- end
- delete ':id/labels' do
- authorize! :admin_label, user_project
-
- label = user_project.labels.find_by(title: params[:name])
- not_found!('Label') unless label
-
- present label.destroy, with: ::API::Entities::Label, current_user: current_user, project: user_project
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/members.rb b/lib/api/v3/members.rb
deleted file mode 100644
index 88dd598f1e9..00000000000
--- a/lib/api/v3/members.rb
+++ /dev/null
@@ -1,136 +0,0 @@
-module API
- module V3
- class Members < Grape::API
- include PaginationParams
-
- before { authenticate! }
-
- helpers ::API::Helpers::MembersHelpers
-
- %w[group project].each do |source_type|
- params do
- requires :id, type: String, desc: "The #{source_type} ID"
- end
- resource source_type.pluralize, requirements: { id: %r{[^/]+} } do
- desc 'Gets a list of group or project members viewable by the authenticated user.' do
- success ::API::Entities::Member
- end
- params do
- optional :query, type: String, desc: 'A query string to search for members'
- use :pagination
- end
- get ":id/members" do
- source = find_source(source_type, params[:id])
-
- members = source.members.where.not(user_id: nil).includes(:user)
- members = members.joins(:user).merge(User.search(params[:query])) if params[:query].present?
- members = paginate(members)
-
- present members, with: ::API::Entities::Member
- end
-
- desc 'Gets a member of a group or project.' do
- success ::API::Entities::Member
- end
- params do
- requires :user_id, type: Integer, desc: 'The user ID of the member'
- end
- get ":id/members/:user_id" do
- source = find_source(source_type, params[:id])
-
- members = source.members
- member = members.find_by!(user_id: params[:user_id])
-
- present member, with: ::API::Entities::Member
- end
-
- desc 'Adds a member to a group or project.' do
- success ::API::Entities::Member
- end
- params do
- requires :user_id, type: Integer, desc: 'The user ID of the new member'
- requires :access_level, type: Integer, desc: 'A valid access level (defaults: `30`, developer access level)'
- optional :expires_at, type: DateTime, desc: 'Date string in the format YEAR-MONTH-DAY'
- end
- post ":id/members" do
- source = find_source(source_type, params[:id])
- authorize_admin_source!(source_type, source)
-
- member = source.members.find_by(user_id: params[:user_id])
-
- # We need this explicit check because `source.add_user` doesn't
- # currently return the member created so it would return 201 even if
- # the member already existed...
- # The `source_type == 'group'` check is to ensure back-compatibility
- # but 409 behavior should be used for both project and group members in 9.0!
- conflict!('Member already exists') if source_type == 'group' && member
-
- unless member
- member = source.add_user(params[:user_id], params[:access_level], current_user: current_user, expires_at: params[:expires_at])
- end
-
- if member.persisted? && member.valid?
- present member, with: ::API::Entities::Member
- else
- # This is to ensure back-compatibility but 400 behavior should be used
- # for all validation errors in 9.0!
- render_api_error!('Access level is not known', 422) if member.errors.key?(:access_level)
- render_validation_error!(member)
- end
- end
-
- desc 'Updates a member of a group or project.' do
- success ::API::Entities::Member
- end
- params do
- requires :user_id, type: Integer, desc: 'The user ID of the new member'
- requires :access_level, type: Integer, desc: 'A valid access level'
- optional :expires_at, type: DateTime, desc: 'Date string in the format YEAR-MONTH-DAY'
- end
- put ":id/members/:user_id" do
- source = find_source(source_type, params.delete(:id))
- authorize_admin_source!(source_type, source)
-
- member = source.members.find_by!(user_id: params.delete(:user_id))
-
- if member.update_attributes(declared_params(include_missing: false))
- present member, with: ::API::Entities::Member
- else
- # This is to ensure back-compatibility but 400 behavior should be used
- # for all validation errors in 9.0!
- render_api_error!('Access level is not known', 422) if member.errors.key?(:access_level)
- render_validation_error!(member)
- end
- end
-
- desc 'Removes a user from a group or project.'
- params do
- requires :user_id, type: Integer, desc: 'The user ID of the member'
- end
- delete ":id/members/:user_id" do
- source = find_source(source_type, params[:id])
-
- # This is to ensure back-compatibility but find_by! should be used
- # in that casse in 9.0!
- member = source.members.find_by(user_id: params[:user_id])
-
- # This is to ensure back-compatibility but this should be removed in
- # favor of find_by! in 9.0!
- not_found!("Member: user_id:#{params[:user_id]}") if source_type == 'group' && member.nil?
-
- # This is to ensure back-compatibility but 204 behavior should be used
- # for all DELETE endpoints in 9.0!
- if member.nil?
- status(200 )
- { message: "Access revoked", id: params[:user_id].to_i }
- else
- ::Members::DestroyService.new(current_user).execute(member)
-
- present member, with: ::API::Entities::Member
- end
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/merge_request_diffs.rb b/lib/api/v3/merge_request_diffs.rb
deleted file mode 100644
index 22866fc2845..00000000000
--- a/lib/api/v3/merge_request_diffs.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-module API
- module V3
- # MergeRequestDiff API
- class MergeRequestDiffs < Grape::API
- before { authenticate! }
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Get a list of merge request diff versions' do
- detail 'This feature was introduced in GitLab 8.12.'
- success ::API::Entities::MergeRequestDiff
- end
-
- params do
- requires :merge_request_id, type: Integer, desc: 'The ID of a merge request'
- end
-
- get ":id/merge_requests/:merge_request_id/versions" do
- merge_request = find_merge_request_with_access(params[:merge_request_id])
-
- present merge_request.merge_request_diffs.order_id_desc, with: ::API::Entities::MergeRequestDiff
- end
-
- desc 'Get a single merge request diff version' do
- detail 'This feature was introduced in GitLab 8.12.'
- success ::API::Entities::MergeRequestDiffFull
- end
-
- params do
- requires :merge_request_id, type: Integer, desc: 'The ID of a merge request'
- requires :version_id, type: Integer, desc: 'The ID of a merge request diff version'
- end
-
- get ":id/merge_requests/:merge_request_id/versions/:version_id" do
- merge_request = find_merge_request_with_access(params[:merge_request_id])
-
- present merge_request.merge_request_diffs.find(params[:version_id]), with: ::API::Entities::MergeRequestDiffFull
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/merge_requests.rb b/lib/api/v3/merge_requests.rb
deleted file mode 100644
index 9b0f70e2bfe..00000000000
--- a/lib/api/v3/merge_requests.rb
+++ /dev/null
@@ -1,297 +0,0 @@
-module API
- module V3
- class MergeRequests < Grape::API
- include PaginationParams
-
- DEPRECATION_MESSAGE = 'This endpoint is deprecated and has been removed on V4'.freeze
-
- before { authenticate! }
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- include TimeTrackingEndpoints
-
- helpers do
- def handle_merge_request_errors!(errors)
- if errors[:project_access].any?
- error!(errors[:project_access], 422)
- elsif errors[:branch_conflict].any?
- error!(errors[:branch_conflict], 422)
- elsif errors[:validate_fork].any?
- error!(errors[:validate_fork], 422)
- elsif errors[:validate_branches].any?
- conflict!(errors[:validate_branches])
- elsif errors[:base].any?
- error!(errors[:base], 422)
- end
-
- render_api_error!(errors, 400)
- end
-
- def issue_entity(project)
- if project.has_external_issue_tracker?
- ::API::Entities::ExternalIssue
- else
- ::API::V3::Entities::Issue
- end
- end
-
- params :optional_params do
- optional :description, type: String, desc: 'The description of the merge request'
- optional :assignee_id, type: Integer, desc: 'The ID of a user to assign the merge request'
- optional :milestone_id, type: Integer, desc: 'The ID of a milestone to assign the merge request'
- optional :labels, type: String, desc: 'Comma-separated list of label names'
- optional :remove_source_branch, type: Boolean, desc: 'Remove source branch when merging'
- end
- end
-
- desc 'List merge requests' do
- detail 'iid filter is deprecated have been removed on V4'
- success ::API::V3::Entities::MergeRequest
- end
- params do
- optional :state, type: String, values: %w[opened closed merged all], default: 'all',
- desc: 'Return opened, closed, merged, or all merge requests'
- optional :order_by, type: String, values: %w[created_at updated_at], default: 'created_at',
- desc: 'Return merge requests ordered by `created_at` or `updated_at` fields.'
- optional :sort, type: String, values: %w[asc desc], default: 'desc',
- desc: 'Return merge requests sorted in `asc` or `desc` order.'
- optional :iid, type: Array[Integer], desc: 'The IID of the merge requests'
- use :pagination
- end
- get ":id/merge_requests" do
- authorize! :read_merge_request, user_project
-
- merge_requests = user_project.merge_requests.inc_notes_with_associations
- merge_requests = filter_by_iid(merge_requests, params[:iid]) if params[:iid].present?
-
- merge_requests =
- case params[:state]
- when 'opened' then merge_requests.opened
- when 'closed' then merge_requests.closed
- when 'merged' then merge_requests.merged
- else merge_requests
- end
-
- merge_requests = merge_requests.reorder(params[:order_by] => params[:sort])
- present paginate(merge_requests), with: ::API::V3::Entities::MergeRequest, current_user: current_user, project: user_project
- end
-
- desc 'Create a merge request' do
- success ::API::V3::Entities::MergeRequest
- end
- params do
- requires :title, type: String, desc: 'The title of the merge request'
- requires :source_branch, type: String, desc: 'The source branch'
- requires :target_branch, type: String, desc: 'The target branch'
- optional :target_project_id, type: Integer,
- desc: 'The target project of the merge request defaults to the :id of the project'
- use :optional_params
- end
- post ":id/merge_requests" do
- Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42126')
-
- authorize! :create_merge_request_from, user_project
-
- mr_params = declared_params(include_missing: false)
- mr_params[:force_remove_source_branch] = mr_params.delete(:remove_source_branch) if mr_params[:remove_source_branch].present?
-
- merge_request = ::MergeRequests::CreateService.new(user_project, current_user, mr_params).execute
-
- if merge_request.valid?
- present merge_request, with: ::API::V3::Entities::MergeRequest, current_user: current_user, project: user_project
- else
- handle_merge_request_errors! merge_request.errors
- end
- end
-
- desc 'Delete a merge request'
- params do
- requires :merge_request_id, type: Integer, desc: 'The ID of a merge request'
- end
- delete ":id/merge_requests/:merge_request_id" do
- merge_request = find_project_merge_request(params[:merge_request_id])
-
- authorize!(:destroy_merge_request, merge_request)
-
- status(200)
- merge_request.destroy
- end
-
- params do
- requires :merge_request_id, type: Integer, desc: 'The ID of a merge request'
- end
- { ":id/merge_request/:merge_request_id" => :deprecated, ":id/merge_requests/:merge_request_id" => :ok }.each do |path, status|
- desc 'Get a single merge request' do
- if status == :deprecated
- detail DEPRECATION_MESSAGE
- end
-
- success ::API::V3::Entities::MergeRequest
- end
- get path do
- merge_request = find_merge_request_with_access(params[:merge_request_id])
-
- present merge_request, with: ::API::V3::Entities::MergeRequest, current_user: current_user, project: user_project
- end
-
- desc 'Get the commits of a merge request' do
- success ::API::Entities::Commit
- end
- get "#{path}/commits" do
- merge_request = find_merge_request_with_access(params[:merge_request_id])
-
- present merge_request.commits, with: ::API::Entities::Commit
- end
-
- desc 'Show the merge request changes' do
- success ::API::Entities::MergeRequestChanges
- end
- get "#{path}/changes" do
- merge_request = find_merge_request_with_access(params[:merge_request_id])
-
- present merge_request, with: ::API::Entities::MergeRequestChanges, current_user: current_user
- end
-
- desc 'Update a merge request' do
- success ::API::V3::Entities::MergeRequest
- end
- params do
- optional :title, type: String, allow_blank: false, desc: 'The title of the merge request'
- optional :target_branch, type: String, allow_blank: false, desc: 'The target branch'
- optional :state_event, type: String, values: %w[close reopen merge],
- desc: 'Status of the merge request'
- use :optional_params
- at_least_one_of :title, :target_branch, :description, :assignee_id,
- :milestone_id, :labels, :state_event,
- :remove_source_branch
- end
- put path do
- Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42127')
-
- merge_request = find_merge_request_with_access(params.delete(:merge_request_id), :update_merge_request)
-
- mr_params = declared_params(include_missing: false)
- mr_params[:force_remove_source_branch] = mr_params.delete(:remove_source_branch) if mr_params[:remove_source_branch].present?
-
- merge_request = ::MergeRequests::UpdateService.new(user_project, current_user, mr_params).execute(merge_request)
-
- if merge_request.valid?
- present merge_request, with: ::API::V3::Entities::MergeRequest, current_user: current_user, project: user_project
- else
- handle_merge_request_errors! merge_request.errors
- end
- end
-
- desc 'Merge a merge request' do
- success ::API::V3::Entities::MergeRequest
- end
- params do
- optional :merge_commit_message, type: String, desc: 'Custom merge commit message'
- optional :should_remove_source_branch, type: Boolean,
- desc: 'When true, the source branch will be deleted if possible'
- optional :merge_when_build_succeeds, type: Boolean,
- desc: 'When true, this merge request will be merged when the build succeeds'
- optional :sha, type: String, desc: 'When present, must have the HEAD SHA of the source branch'
- end
- put "#{path}/merge" do
- merge_request = find_project_merge_request(params[:merge_request_id])
-
- # Merge request can not be merged
- # because user dont have permissions to push into target branch
- unauthorized! unless merge_request.can_be_merged_by?(current_user)
-
- not_allowed! unless merge_request.mergeable_state?
-
- render_api_error!('Branch cannot be merged', 406) unless merge_request.mergeable?
-
- if params[:sha] && merge_request.diff_head_sha != params[:sha]
- render_api_error!("SHA does not match HEAD of source branch: #{merge_request.diff_head_sha}", 409)
- end
-
- merge_params = {
- commit_message: params[:merge_commit_message],
- should_remove_source_branch: params[:should_remove_source_branch]
- }
-
- if params[:merge_when_build_succeeds] && merge_request.head_pipeline && merge_request.head_pipeline.active?
- ::MergeRequests::MergeWhenPipelineSucceedsService
- .new(merge_request.target_project, current_user, merge_params)
- .execute(merge_request)
- else
- ::MergeRequests::MergeService
- .new(merge_request.target_project, current_user, merge_params)
- .execute(merge_request)
- end
-
- present merge_request, with: ::API::V3::Entities::MergeRequest, current_user: current_user, project: user_project
- end
-
- desc 'Cancel merge if "Merge When Build succeeds" is enabled' do
- success ::API::V3::Entities::MergeRequest
- end
- post "#{path}/cancel_merge_when_build_succeeds" do
- merge_request = find_project_merge_request(params[:merge_request_id])
-
- unauthorized! unless merge_request.can_cancel_merge_when_pipeline_succeeds?(current_user)
-
- ::MergeRequest::MergeWhenPipelineSucceedsService
- .new(merge_request.target_project, current_user)
- .cancel(merge_request)
- end
-
- desc 'Get the comments of a merge request' do
- detail 'Duplicate. DEPRECATED and HAS BEEN REMOVED in V4'
- success ::API::Entities::MRNote
- end
- params do
- use :pagination
- end
- get "#{path}/comments" do
- merge_request = find_merge_request_with_access(params[:merge_request_id])
- present paginate(merge_request.notes.fresh), with: ::API::Entities::MRNote
- end
-
- desc 'Post a comment to a merge request' do
- detail 'Duplicate. DEPRECATED and HAS BEEN REMOVED in V4'
- success ::API::Entities::MRNote
- end
- params do
- requires :note, type: String, desc: 'The text of the comment'
- end
- post "#{path}/comments" do
- merge_request = find_merge_request_with_access(params[:merge_request_id], :create_note)
-
- opts = {
- note: params[:note],
- noteable_type: 'MergeRequest',
- noteable_id: merge_request.id
- }
-
- note = ::Notes::CreateService.new(user_project, current_user, opts).execute
-
- if note.save
- present note, with: ::API::Entities::MRNote
- else
- render_api_error!("Failed to save note #{note.errors.messages}", 400)
- end
- end
-
- desc 'List issues that will be closed on merge' do
- success ::API::Entities::MRNote
- end
- params do
- use :pagination
- end
- get "#{path}/closes_issues" do
- merge_request = find_merge_request_with_access(params[:merge_request_id])
- issues = ::Kaminari.paginate_array(merge_request.closes_issues(current_user))
- present paginate(issues), with: issue_entity(user_project), current_user: current_user
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/milestones.rb b/lib/api/v3/milestones.rb
deleted file mode 100644
index 9be4cf9d22a..00000000000
--- a/lib/api/v3/milestones.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-module API
- module V3
- class Milestones < Grape::API
- include PaginationParams
-
- before { authenticate! }
-
- helpers do
- def filter_milestones_state(milestones, state)
- case state
- when 'active' then milestones.active
- when 'closed' then milestones.closed
- else milestones
- end
- end
- end
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Get a list of project milestones' do
- success ::API::Entities::Milestone
- end
- params do
- optional :state, type: String, values: %w[active closed all], default: 'all',
- desc: 'Return "active", "closed", or "all" milestones'
- optional :iid, type: Array[Integer], desc: 'The IID of the milestone'
- use :pagination
- end
- get ":id/milestones" do
- authorize! :read_milestone, user_project
-
- milestones = user_project.milestones
- milestones = filter_milestones_state(milestones, params[:state])
- milestones = filter_by_iid(milestones, params[:iid]) if params[:iid].present?
- milestones = milestones.order_id_desc
-
- present paginate(milestones), with: ::API::Entities::Milestone
- end
-
- desc 'Get all issues for a single project milestone' do
- success ::API::V3::Entities::Issue
- end
- params do
- requires :milestone_id, type: Integer, desc: 'The ID of a project milestone'
- use :pagination
- end
- get ':id/milestones/:milestone_id/issues' do
- authorize! :read_milestone, user_project
-
- milestone = user_project.milestones.find(params[:milestone_id])
-
- finder_params = {
- project_id: user_project.id,
- milestone_title: milestone.title
- }
-
- issues = IssuesFinder.new(current_user, finder_params).execute
- present paginate(issues), with: ::API::V3::Entities::Issue, current_user: current_user, project: user_project
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/notes.rb b/lib/api/v3/notes.rb
deleted file mode 100644
index d49772b92f2..00000000000
--- a/lib/api/v3/notes.rb
+++ /dev/null
@@ -1,148 +0,0 @@
-module API
- module V3
- class Notes < Grape::API
- include PaginationParams
-
- before { authenticate! }
-
- NOTEABLE_TYPES = [Issue, MergeRequest, Snippet].freeze
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- NOTEABLE_TYPES.each do |noteable_type|
- noteables_str = noteable_type.to_s.underscore.pluralize
-
- desc 'Get a list of project +noteable+ notes' do
- success ::API::V3::Entities::Note
- end
- params do
- requires :noteable_id, type: Integer, desc: 'The ID of the noteable'
- use :pagination
- end
- get ":id/#{noteables_str}/:noteable_id/notes" do
- noteable = user_project.public_send(noteables_str.to_sym).find(params[:noteable_id]) # rubocop:disable GitlabSecurity/PublicSend
-
- if can?(current_user, noteable_read_ability_name(noteable), noteable)
- # We exclude notes that are cross-references and that cannot be viewed
- # by the current user. By doing this exclusion at this level and not
- # at the DB query level (which we cannot in that case), the current
- # page can have less elements than :per_page even if
- # there's more than one page.
- notes =
- # paginate() only works with a relation. This could lead to a
- # mismatch between the pagination headers info and the actual notes
- # array returned, but this is really a edge-case.
- paginate(noteable.notes)
- .reject { |n| n.cross_reference_not_visible_for?(current_user) }
- present notes, with: ::API::V3::Entities::Note
- else
- not_found!("Notes")
- end
- end
-
- desc 'Get a single +noteable+ note' do
- success ::API::V3::Entities::Note
- end
- params do
- requires :note_id, type: Integer, desc: 'The ID of a note'
- requires :noteable_id, type: Integer, desc: 'The ID of the noteable'
- end
- get ":id/#{noteables_str}/:noteable_id/notes/:note_id" do
- noteable = user_project.public_send(noteables_str.to_sym).find(params[:noteable_id]) # rubocop:disable GitlabSecurity/PublicSend
- note = noteable.notes.find(params[:note_id])
- can_read_note = can?(current_user, noteable_read_ability_name(noteable), noteable) && !note.cross_reference_not_visible_for?(current_user)
-
- if can_read_note
- present note, with: ::API::V3::Entities::Note
- else
- not_found!("Note")
- end
- end
-
- desc 'Create a new +noteable+ note' do
- success ::API::V3::Entities::Note
- end
- params do
- requires :noteable_id, type: Integer, desc: 'The ID of the noteable'
- requires :body, type: String, desc: 'The content of a note'
- optional :created_at, type: String, desc: 'The creation date of the note'
- end
- post ":id/#{noteables_str}/:noteable_id/notes" do
- opts = {
- note: params[:body],
- noteable_type: noteables_str.classify,
- noteable_id: params[:noteable_id]
- }
-
- noteable = user_project.public_send(noteables_str.to_sym).find(params[:noteable_id]) # rubocop:disable GitlabSecurity/PublicSend
-
- if can?(current_user, noteable_read_ability_name(noteable), noteable)
- if params[:created_at] && (current_user.admin? || user_project.owner == current_user)
- opts[:created_at] = params[:created_at]
- end
-
- note = ::Notes::CreateService.new(user_project, current_user, opts).execute
- if note.valid?
- present note, with: ::API::V3::Entities.const_get(note.class.name)
- else
- not_found!("Note #{note.errors.messages}")
- end
- else
- not_found!("Note")
- end
- end
-
- desc 'Update an existing +noteable+ note' do
- success ::API::V3::Entities::Note
- end
- params do
- requires :noteable_id, type: Integer, desc: 'The ID of the noteable'
- requires :note_id, type: Integer, desc: 'The ID of a note'
- requires :body, type: String, desc: 'The content of a note'
- end
- put ":id/#{noteables_str}/:noteable_id/notes/:note_id" do
- note = user_project.notes.find(params[:note_id])
-
- authorize! :admin_note, note
-
- opts = {
- note: params[:body]
- }
-
- note = ::Notes::UpdateService.new(user_project, current_user, opts).execute(note)
-
- if note.valid?
- present note, with: ::API::V3::Entities::Note
- else
- render_api_error!("Failed to save note #{note.errors.messages}", 400)
- end
- end
-
- desc 'Delete a +noteable+ note' do
- success ::API::V3::Entities::Note
- end
- params do
- requires :noteable_id, type: Integer, desc: 'The ID of the noteable'
- requires :note_id, type: Integer, desc: 'The ID of a note'
- end
- delete ":id/#{noteables_str}/:noteable_id/notes/:note_id" do
- note = user_project.notes.find(params[:note_id])
- authorize! :admin_note, note
-
- ::Notes::DestroyService.new(user_project, current_user).execute(note)
-
- present note, with: ::API::V3::Entities::Note
- end
- end
- end
-
- helpers do
- def noteable_read_ability_name(noteable)
- "read_#{noteable.class.to_s.underscore}".to_sym
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/pipelines.rb b/lib/api/v3/pipelines.rb
deleted file mode 100644
index 6d31c12f572..00000000000
--- a/lib/api/v3/pipelines.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-module API
- module V3
- class Pipelines < Grape::API
- include PaginationParams
-
- before { authenticate! }
-
- params do
- requires :id, type: String, desc: 'The project ID'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Get all Pipelines of the project' do
- detail 'This feature was introduced in GitLab 8.11.'
- success ::API::Entities::Pipeline
- end
- params do
- use :pagination
- optional :scope, type: String, values: %w(running branches tags),
- desc: 'Either running, branches, or tags'
- end
- get ':id/pipelines' do
- Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42123')
-
- authorize! :read_pipeline, user_project
-
- pipelines = PipelinesFinder.new(user_project, scope: params[:scope]).execute
- present paginate(pipelines), with: ::API::Entities::Pipeline
- end
- end
-
- helpers do
- def pipeline
- @pipeline ||= user_project.pipelines.find(params[:pipeline_id])
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/project_hooks.rb b/lib/api/v3/project_hooks.rb
deleted file mode 100644
index 631944150c7..00000000000
--- a/lib/api/v3/project_hooks.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-module API
- module V3
- class ProjectHooks < Grape::API
- include PaginationParams
-
- before { authenticate! }
- before { authorize_admin_project }
-
- helpers do
- params :project_hook_properties do
- requires :url, type: String, desc: "The URL to send the request to"
- optional :push_events, type: Boolean, desc: "Trigger hook on push events"
- optional :issues_events, type: Boolean, desc: "Trigger hook on issues events"
- optional :confidential_issues_events, type: Boolean, desc: "Trigger hook on confidential issues events"
- optional :merge_requests_events, type: Boolean, desc: "Trigger hook on merge request events"
- optional :tag_push_events, type: Boolean, desc: "Trigger hook on tag push events"
- optional :note_events, type: Boolean, desc: "Trigger hook on note(comment) events"
- optional :build_events, type: Boolean, desc: "Trigger hook on build events"
- optional :pipeline_events, type: Boolean, desc: "Trigger hook on pipeline events"
- optional :wiki_page_events, type: Boolean, desc: "Trigger hook on wiki events"
- optional :enable_ssl_verification, type: Boolean, desc: "Do SSL verification when triggering the hook"
- optional :token, type: String, desc: "Secret token to validate received payloads; this will not be returned in the response"
- end
- end
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Get project hooks' do
- success ::API::V3::Entities::ProjectHook
- end
- params do
- use :pagination
- end
- get ":id/hooks" do
- hooks = paginate user_project.hooks
-
- present hooks, with: ::API::V3::Entities::ProjectHook
- end
-
- desc 'Get a project hook' do
- success ::API::V3::Entities::ProjectHook
- end
- params do
- requires :hook_id, type: Integer, desc: 'The ID of a project hook'
- end
- get ":id/hooks/:hook_id" do
- hook = user_project.hooks.find(params[:hook_id])
- present hook, with: ::API::V3::Entities::ProjectHook
- end
-
- desc 'Add hook to project' do
- success ::API::V3::Entities::ProjectHook
- end
- params do
- use :project_hook_properties
- end
- post ":id/hooks" do
- attrs = declared_params(include_missing: false)
- attrs[:job_events] = attrs.delete(:build_events) if attrs.key?(:build_events)
- hook = user_project.hooks.new(attrs)
-
- if hook.save
- present hook, with: ::API::V3::Entities::ProjectHook
- else
- error!("Invalid url given", 422) if hook.errors[:url].present?
-
- not_found!("Project hook #{hook.errors.messages}")
- end
- end
-
- desc 'Update an existing project hook' do
- success ::API::V3::Entities::ProjectHook
- end
- params do
- requires :hook_id, type: Integer, desc: "The ID of the hook to update"
- use :project_hook_properties
- end
- put ":id/hooks/:hook_id" do
- hook = user_project.hooks.find(params.delete(:hook_id))
-
- attrs = declared_params(include_missing: false)
- attrs[:job_events] = attrs.delete(:build_events) if attrs.key?(:build_events)
- if hook.update_attributes(attrs)
- present hook, with: ::API::V3::Entities::ProjectHook
- else
- error!("Invalid url given", 422) if hook.errors[:url].present?
-
- not_found!("Project hook #{hook.errors.messages}")
- end
- end
-
- desc 'Deletes project hook' do
- success ::API::V3::Entities::ProjectHook
- end
- params do
- requires :hook_id, type: Integer, desc: 'The ID of the hook to delete'
- end
- delete ":id/hooks/:hook_id" do
- begin
- present user_project.hooks.destroy(params[:hook_id]), with: ::API::V3::Entities::ProjectHook
- rescue
- # ProjectHook can raise Error if hook_id not found
- not_found!("Error deleting hook #{params[:hook_id]}")
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/project_snippets.rb b/lib/api/v3/project_snippets.rb
deleted file mode 100644
index 6ba425ba8c7..00000000000
--- a/lib/api/v3/project_snippets.rb
+++ /dev/null
@@ -1,143 +0,0 @@
-module API
- module V3
- class ProjectSnippets < Grape::API
- include PaginationParams
-
- before { authenticate! }
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- helpers do
- def handle_project_member_errors(errors)
- if errors[:project_access].any?
- error!(errors[:project_access], 422)
- end
-
- not_found!
- end
-
- def snippets_for_current_user
- SnippetsFinder.new(current_user, project: user_project).execute
- end
- end
-
- desc 'Get all project snippets' do
- success ::API::V3::Entities::ProjectSnippet
- end
- params do
- use :pagination
- end
- get ":id/snippets" do
- present paginate(snippets_for_current_user), with: ::API::V3::Entities::ProjectSnippet
- end
-
- desc 'Get a single project snippet' do
- success ::API::V3::Entities::ProjectSnippet
- end
- params do
- requires :snippet_id, type: Integer, desc: 'The ID of a project snippet'
- end
- get ":id/snippets/:snippet_id" do
- snippet = snippets_for_current_user.find(params[:snippet_id])
- present snippet, with: ::API::V3::Entities::ProjectSnippet
- end
-
- desc 'Create a new project snippet' do
- success ::API::V3::Entities::ProjectSnippet
- end
- params do
- requires :title, type: String, desc: 'The title of the snippet'
- requires :file_name, type: String, desc: 'The file name of the snippet'
- requires :code, type: String, desc: 'The content of the snippet'
- requires :visibility_level, type: Integer,
- values: [Gitlab::VisibilityLevel::PRIVATE,
- Gitlab::VisibilityLevel::INTERNAL,
- Gitlab::VisibilityLevel::PUBLIC],
- desc: 'The visibility level of the snippet'
- end
- post ":id/snippets" do
- authorize! :create_project_snippet, user_project
- snippet_params = declared_params.merge(request: request, api: true)
- snippet_params[:content] = snippet_params.delete(:code)
-
- snippet = CreateSnippetService.new(user_project, current_user, snippet_params).execute
-
- render_spam_error! if snippet.spam?
-
- if snippet.persisted?
- present snippet, with: ::API::V3::Entities::ProjectSnippet
- else
- render_validation_error!(snippet)
- end
- end
-
- desc 'Update an existing project snippet' do
- success ::API::V3::Entities::ProjectSnippet
- end
- params do
- requires :snippet_id, type: Integer, desc: 'The ID of a project snippet'
- optional :title, type: String, desc: 'The title of the snippet'
- optional :file_name, type: String, desc: 'The file name of the snippet'
- optional :code, type: String, desc: 'The content of the snippet'
- optional :visibility_level, type: Integer,
- values: [Gitlab::VisibilityLevel::PRIVATE,
- Gitlab::VisibilityLevel::INTERNAL,
- Gitlab::VisibilityLevel::PUBLIC],
- desc: 'The visibility level of the snippet'
- at_least_one_of :title, :file_name, :code, :visibility_level
- end
- put ":id/snippets/:snippet_id" do
- snippet = snippets_for_current_user.find_by(id: params.delete(:snippet_id))
- not_found!('Snippet') unless snippet
-
- authorize! :update_project_snippet, snippet
-
- snippet_params = declared_params(include_missing: false)
- .merge(request: request, api: true)
-
- snippet_params[:content] = snippet_params.delete(:code) if snippet_params[:code].present?
-
- UpdateSnippetService.new(user_project, current_user, snippet,
- snippet_params).execute
-
- render_spam_error! if snippet.spam?
-
- if snippet.valid?
- present snippet, with: ::API::V3::Entities::ProjectSnippet
- else
- render_validation_error!(snippet)
- end
- end
-
- desc 'Delete a project snippet'
- params do
- requires :snippet_id, type: Integer, desc: 'The ID of a project snippet'
- end
- delete ":id/snippets/:snippet_id" do
- snippet = snippets_for_current_user.find_by(id: params[:snippet_id])
- not_found!('Snippet') unless snippet
-
- authorize! :admin_project_snippet, snippet
- snippet.destroy
-
- status(200)
- end
-
- desc 'Get a raw project snippet'
- params do
- requires :snippet_id, type: Integer, desc: 'The ID of a project snippet'
- end
- get ":id/snippets/:snippet_id/raw" do
- snippet = snippets_for_current_user.find_by(id: params[:snippet_id])
- not_found!('Snippet') unless snippet
-
- env['api.format'] = :txt
- content_type 'text/plain'
- present snippet.content
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/projects.rb b/lib/api/v3/projects.rb
deleted file mode 100644
index eb3dd113524..00000000000
--- a/lib/api/v3/projects.rb
+++ /dev/null
@@ -1,475 +0,0 @@
-module API
- module V3
- class Projects < Grape::API
- include PaginationParams
-
- before { authenticate_non_get! }
-
- after_validation do
- set_only_allow_merge_if_pipeline_succeeds!
- end
-
- helpers do
- params :optional_params do
- optional :description, type: String, desc: 'The description of the project'
- optional :issues_enabled, type: Boolean, desc: 'Flag indication if the issue tracker is enabled'
- optional :merge_requests_enabled, type: Boolean, desc: 'Flag indication if merge requests are enabled'
- optional :wiki_enabled, type: Boolean, desc: 'Flag indication if the wiki is enabled'
- optional :builds_enabled, type: Boolean, desc: 'Flag indication if builds are enabled'
- optional :snippets_enabled, type: Boolean, desc: 'Flag indication if snippets are enabled'
- optional :shared_runners_enabled, type: Boolean, desc: 'Flag indication if shared runners are enabled for that project'
- optional :resolve_outdated_diff_discussions, type: Boolean, desc: 'Automatically resolve merge request diffs discussions on lines changed with a push'
- optional :container_registry_enabled, type: Boolean, desc: 'Flag indication if the container registry is enabled for that project'
- optional :lfs_enabled, type: Boolean, desc: 'Flag indication if Git LFS is enabled for that project'
- optional :public, type: Boolean, desc: 'Create a public project. The same as visibility_level = 20.'
- optional :visibility_level, type: Integer, values: [
- Gitlab::VisibilityLevel::PRIVATE,
- Gitlab::VisibilityLevel::INTERNAL,
- Gitlab::VisibilityLevel::PUBLIC
- ], desc: 'Create a public project. The same as visibility_level = 20.'
- optional :public_builds, type: Boolean, desc: 'Perform public builds'
- optional :request_access_enabled, type: Boolean, desc: 'Allow users to request member access'
- optional :only_allow_merge_if_build_succeeds, type: Boolean, desc: 'Only allow to merge if builds succeed'
- optional :only_allow_merge_if_pipeline_succeeds, type: Boolean, desc: 'Only allow to merge if builds succeed'
- optional :only_allow_merge_if_all_discussions_are_resolved, type: Boolean, desc: 'Only allow to merge if all discussions are resolved'
- end
-
- def map_public_to_visibility_level(attrs)
- publik = attrs.delete(:public)
- if !publik.nil? && !attrs[:visibility_level].present?
- # Since setting the public attribute to private could mean either
- # private or internal, use the more conservative option, private.
- attrs[:visibility_level] = (publik == true) ? Gitlab::VisibilityLevel::PUBLIC : Gitlab::VisibilityLevel::PRIVATE
- end
-
- attrs
- end
-
- def set_only_allow_merge_if_pipeline_succeeds!
- if params.key?(:only_allow_merge_if_build_succeeds)
- params[:only_allow_merge_if_pipeline_succeeds] = params.delete(:only_allow_merge_if_build_succeeds)
- end
- end
- end
-
- resource :projects do
- helpers do
- params :collection_params do
- use :sort_params
- use :filter_params
- use :pagination
-
- optional :simple, type: Boolean, default: false,
- desc: 'Return only the ID, URL, name, and path of each project'
- end
-
- params :sort_params do
- optional :order_by, type: String, values: %w[id name path created_at updated_at last_activity_at],
- default: 'created_at', desc: 'Return projects ordered by field'
- optional :sort, type: String, values: %w[asc desc], default: 'desc',
- desc: 'Return projects sorted in ascending and descending order'
- end
-
- params :filter_params do
- optional :archived, type: Boolean, default: nil, desc: 'Limit by archived status'
- optional :visibility, type: String, values: %w[public internal private],
- desc: 'Limit by visibility'
- optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria'
- end
-
- params :statistics_params do
- optional :statistics, type: Boolean, default: false, desc: 'Include project statistics'
- end
-
- params :create_params do
- optional :namespace_id, type: Integer, desc: 'Namespace ID for the new project. Default to the user namespace.'
- optional :import_url, type: String, desc: 'URL from which the project is imported'
- end
-
- def present_projects(projects, options = {})
- options = options.reverse_merge(
- with: ::API::V3::Entities::Project,
- current_user: current_user,
- simple: params[:simple]
- )
-
- projects = filter_projects(projects)
- projects = projects.with_statistics if options[:statistics]
- options[:with] = ::API::Entities::BasicProjectDetails if options[:simple]
-
- present paginate(projects), options
- end
- end
-
- desc 'Get a list of visible projects for authenticated user' do
- success ::API::Entities::BasicProjectDetails
- end
- params do
- use :collection_params
- end
- get '/visible' do
- entity = current_user ? ::API::V3::Entities::ProjectWithAccess : ::API::Entities::BasicProjectDetails
- present_projects ProjectsFinder.new(current_user: current_user).execute, with: entity
- end
-
- desc 'Get a projects list for authenticated user' do
- success ::API::Entities::BasicProjectDetails
- end
- params do
- use :collection_params
- end
- get do
- authenticate!
-
- present_projects current_user.authorized_projects.order_id_desc,
- with: ::API::V3::Entities::ProjectWithAccess
- end
-
- desc 'Get an owned projects list for authenticated user' do
- success ::API::Entities::BasicProjectDetails
- end
- params do
- use :collection_params
- use :statistics_params
- end
- get '/owned' do
- authenticate!
-
- present_projects current_user.owned_projects,
- with: ::API::V3::Entities::ProjectWithAccess,
- statistics: params[:statistics]
- end
-
- desc 'Gets starred project for the authenticated user' do
- success ::API::Entities::BasicProjectDetails
- end
- params do
- use :collection_params
- end
- get '/starred' do
- authenticate!
-
- present_projects ProjectsFinder.new(current_user: current_user, params: { starred: true }).execute
- end
-
- desc 'Get all projects for admin user' do
- success ::API::Entities::BasicProjectDetails
- end
- params do
- use :collection_params
- use :statistics_params
- end
- get '/all' do
- authenticated_as_admin!
-
- present_projects Project.all, with: ::API::V3::Entities::ProjectWithAccess, statistics: params[:statistics]
- end
-
- desc 'Search for projects the current user has access to' do
- success ::API::V3::Entities::Project
- end
- params do
- requires :query, type: String, desc: 'The project name to be searched'
- use :sort_params
- use :pagination
- end
- get "/search/:query", requirements: { query: %r{[^/]+} } do
- search_service = ::Search::GlobalService.new(current_user, search: params[:query]).execute
- projects = search_service.objects('projects', params[:page], false)
- projects = projects.reorder(params[:order_by] => params[:sort])
-
- present paginate(projects), with: ::API::V3::Entities::Project
- end
-
- desc 'Create new project' do
- success ::API::V3::Entities::Project
- end
- params do
- optional :name, type: String, desc: 'The name of the project'
- optional :path, type: String, desc: 'The path of the repository'
- at_least_one_of :name, :path
- use :optional_params
- use :create_params
- end
- post do
- attrs = map_public_to_visibility_level(declared_params(include_missing: false))
- project = ::Projects::CreateService.new(current_user, attrs).execute
-
- if project.saved?
- present project, with: ::API::V3::Entities::Project,
- user_can_admin_project: can?(current_user, :admin_project, project)
- else
- if project.errors[:limit_reached].present?
- error!(project.errors[:limit_reached], 403)
- end
-
- render_validation_error!(project)
- end
- end
-
- desc 'Create new project for a specified user. Only available to admin users.' do
- success ::API::V3::Entities::Project
- end
- params do
- requires :name, type: String, desc: 'The name of the project'
- requires :user_id, type: Integer, desc: 'The ID of a user'
- optional :default_branch, type: String, desc: 'The default branch of the project'
- use :optional_params
- use :create_params
- end
- post "user/:user_id" do
- authenticated_as_admin!
- user = User.find_by(id: params.delete(:user_id))
- not_found!('User') unless user
-
- attrs = map_public_to_visibility_level(declared_params(include_missing: false))
- project = ::Projects::CreateService.new(user, attrs).execute
-
- if project.saved?
- present project, with: ::API::V3::Entities::Project,
- user_can_admin_project: can?(current_user, :admin_project, project)
- else
- render_validation_error!(project)
- end
- end
- end
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Get a single project' do
- success ::API::V3::Entities::ProjectWithAccess
- end
- get ":id" do
- entity = current_user ? ::API::V3::Entities::ProjectWithAccess : ::API::Entities::BasicProjectDetails
- present user_project, with: entity, current_user: current_user,
- user_can_admin_project: can?(current_user, :admin_project, user_project)
- end
-
- desc 'Get events for a single project' do
- success ::API::V3::Entities::Event
- end
- params do
- use :pagination
- end
- get ":id/events" do
- present paginate(user_project.events.recent), with: ::API::V3::Entities::Event
- end
-
- desc 'Fork new project for the current user or provided namespace.' do
- success ::API::V3::Entities::Project
- end
- params do
- optional :namespace, type: String, desc: 'The ID or name of the namespace that the project will be forked into'
- end
- post 'fork/:id' do
- fork_params = declared_params(include_missing: false)
- namespace_id = fork_params[:namespace]
-
- if namespace_id.present?
- fork_params[:namespace] = find_namespace(namespace_id)
-
- unless fork_params[:namespace] && can?(current_user, :create_projects, fork_params[:namespace])
- not_found!('Target Namespace')
- end
- end
-
- forked_project = ::Projects::ForkService.new(user_project, current_user, fork_params).execute
-
- if forked_project.errors.any?
- conflict!(forked_project.errors.messages)
- else
- present forked_project, with: ::API::V3::Entities::Project,
- user_can_admin_project: can?(current_user, :admin_project, forked_project)
- end
- end
-
- desc 'Update an existing project' do
- success ::API::V3::Entities::Project
- end
- params do
- optional :name, type: String, desc: 'The name of the project'
- optional :default_branch, type: String, desc: 'The default branch of the project'
- optional :path, type: String, desc: 'The path of the repository'
- use :optional_params
- at_least_one_of :name, :description, :issues_enabled, :merge_requests_enabled,
- :wiki_enabled, :builds_enabled, :snippets_enabled,
- :shared_runners_enabled, :resolve_outdated_diff_discussions,
- :container_registry_enabled, :lfs_enabled, :public, :visibility_level,
- :public_builds, :request_access_enabled, :only_allow_merge_if_build_succeeds,
- :only_allow_merge_if_all_discussions_are_resolved, :path,
- :default_branch
- end
- put ':id' do
- authorize_admin_project
- attrs = map_public_to_visibility_level(declared_params(include_missing: false))
- authorize! :rename_project, user_project if attrs[:name].present?
- authorize! :change_visibility_level, user_project if attrs[:visibility_level].present?
-
- result = ::Projects::UpdateService.new(user_project, current_user, attrs).execute
-
- if result[:status] == :success
- present user_project, with: ::API::V3::Entities::Project,
- user_can_admin_project: can?(current_user, :admin_project, user_project)
- else
- render_validation_error!(user_project)
- end
- end
-
- desc 'Archive a project' do
- success ::API::V3::Entities::Project
- end
- post ':id/archive' do
- authorize!(:archive_project, user_project)
-
- user_project.archive!
-
- present user_project, with: ::API::V3::Entities::Project
- end
-
- desc 'Unarchive a project' do
- success ::API::V3::Entities::Project
- end
- post ':id/unarchive' do
- authorize!(:archive_project, user_project)
-
- user_project.unarchive!
-
- present user_project, with: ::API::V3::Entities::Project
- end
-
- desc 'Star a project' do
- success ::API::V3::Entities::Project
- end
- post ':id/star' do
- if current_user.starred?(user_project)
- not_modified!
- else
- current_user.toggle_star(user_project)
- user_project.reload
-
- present user_project, with: ::API::V3::Entities::Project
- end
- end
-
- desc 'Unstar a project' do
- success ::API::V3::Entities::Project
- end
- delete ':id/star' do
- if current_user.starred?(user_project)
- current_user.toggle_star(user_project)
- user_project.reload
-
- present user_project, with: ::API::V3::Entities::Project
- else
- not_modified!
- end
- end
-
- desc 'Remove a project'
- delete ":id" do
- authorize! :remove_project, user_project
-
- status(200)
- ::Projects::DestroyService.new(user_project, current_user, {}).async_execute
- end
-
- desc 'Mark this project as forked from another'
- params do
- requires :forked_from_id, type: String, desc: 'The ID of the project it was forked from'
- end
- post ":id/fork/:forked_from_id" do
- authenticated_as_admin!
-
- forked_from_project = find_project!(params[:forked_from_id])
- not_found!("Source Project") unless forked_from_project
-
- if user_project.forked_from_project.nil?
- user_project.create_forked_project_link(forked_to_project_id: user_project.id, forked_from_project_id: forked_from_project.id)
-
- ::Projects::ForksCountService.new(forked_from_project).refresh_cache
- else
- render_api_error!("Project already forked", 409)
- end
- end
-
- desc 'Remove a forked_from relationship'
- delete ":id/fork" do
- authorize! :remove_fork_project, user_project
-
- if user_project.forked?
- status(200)
- user_project.forked_project_link.destroy
- else
- not_modified!
- end
- end
-
- desc 'Share the project with a group' do
- success ::API::Entities::ProjectGroupLink
- end
- params do
- requires :group_id, type: Integer, desc: 'The ID of a group'
- requires :group_access, type: Integer, values: Gitlab::Access.values, desc: 'The group access level'
- optional :expires_at, type: Date, desc: 'Share expiration date'
- end
- post ":id/share" do
- authorize! :admin_project, user_project
- group = Group.find_by_id(params[:group_id])
-
- unless group && can?(current_user, :read_group, group)
- not_found!('Group')
- end
-
- unless user_project.allowed_to_share_with_group?
- break render_api_error!("The project sharing with group is disabled", 400)
- end
-
- link = user_project.project_group_links.new(declared_params(include_missing: false))
-
- if link.save
- present link, with: ::API::Entities::ProjectGroupLink
- else
- render_api_error!(link.errors.full_messages.first, 409)
- end
- end
-
- params do
- requires :group_id, type: Integer, desc: 'The ID of the group'
- end
- delete ":id/share/:group_id" do
- authorize! :admin_project, user_project
-
- link = user_project.project_group_links.find_by(group_id: params[:group_id])
- not_found!('Group Link') unless link
-
- link.destroy
- no_content!
- end
-
- desc 'Upload a file'
- params do
- requires :file, type: File, desc: 'The file to be uploaded'
- end
- post ":id/uploads" do
- UploadService.new(user_project, params[:file]).execute
- end
-
- desc 'Get the users list of a project' do
- success ::API::Entities::UserBasic
- end
- params do
- optional :search, type: String, desc: 'Return list of users matching the search criteria'
- use :pagination
- end
- get ':id/users' do
- users = user_project.team.users
- users = users.search(params[:search]) if params[:search].present?
-
- present paginate(users), with: ::API::Entities::UserBasic
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/repositories.rb b/lib/api/v3/repositories.rb
deleted file mode 100644
index f701d64e886..00000000000
--- a/lib/api/v3/repositories.rb
+++ /dev/null
@@ -1,110 +0,0 @@
-require 'mime/types'
-
-module API
- module V3
- class Repositories < Grape::API
- before { authorize! :download_code, user_project }
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
- helpers do
- def handle_project_member_errors(errors)
- if errors[:project_access].any?
- error!(errors[:project_access], 422)
- end
-
- not_found!
- end
- end
-
- desc 'Get a project repository tree' do
- success ::API::Entities::TreeObject
- end
- params do
- optional :ref_name, type: String, desc: 'The name of a repository branch or tag, if not given the default branch is used'
- optional :path, type: String, desc: 'The path of the tree'
- optional :recursive, type: Boolean, default: false, desc: 'Used to get a recursive tree'
- end
- get ':id/repository/tree' do
- ref = params[:ref_name] || user_project.try(:default_branch) || 'master'
- path = params[:path] || nil
-
- commit = user_project.commit(ref)
- not_found!('Tree') unless commit
-
- tree = user_project.repository.tree(commit.id, path, recursive: params[:recursive])
-
- present tree.sorted_entries, with: ::API::Entities::TreeObject
- end
-
- desc 'Get a raw file contents'
- params do
- requires :sha, type: String, desc: 'The commit, branch name, or tag name'
- requires :filepath, type: String, desc: 'The path to the file to display'
- end
- get [":id/repository/blobs/:sha", ":id/repository/commits/:sha/blob"], requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
- repo = user_project.repository
- commit = repo.commit(params[:sha])
- not_found! "Commit" unless commit
- blob = Gitlab::Git::Blob.find(repo, commit.id, params[:filepath])
- not_found! "File" unless blob
- send_git_blob repo, blob
- end
-
- desc 'Get a raw blob contents by blob sha'
- params do
- requires :sha, type: String, desc: 'The commit, branch name, or tag name'
- end
- get ':id/repository/raw_blobs/:sha', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
- repo = user_project.repository
- begin
- blob = Gitlab::Git::Blob.raw(repo, params[:sha])
- rescue
- not_found! 'Blob'
- end
- not_found! 'Blob' unless blob
- send_git_blob repo, blob
- end
-
- desc 'Get an archive of the repository'
- params do
- optional :sha, type: String, desc: 'The commit sha of the archive to be downloaded'
- optional :format, type: String, desc: 'The archive format'
- end
- get ':id/repository/archive', requirements: { format: Gitlab::PathRegex.archive_formats_regex } do
- begin
- send_git_archive user_project.repository, ref: params[:sha], format: params[:format], append_sha: true
- rescue
- not_found!('File')
- end
- end
-
- desc 'Compare two branches, tags, or commits' do
- success ::API::Entities::Compare
- end
- params do
- requires :from, type: String, desc: 'The commit, branch name, or tag name to start comparison'
- requires :to, type: String, desc: 'The commit, branch name, or tag name to stop comparison'
- end
- get ':id/repository/compare' do
- compare = Gitlab::Git::Compare.new(user_project.repository.raw_repository, params[:from], params[:to])
- present compare, with: ::API::Entities::Compare
- end
-
- desc 'Get repository contributors' do
- success ::API::Entities::Contributor
- end
- get ':id/repository/contributors' do
- begin
- present user_project.repository.contributors,
- with: ::API::Entities::Contributor
- rescue
- not_found!
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/runners.rb b/lib/api/v3/runners.rb
deleted file mode 100644
index 8a5c46805bd..00000000000
--- a/lib/api/v3/runners.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-module API
- module V3
- class Runners < Grape::API
- include PaginationParams
-
- before { authenticate! }
-
- resource :runners do
- desc 'Remove a runner' do
- success ::API::Entities::Runner
- end
- params do
- requires :id, type: Integer, desc: 'The ID of the runner'
- end
- delete ':id' do
- runner = Ci::Runner.find(params[:id])
- not_found!('Runner') unless runner
-
- authenticate_delete_runner!(runner)
-
- status(200)
- runner.destroy
- end
- end
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- before { authorize_admin_project }
-
- desc "Disable project's runner" do
- success ::API::Entities::Runner
- end
- params do
- requires :runner_id, type: Integer, desc: 'The ID of the runner'
- end
- delete ':id/runners/:runner_id' do
- runner_project = user_project.runner_projects.find_by(runner_id: params[:runner_id])
- not_found!('Runner') unless runner_project
-
- runner = runner_project.runner
- forbidden!("Only one project associated with the runner. Please remove the runner instead") if runner.projects.count == 1
-
- runner_project.destroy
-
- present runner, with: ::API::Entities::Runner
- end
- end
-
- helpers do
- def authenticate_delete_runner!(runner)
- return if current_user.admin?
-
- forbidden!("Runner is shared") if runner.is_shared?
- forbidden!("Runner associated with more than one project") if runner.projects.count > 1
- forbidden!("No access granted") unless user_can_access_runner?(runner)
- end
-
- def user_can_access_runner?(runner)
- current_user.ci_owned_runners.exists?(runner.id)
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/services.rb b/lib/api/v3/services.rb
deleted file mode 100644
index 20ca1021c71..00000000000
--- a/lib/api/v3/services.rb
+++ /dev/null
@@ -1,670 +0,0 @@
-module API
- module V3
- class Services < Grape::API
- services = {
- 'asana' => [
- {
- required: true,
- name: :api_key,
- type: String,
- desc: 'User API token'
- },
- {
- required: false,
- name: :restrict_to_branch,
- type: String,
- desc: 'Comma-separated list of branches which will be automatically inspected. Leave blank to include all branches'
- }
- ],
- 'assembla' => [
- {
- required: true,
- name: :token,
- type: String,
- desc: 'The authentication token'
- },
- {
- required: false,
- name: :subdomain,
- type: String,
- desc: 'Subdomain setting'
- }
- ],
- 'bamboo' => [
- {
- required: true,
- name: :bamboo_url,
- type: String,
- desc: 'Bamboo root URL like https://bamboo.example.com'
- },
- {
- required: true,
- name: :build_key,
- type: String,
- desc: 'Bamboo build plan key like'
- },
- {
- required: true,
- name: :username,
- type: String,
- desc: 'A user with API access, if applicable'
- },
- {
- required: true,
- name: :password,
- type: String,
- desc: 'Passord of the user'
- }
- ],
- 'bugzilla' => [
- {
- required: true,
- name: :new_issue_url,
- type: String,
- desc: 'New issue URL'
- },
- {
- required: true,
- name: :issues_url,
- type: String,
- desc: 'Issues URL'
- },
- {
- required: true,
- name: :project_url,
- type: String,
- desc: 'Project URL'
- },
- {
- required: false,
- name: :description,
- type: String,
- desc: 'Description'
- },
- {
- required: false,
- name: :title,
- type: String,
- desc: 'Title'
- }
- ],
- 'buildkite' => [
- {
- required: true,
- name: :token,
- type: String,
- desc: 'Buildkite project GitLab token'
- },
- {
- required: true,
- name: :project_url,
- type: String,
- desc: 'The buildkite project URL'
- },
- {
- required: false,
- name: :enable_ssl_verification,
- type: Boolean,
- desc: 'Enable SSL verification for communication'
- }
- ],
- 'builds-email' => [
- {
- required: true,
- name: :recipients,
- type: String,
- desc: 'Comma-separated list of recipient email addresses'
- },
- {
- required: false,
- name: :add_pusher,
- type: Boolean,
- desc: 'Add pusher to recipients list'
- },
- {
- required: false,
- name: :notify_only_broken_builds,
- type: Boolean,
- desc: 'Notify only broken builds'
- }
- ],
- 'campfire' => [
- {
- required: true,
- name: :token,
- type: String,
- desc: 'Campfire token'
- },
- {
- required: false,
- name: :subdomain,
- type: String,
- desc: 'Campfire subdomain'
- },
- {
- required: false,
- name: :room,
- type: String,
- desc: 'Campfire room'
- }
- ],
- 'custom-issue-tracker' => [
- {
- required: true,
- name: :new_issue_url,
- type: String,
- desc: 'New issue URL'
- },
- {
- required: true,
- name: :issues_url,
- type: String,
- desc: 'Issues URL'
- },
- {
- required: true,
- name: :project_url,
- type: String,
- desc: 'Project URL'
- },
- {
- required: false,
- name: :description,
- type: String,
- desc: 'Description'
- },
- {
- required: false,
- name: :title,
- type: String,
- desc: 'Title'
- }
- ],
- 'drone-ci' => [
- {
- required: true,
- name: :token,
- type: String,
- desc: 'Drone CI token'
- },
- {
- required: true,
- name: :drone_url,
- type: String,
- desc: 'Drone CI URL'
- },
- {
- required: false,
- name: :enable_ssl_verification,
- type: Boolean,
- desc: 'Enable SSL verification for communication'
- }
- ],
- 'emails-on-push' => [
- {
- required: true,
- name: :recipients,
- type: String,
- desc: 'Comma-separated list of recipient email addresses'
- },
- {
- required: false,
- name: :disable_diffs,
- type: Boolean,
- desc: 'Disable code diffs'
- },
- {
- required: false,
- name: :send_from_committer_email,
- type: Boolean,
- desc: 'Send from committer'
- }
- ],
- 'external-wiki' => [
- {
- required: true,
- name: :external_wiki_url,
- type: String,
- desc: 'The URL of the external Wiki'
- }
- ],
- 'flowdock' => [
- {
- required: true,
- name: :token,
- type: String,
- desc: 'Flowdock token'
- }
- ],
- 'gemnasium' => [
- {
- required: true,
- name: :api_key,
- type: String,
- desc: 'Your personal API key on gemnasium.com'
- },
- {
- required: true,
- name: :token,
- type: String,
- desc: "The project's slug on gemnasium.com"
- }
- ],
- 'hipchat' => [
- {
- required: true,
- name: :token,
- type: String,
- desc: 'The room token'
- },
- {
- required: false,
- name: :room,
- type: String,
- desc: 'The room name or ID'
- },
- {
- required: false,
- name: :color,
- type: String,
- desc: 'The room color'
- },
- {
- required: false,
- name: :notify,
- type: Boolean,
- desc: 'Enable notifications'
- },
- {
- required: false,
- name: :api_version,
- type: String,
- desc: 'Leave blank for default (v2)'
- },
- {
- required: false,
- name: :server,
- type: String,
- desc: 'Leave blank for default. https://hipchat.example.com'
- }
- ],
- 'irker' => [
- {
- required: true,
- name: :recipients,
- type: String,
- desc: 'Recipients/channels separated by whitespaces'
- },
- {
- required: false,
- name: :default_irc_uri,
- type: String,
- desc: 'Default: irc://irc.network.net:6697'
- },
- {
- required: false,
- name: :server_host,
- type: String,
- desc: 'Server host. Default localhost'
- },
- {
- required: false,
- name: :server_port,
- type: Integer,
- desc: 'Server port. Default 6659'
- },
- {
- required: false,
- name: :colorize_messages,
- type: Boolean,
- desc: 'Colorize messages'
- }
- ],
- 'jira' => [
- {
- required: true,
- name: :url,
- type: String,
- desc: 'The URL to the JIRA project which is being linked to this GitLab project, e.g., https://jira.example.com'
- },
- {
- required: true,
- name: :project_key,
- type: String,
- desc: 'The short identifier for your JIRA project, all uppercase, e.g., PROJ'
- },
- {
- required: false,
- name: :username,
- type: String,
- desc: 'The username of the user created to be used with GitLab/JIRA'
- },
- {
- required: false,
- name: :password,
- type: String,
- desc: 'The password of the user created to be used with GitLab/JIRA'
- },
- {
- required: false,
- name: :jira_issue_transition_id,
- type: Integer,
- desc: 'The ID of a transition that moves issues to a closed state. You can find this number under the JIRA workflow administration (**Administration > Issues > Workflows**) by selecting **View** under **Operations** of the desired workflow of your project. The ID of each state can be found inside the parenthesis of each transition name under the **Transitions (id)** column ([see screenshot][trans]). By default, this ID is set to `2`'
- }
- ],
-
- 'kubernetes' => [
- {
- required: true,
- name: :namespace,
- type: String,
- desc: 'The Kubernetes namespace to use'
- },
- {
- required: true,
- name: :api_url,
- type: String,
- desc: 'The URL to the Kubernetes cluster API, e.g., https://kubernetes.example.com'
- },
- {
- required: true,
- name: :token,
- type: String,
- desc: 'The service token to authenticate against the Kubernetes cluster with'
- },
- {
- required: false,
- name: :ca_pem,
- type: String,
- desc: 'A custom certificate authority bundle to verify the Kubernetes cluster with (PEM format)'
- }
- ],
- 'mattermost-slash-commands' => [
- {
- required: true,
- name: :token,
- type: String,
- desc: 'The Mattermost token'
- }
- ],
- 'slack-slash-commands' => [
- {
- required: true,
- name: :token,
- type: String,
- desc: 'The Slack token'
- }
- ],
- 'packagist' => [
- {
- required: true,
- name: :username,
- type: String,
- desc: 'The username'
- },
- {
- required: true,
- name: :token,
- type: String,
- desc: 'The Packagist API token'
- },
- {
- required: false,
- name: :server,
- type: String,
- desc: 'The server'
- }
- ],
- 'pipelines-email' => [
- {
- required: true,
- name: :recipients,
- type: String,
- desc: 'Comma-separated list of recipient email addresses'
- },
- {
- required: false,
- name: :notify_only_broken_builds,
- type: Boolean,
- desc: 'Notify only broken builds'
- }
- ],
- 'pivotaltracker' => [
- {
- required: true,
- name: :token,
- type: String,
- desc: 'The Pivotaltracker token'
- },
- {
- required: false,
- name: :restrict_to_branch,
- type: String,
- desc: 'Comma-separated list of branches which will be automatically inspected. Leave blank to include all branches.'
- }
- ],
- 'pushover' => [
- {
- required: true,
- name: :api_key,
- type: String,
- desc: 'The application key'
- },
- {
- required: true,
- name: :user_key,
- type: String,
- desc: 'The user key'
- },
- {
- required: true,
- name: :priority,
- type: String,
- desc: 'The priority'
- },
- {
- required: true,
- name: :device,
- type: String,
- desc: 'Leave blank for all active devices'
- },
- {
- required: true,
- name: :sound,
- type: String,
- desc: 'The sound of the notification'
- }
- ],
- 'redmine' => [
- {
- required: true,
- name: :new_issue_url,
- type: String,
- desc: 'The new issue URL'
- },
- {
- required: true,
- name: :project_url,
- type: String,
- desc: 'The project URL'
- },
- {
- required: true,
- name: :issues_url,
- type: String,
- desc: 'The issues URL'
- },
- {
- required: false,
- name: :description,
- type: String,
- desc: 'The description of the tracker'
- }
- ],
- 'slack' => [
- {
- required: true,
- name: :webhook,
- type: String,
- desc: 'The Slack webhook. e.g. https://hooks.slack.com/services/...'
- },
- {
- required: false,
- name: :new_issue_url,
- type: String,
- desc: 'The user name'
- },
- {
- required: false,
- name: :channel,
- type: String,
- desc: 'The channel name'
- }
- ],
- 'microsoft-teams' => [
- required: true,
- name: :webhook,
- type: String,
- desc: 'The Microsoft Teams webhook. e.g. https://outlook.office.com/webhook/…'
- ],
- 'mattermost' => [
- {
- required: true,
- name: :webhook,
- type: String,
- desc: 'The Mattermost webhook. e.g. http://mattermost_host/hooks/...'
- }
- ],
- 'teamcity' => [
- {
- required: true,
- name: :teamcity_url,
- type: String,
- desc: 'TeamCity root URL like https://teamcity.example.com'
- },
- {
- required: true,
- name: :build_type,
- type: String,
- desc: 'Build configuration ID'
- },
- {
- required: true,
- name: :username,
- type: String,
- desc: 'A user with permissions to trigger a manual build'
- },
- {
- required: true,
- name: :password,
- type: String,
- desc: 'The password of the user'
- }
- ]
- }
-
- trigger_services = {
- 'mattermost-slash-commands' => [
- {
- name: :token,
- type: String,
- desc: 'The Mattermost token'
- }
- ],
- 'slack-slash-commands' => [
- {
- name: :token,
- type: String,
- desc: 'The Slack token'
- }
- ]
- }.freeze
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- before { authenticate! }
- before { authorize_admin_project }
-
- helpers do
- def service_attributes(service)
- service.fields.inject([]) do |arr, hash|
- arr << hash[:name].to_sym
- end
- end
- end
-
- desc "Delete a service for project"
- params do
- requires :service_slug, type: String, values: services.keys, desc: 'The name of the service'
- end
- delete ":id/services/:service_slug" do
- service = user_project.find_or_initialize_service(params[:service_slug].underscore)
-
- attrs = service_attributes(service).inject({}) do |hash, key|
- hash.merge!(key => nil)
- end
-
- if service.update_attributes(attrs.merge(active: false))
- status(200)
- true
- else
- render_api_error!('400 Bad Request', 400)
- end
- end
-
- desc 'Get the service settings for project' do
- success Entities::ProjectService
- end
- params do
- requires :service_slug, type: String, values: services.keys, desc: 'The name of the service'
- end
- get ":id/services/:service_slug" do
- service = user_project.find_or_initialize_service(params[:service_slug].underscore)
- present service, with: Entities::ProjectService
- end
- end
-
- trigger_services.each do |service_slug, settings|
- helpers do
- def slash_command_service(project, service_slug, params)
- project.services.active.where(template: false).find do |service|
- service.try(:token) == params[:token] && service.to_param == service_slug.underscore
- end
- end
- end
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc "Trigger a slash command for #{service_slug}" do
- detail 'Added in GitLab 8.13'
- end
- params do
- settings.each do |setting|
- requires setting[:name], type: setting[:type], desc: setting[:desc]
- end
- end
- post ":id/services/#{service_slug.underscore}/trigger" do
- project = find_project(params[:id])
-
- # This is not accurate, but done to prevent leakage of the project names
- not_found!('Service') unless project
-
- service = slash_command_service(project, service_slug, params)
- result = service.try(:trigger, params)
-
- if result
- status result[:status] || 200
- present result
- else
- not_found!('Service')
- end
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/settings.rb b/lib/api/v3/settings.rb
deleted file mode 100644
index fc56495c8b1..00000000000
--- a/lib/api/v3/settings.rb
+++ /dev/null
@@ -1,147 +0,0 @@
-module API
- module V3
- class Settings < Grape::API
- before { authenticated_as_admin! }
-
- helpers do
- def current_settings
- @current_setting ||=
- (ApplicationSetting.current_without_cache || ApplicationSetting.create_from_defaults)
- end
- end
-
- desc 'Get the current application settings' do
- success Entities::ApplicationSetting
- end
- get "application/settings" do
- present current_settings, with: Entities::ApplicationSetting
- end
-
- desc 'Modify application settings' do
- success Entities::ApplicationSetting
- end
- params do
- optional :default_branch_protection, type: Integer, values: [0, 1, 2], desc: 'Determine if developers can push to master'
- optional :default_project_visibility, type: Integer, values: Gitlab::VisibilityLevel.values, desc: 'The default project visibility'
- optional :default_snippet_visibility, type: Integer, values: Gitlab::VisibilityLevel.values, desc: 'The default snippet visibility'
- optional :default_group_visibility, type: Integer, values: Gitlab::VisibilityLevel.values, desc: 'The default group visibility'
- optional :restricted_visibility_levels, type: Array[String], desc: 'Selected levels cannot be used by non-admin users for projects or snippets. If the public level is restricted, user profiles are only visible to logged in users.'
- optional :import_sources, type: Array[String], values: %w[github bitbucket gitlab google_code fogbugz git gitlab_project],
- desc: 'Enabled sources for code import during project creation. OmniAuth must be configured for GitHub, Bitbucket, and GitLab.com'
- optional :disabled_oauth_sign_in_sources, type: Array[String], desc: 'Disable certain OAuth sign-in sources'
- optional :enabled_git_access_protocol, type: String, values: %w[ssh http nil], desc: 'Allow only the selected protocols to be used for Git access.'
- optional :gravatar_enabled, type: Boolean, desc: 'Flag indicating if the Gravatar service is enabled'
- optional :default_projects_limit, type: Integer, desc: 'The maximum number of personal projects'
- optional :max_attachment_size, type: Integer, desc: 'Maximum attachment size in MB'
- optional :session_expire_delay, type: Integer, desc: 'Session duration in minutes. GitLab restart is required to apply changes.'
- optional :user_oauth_applications, type: Boolean, desc: 'Allow users to register any application to use GitLab as an OAuth provider'
- optional :user_default_external, type: Boolean, desc: 'Newly registered users will by default be external'
- optional :signup_enabled, type: Boolean, desc: 'Flag indicating if sign up is enabled'
- optional :send_user_confirmation_email, type: Boolean, desc: 'Send confirmation email on sign-up'
- optional :domain_whitelist, type: String, desc: 'ONLY users with e-mail addresses that match these domain(s) will be able to sign-up. Wildcards allowed. Use separate lines for multiple entries. Ex: domain.com, *.domain.com'
- optional :domain_blacklist_enabled, type: Boolean, desc: 'Enable domain blacklist for sign ups'
- given domain_blacklist_enabled: ->(val) { val } do
- requires :domain_blacklist, type: String, desc: 'Users with e-mail addresses that match these domain(s) will NOT be able to sign-up. Wildcards allowed. Use separate lines for multiple entries. Ex: domain.com, *.domain.com'
- end
- optional :after_sign_up_text, type: String, desc: 'Text shown after sign up'
- optional :password_authentication_enabled, type: Boolean, desc: 'Flag indicating if password authentication is enabled for the web interface'
- optional :signin_enabled, type: Boolean, desc: 'Flag indicating if password authentication is enabled for the web interface'
- mutually_exclusive :password_authentication_enabled, :signin_enabled
- optional :require_two_factor_authentication, type: Boolean, desc: 'Require all users to setup Two-factor authentication'
- given require_two_factor_authentication: ->(val) { val } do
- requires :two_factor_grace_period, type: Integer, desc: 'Amount of time (in hours) that users are allowed to skip forced configuration of two-factor authentication'
- end
- optional :home_page_url, type: String, desc: 'We will redirect non-logged in users to this page'
- optional :after_sign_out_path, type: String, desc: 'We will redirect users to this page after they sign out'
- optional :sign_in_text, type: String, desc: 'The sign in text of the GitLab application'
- optional :help_page_text, type: String, desc: 'Custom text displayed on the help page'
- optional :shared_runners_enabled, type: Boolean, desc: 'Enable shared runners for new projects'
- given shared_runners_enabled: ->(val) { val } do
- requires :shared_runners_text, type: String, desc: 'Shared runners text '
- end
- optional :max_artifacts_size, type: Integer, desc: "Set the maximum file size each build's artifacts can have"
- optional :max_pages_size, type: Integer, desc: 'Maximum size of pages in MB'
- optional :container_registry_token_expire_delay, type: Integer, desc: 'Authorization token duration (minutes)'
- optional :metrics_enabled, type: Boolean, desc: 'Enable the InfluxDB metrics'
- given metrics_enabled: ->(val) { val } do
- requires :metrics_host, type: String, desc: 'The InfluxDB host'
- requires :metrics_port, type: Integer, desc: 'The UDP port to use for connecting to InfluxDB'
- requires :metrics_pool_size, type: Integer, desc: 'The amount of InfluxDB connections to open'
- requires :metrics_timeout, type: Integer, desc: 'The amount of seconds after which an InfluxDB connection will time out'
- requires :metrics_method_call_threshold, type: Integer, desc: 'A method call is only tracked when it takes longer to complete than the given amount of milliseconds.'
- requires :metrics_sample_interval, type: Integer, desc: 'The sampling interval in seconds'
- requires :metrics_packet_size, type: Integer, desc: 'The amount of points to store in a single UDP packet'
- end
- optional :sidekiq_throttling_enabled, type: Boolean, desc: 'Enable Sidekiq Job Throttling'
- given sidekiq_throttling_enabled: ->(val) { val } do
- requires :sidekiq_throttling_queus, type: Array[String], desc: 'Choose which queues you wish to throttle'
- requires :sidekiq_throttling_factor, type: Float, desc: 'The factor by which the queues should be throttled. A value between 0.0 and 1.0, exclusive.'
- end
- optional :recaptcha_enabled, type: Boolean, desc: 'Helps prevent bots from creating accounts'
- given recaptcha_enabled: ->(val) { val } do
- requires :recaptcha_site_key, type: String, desc: 'Generate site key at http://www.google.com/recaptcha'
- requires :recaptcha_private_key, type: String, desc: 'Generate private key at http://www.google.com/recaptcha'
- end
- optional :akismet_enabled, type: Boolean, desc: 'Helps prevent bots from creating issues'
- given akismet_enabled: ->(val) { val } do
- requires :akismet_api_key, type: String, desc: 'Generate API key at http://www.akismet.com'
- end
- optional :admin_notification_email, type: String, desc: 'Abuse reports will be sent to this address if it is set. Abuse reports are always available in the admin area.'
- optional :sentry_enabled, type: Boolean, desc: 'Sentry is an error reporting and logging tool which is currently not shipped with GitLab, get it here: https://getsentry.com'
- given sentry_enabled: ->(val) { val } do
- requires :sentry_dsn, type: String, desc: 'Sentry Data Source Name'
- end
- optional :repository_storage, type: String, desc: 'Storage paths for new projects'
- optional :repository_checks_enabled, type: Boolean, desc: "GitLab will periodically run 'git fsck' in all project and wiki repositories to look for silent disk corruption issues."
- optional :koding_enabled, type: Boolean, desc: 'Enable Koding'
- given koding_enabled: ->(val) { val } do
- requires :koding_url, type: String, desc: 'The Koding team URL'
- end
- optional :plantuml_enabled, type: Boolean, desc: 'Enable PlantUML'
- given plantuml_enabled: ->(val) { val } do
- requires :plantuml_url, type: String, desc: 'The PlantUML server URL'
- end
- optional :version_check_enabled, type: Boolean, desc: 'Let GitLab inform you when an update is available.'
- optional :email_author_in_body, type: Boolean, desc: 'Some email servers do not support overriding the email sender name. Enable this option to include the name of the author of the issue, merge request or comment in the email body instead.'
- optional :html_emails_enabled, type: Boolean, desc: 'By default GitLab sends emails in HTML and plain text formats so mail clients can choose what format to use. Disable this option if you only want to send emails in plain text format.'
- optional :housekeeping_enabled, type: Boolean, desc: 'Enable automatic repository housekeeping (git repack, git gc)'
- given housekeeping_enabled: ->(val) { val } do
- requires :housekeeping_bitmaps_enabled, type: Boolean, desc: "Creating pack file bitmaps makes housekeeping take a little longer but bitmaps should accelerate 'git clone' performance."
- requires :housekeeping_incremental_repack_period, type: Integer, desc: "Number of Git pushes after which an incremental 'git repack' is run."
- requires :housekeeping_full_repack_period, type: Integer, desc: "Number of Git pushes after which a full 'git repack' is run."
- requires :housekeeping_gc_period, type: Integer, desc: "Number of Git pushes after which 'git gc' is run."
- end
- optional :terminal_max_session_time, type: Integer, desc: 'Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time.'
- at_least_one_of :default_branch_protection, :default_project_visibility, :default_snippet_visibility,
- :default_group_visibility, :restricted_visibility_levels, :import_sources,
- :enabled_git_access_protocol, :gravatar_enabled, :default_projects_limit,
- :max_attachment_size, :session_expire_delay, :disabled_oauth_sign_in_sources,
- :user_oauth_applications, :user_default_external, :signup_enabled,
- :send_user_confirmation_email, :domain_whitelist, :domain_blacklist_enabled,
- :after_sign_up_text, :password_authentication_enabled, :signin_enabled, :require_two_factor_authentication,
- :home_page_url, :after_sign_out_path, :sign_in_text, :help_page_text,
- :shared_runners_enabled, :max_artifacts_size, :max_pages_size, :container_registry_token_expire_delay,
- :metrics_enabled, :sidekiq_throttling_enabled, :recaptcha_enabled,
- :akismet_enabled, :admin_notification_email, :sentry_enabled,
- :repository_storage, :repository_checks_enabled, :koding_enabled, :plantuml_enabled,
- :version_check_enabled, :email_author_in_body, :html_emails_enabled,
- :housekeeping_enabled, :terminal_max_session_time
- end
- put "application/settings" do
- attrs = declared_params(include_missing: false)
-
- if attrs.has_key?(:signin_enabled)
- attrs[:password_authentication_enabled_for_web] = attrs.delete(:signin_enabled)
- elsif attrs.has_key?(:password_authentication_enabled)
- attrs[:password_authentication_enabled_for_web] = attrs.delete(:password_authentication_enabled)
- end
-
- if current_settings.update_attributes(attrs)
- present current_settings, with: Entities::ApplicationSetting
- else
- render_validation_error!(current_settings)
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/snippets.rb b/lib/api/v3/snippets.rb
deleted file mode 100644
index 1df8a20e74a..00000000000
--- a/lib/api/v3/snippets.rb
+++ /dev/null
@@ -1,141 +0,0 @@
-module API
- module V3
- class Snippets < Grape::API
- include PaginationParams
-
- before { authenticate! }
-
- resource :snippets do
- helpers do
- def snippets_for_current_user
- SnippetsFinder.new(current_user, author: current_user).execute
- end
-
- def public_snippets
- SnippetsFinder.new(current_user, visibility: Snippet::PUBLIC).execute
- end
- end
-
- desc 'Get a snippets list for authenticated user' do
- detail 'This feature was introduced in GitLab 8.15.'
- success ::API::Entities::PersonalSnippet
- end
- params do
- use :pagination
- end
- get do
- present paginate(snippets_for_current_user), with: ::API::Entities::PersonalSnippet
- end
-
- desc 'List all public snippets current_user has access to' do
- detail 'This feature was introduced in GitLab 8.15.'
- success ::API::Entities::PersonalSnippet
- end
- params do
- use :pagination
- end
- get 'public' do
- present paginate(public_snippets), with: ::API::Entities::PersonalSnippet
- end
-
- desc 'Get a single snippet' do
- detail 'This feature was introduced in GitLab 8.15.'
- success ::API::Entities::PersonalSnippet
- end
- params do
- requires :id, type: Integer, desc: 'The ID of a snippet'
- end
- get ':id' do
- snippet = snippets_for_current_user.find(params[:id])
- present snippet, with: ::API::Entities::PersonalSnippet
- end
-
- desc 'Create new snippet' do
- detail 'This feature was introduced in GitLab 8.15.'
- success ::API::Entities::PersonalSnippet
- end
- params do
- requires :title, type: String, desc: 'The title of a snippet'
- requires :file_name, type: String, desc: 'The name of a snippet file'
- requires :content, type: String, desc: 'The content of a snippet'
- optional :visibility_level, type: Integer,
- values: Gitlab::VisibilityLevel.values,
- default: Gitlab::VisibilityLevel::INTERNAL,
- desc: 'The visibility level of the snippet'
- end
- post do
- attrs = declared_params(include_missing: false).merge(request: request, api: true)
- snippet = CreateSnippetService.new(nil, current_user, attrs).execute
-
- if snippet.persisted?
- present snippet, with: ::API::Entities::PersonalSnippet
- else
- render_validation_error!(snippet)
- end
- end
-
- desc 'Update an existing snippet' do
- detail 'This feature was introduced in GitLab 8.15.'
- success ::API::Entities::PersonalSnippet
- end
- params do
- requires :id, type: Integer, desc: 'The ID of a snippet'
- optional :title, type: String, desc: 'The title of a snippet'
- optional :file_name, type: String, desc: 'The name of a snippet file'
- optional :content, type: String, desc: 'The content of a snippet'
- optional :visibility_level, type: Integer,
- values: Gitlab::VisibilityLevel.values,
- desc: 'The visibility level of the snippet'
- at_least_one_of :title, :file_name, :content, :visibility_level
- end
- put ':id' do
- snippet = snippets_for_current_user.find_by(id: params.delete(:id))
- break not_found!('Snippet') unless snippet
-
- authorize! :update_personal_snippet, snippet
-
- attrs = declared_params(include_missing: false)
-
- UpdateSnippetService.new(nil, current_user, snippet, attrs).execute
-
- if snippet.persisted?
- present snippet, with: ::API::Entities::PersonalSnippet
- else
- render_validation_error!(snippet)
- end
- end
-
- desc 'Remove snippet' do
- detail 'This feature was introduced in GitLab 8.15.'
- success ::API::Entities::PersonalSnippet
- end
- params do
- requires :id, type: Integer, desc: 'The ID of a snippet'
- end
- delete ':id' do
- snippet = snippets_for_current_user.find_by(id: params.delete(:id))
- break not_found!('Snippet') unless snippet
-
- authorize! :destroy_personal_snippet, snippet
- snippet.destroy
- no_content!
- end
-
- desc 'Get a raw snippet' do
- detail 'This feature was introduced in GitLab 8.15.'
- end
- params do
- requires :id, type: Integer, desc: 'The ID of a snippet'
- end
- get ":id/raw" do
- snippet = snippets_for_current_user.find_by(id: params.delete(:id))
- break not_found!('Snippet') unless snippet
-
- env['api.format'] = :txt
- content_type 'text/plain'
- present snippet.content
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/subscriptions.rb b/lib/api/v3/subscriptions.rb
deleted file mode 100644
index 690768db82f..00000000000
--- a/lib/api/v3/subscriptions.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-module API
- module V3
- class Subscriptions < Grape::API
- before { authenticate! }
-
- subscribable_types = {
- 'merge_request' => proc { |id| find_merge_request_with_access(id, :update_merge_request) },
- 'merge_requests' => proc { |id| find_merge_request_with_access(id, :update_merge_request) },
- 'issues' => proc { |id| find_project_issue(id) },
- 'labels' => proc { |id| find_project_label(id) }
- }
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- requires :subscribable_id, type: String, desc: 'The ID of a resource'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- subscribable_types.each do |type, finder|
- type_singularized = type.singularize
- entity_class = ::API::Entities.const_get(type_singularized.camelcase)
-
- desc 'Subscribe to a resource' do
- success entity_class
- end
- post ":id/#{type}/:subscribable_id/subscription" do
- resource = instance_exec(params[:subscribable_id], &finder)
-
- if resource.subscribed?(current_user, user_project)
- not_modified!
- else
- resource.subscribe(current_user, user_project)
- present resource, with: entity_class, current_user: current_user, project: user_project
- end
- end
-
- desc 'Unsubscribe from a resource' do
- success entity_class
- end
- delete ":id/#{type}/:subscribable_id/subscription" do
- resource = instance_exec(params[:subscribable_id], &finder)
-
- if !resource.subscribed?(current_user, user_project)
- not_modified!
- else
- resource.unsubscribe(current_user, user_project)
- present resource, with: entity_class, current_user: current_user, project: user_project
- end
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/system_hooks.rb b/lib/api/v3/system_hooks.rb
deleted file mode 100644
index 5787c06fc12..00000000000
--- a/lib/api/v3/system_hooks.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-module API
- module V3
- class SystemHooks < Grape::API
- before do
- authenticate!
- authenticated_as_admin!
- end
-
- resource :hooks do
- desc 'Get the list of system hooks' do
- success ::API::Entities::Hook
- end
- get do
- present SystemHook.all, with: ::API::Entities::Hook
- end
-
- desc 'Delete a hook' do
- success ::API::Entities::Hook
- end
- params do
- requires :id, type: Integer, desc: 'The ID of the system hook'
- end
- delete ":id" do
- hook = SystemHook.find_by(id: params[:id])
- not_found!('System hook') unless hook
-
- present hook.destroy, with: ::API::Entities::Hook
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/tags.rb b/lib/api/v3/tags.rb
deleted file mode 100644
index 6e37d31d153..00000000000
--- a/lib/api/v3/tags.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-module API
- module V3
- class Tags < Grape::API
- before { authorize! :download_code, user_project }
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Get a project repository tags' do
- success ::API::Entities::Tag
- end
- get ":id/repository/tags" do
- tags = user_project.repository.tags.sort_by(&:name).reverse
- present tags, with: ::API::Entities::Tag, project: user_project
- end
-
- desc 'Delete a repository tag'
- params do
- requires :tag_name, type: String, desc: 'The name of the tag'
- end
- delete ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do
- authorize_push_project
-
- result = ::Tags::DestroyService.new(user_project, current_user)
- .execute(params[:tag_name])
-
- if result[:status] == :success
- status(200)
- {
- tag_name: params[:tag_name]
- }
- else
- render_api_error!(result[:message], result[:return_code])
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/templates.rb b/lib/api/v3/templates.rb
deleted file mode 100644
index b82b02b5f49..00000000000
--- a/lib/api/v3/templates.rb
+++ /dev/null
@@ -1,122 +0,0 @@
-module API
- module V3
- class Templates < Grape::API
- GLOBAL_TEMPLATE_TYPES = {
- gitignores: {
- klass: Gitlab::Template::GitignoreTemplate,
- gitlab_version: 8.8
- },
- gitlab_ci_ymls: {
- klass: Gitlab::Template::GitlabCiYmlTemplate,
- gitlab_version: 8.9
- },
- dockerfiles: {
- klass: Gitlab::Template::DockerfileTemplate,
- gitlab_version: 8.15
- }
- }.freeze
- PROJECT_TEMPLATE_REGEX =
- %r{[\<\{\[]
- (project|description|
- one\sline\s.+\swhat\sit\sdoes\.) # matching the start and end is enough here
- [\>\}\]]}xi.freeze
- YEAR_TEMPLATE_REGEX = /[<{\[](year|yyyy)[>}\]]/i.freeze
- FULLNAME_TEMPLATE_REGEX =
- %r{[\<\{\[]
- (fullname|name\sof\s(author|copyright\sowner))
- [\>\}\]]}xi.freeze
- DEPRECATION_MESSAGE = ' This endpoint is deprecated and has been removed in V4.'.freeze
-
- helpers do
- def parsed_license_template
- # We create a fresh Licensee::License object since we'll modify its
- # content in place below.
- template = Licensee::License.new(params[:name])
-
- template.content.gsub!(YEAR_TEMPLATE_REGEX, Time.now.year.to_s)
- template.content.gsub!(PROJECT_TEMPLATE_REGEX, params[:project]) if params[:project].present?
-
- fullname = params[:fullname].presence || current_user.try(:name)
- template.content.gsub!(FULLNAME_TEMPLATE_REGEX, fullname) if fullname
- template
- end
-
- def render_response(template_type, template)
- not_found!(template_type.to_s.singularize) unless template
- present template, with: ::API::Entities::Template
- end
- end
-
- { "licenses" => :deprecated, "templates/licenses" => :ok }.each do |route, status|
- desc 'Get the list of the available license template' do
- detailed_desc = 'This feature was introduced in GitLab 8.7.'
- detailed_desc << DEPRECATION_MESSAGE unless status == :ok
- detail detailed_desc
- success ::API::Entities::License
- end
- params do
- optional :popular, type: Boolean, desc: 'If passed, returns only popular licenses'
- end
- get route do
- options = {
- featured: declared(params)[:popular].present? ? true : nil
- }
- present Licensee::License.all(options), with: ::API::Entities::License
- end
- end
-
- { "licenses/:name" => :deprecated, "templates/licenses/:name" => :ok }.each do |route, status|
- desc 'Get the text for a specific license' do
- detailed_desc = 'This feature was introduced in GitLab 8.7.'
- detailed_desc << DEPRECATION_MESSAGE unless status == :ok
- detail detailed_desc
- success ::API::Entities::License
- end
- params do
- requires :name, type: String, desc: 'The name of the template'
- end
- get route, requirements: { name: /[\w\.-]+/ } do
- not_found!('License') unless Licensee::License.find(declared(params)[:name])
-
- template = parsed_license_template
-
- present template, with: ::API::Entities::License
- end
- end
-
- GLOBAL_TEMPLATE_TYPES.each do |template_type, properties|
- klass = properties[:klass]
- gitlab_version = properties[:gitlab_version]
-
- { template_type => :deprecated, "templates/#{template_type}" => :ok }.each do |route, status|
- desc 'Get the list of the available template' do
- detailed_desc = "This feature was introduced in GitLab #{gitlab_version}."
- detailed_desc << DEPRECATION_MESSAGE unless status == :ok
- detail detailed_desc
- success ::API::Entities::TemplatesList
- end
- get route do
- present klass.all, with: ::API::Entities::TemplatesList
- end
- end
-
- { "#{template_type}/:name" => :deprecated, "templates/#{template_type}/:name" => :ok }.each do |route, status|
- desc 'Get the text for a specific template present in local filesystem' do
- detailed_desc = "This feature was introduced in GitLab #{gitlab_version}."
- detailed_desc << DEPRECATION_MESSAGE unless status == :ok
- detail detailed_desc
- success ::API::Entities::Template
- end
- params do
- requires :name, type: String, desc: 'The name of the template'
- end
- get route do
- new_template = klass.find(declared(params)[:name])
-
- render_response(template_type, new_template)
- end
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/time_tracking_endpoints.rb b/lib/api/v3/time_tracking_endpoints.rb
deleted file mode 100644
index 1aad39815f9..00000000000
--- a/lib/api/v3/time_tracking_endpoints.rb
+++ /dev/null
@@ -1,116 +0,0 @@
-module API
- module V3
- module TimeTrackingEndpoints
- extend ActiveSupport::Concern
-
- included do
- helpers do
- def issuable_name
- declared_params.key?(:issue_id) ? 'issue' : 'merge_request'
- end
-
- def issuable_key
- "#{issuable_name}_id".to_sym
- end
-
- def update_issuable_key
- "update_#{issuable_name}".to_sym
- end
-
- def read_issuable_key
- "read_#{issuable_name}".to_sym
- end
-
- def load_issuable
- @issuable ||= begin
- case issuable_name
- when 'issue'
- find_project_issue(params.delete(issuable_key))
- when 'merge_request'
- find_project_merge_request(params.delete(issuable_key))
- end
- end
- end
-
- def update_issuable(attrs)
- custom_params = declared_params(include_missing: false)
- custom_params.merge!(attrs)
-
- issuable = update_service.new(user_project, current_user, custom_params).execute(load_issuable)
- if issuable.valid?
- present issuable, with: ::API::Entities::IssuableTimeStats
- else
- render_validation_error!(issuable)
- end
- end
-
- def update_service
- issuable_name == 'issue' ? ::Issues::UpdateService : ::MergeRequests::UpdateService
- end
- end
-
- issuable_name = name.end_with?('Issues') ? 'issue' : 'merge_request'
- issuable_collection_name = issuable_name.pluralize
- issuable_key = "#{issuable_name}_id".to_sym
-
- desc "Set a time estimate for a project #{issuable_name}"
- params do
- requires issuable_key, type: Integer, desc: "The ID of a project #{issuable_name}"
- requires :duration, type: String, desc: 'The duration to be parsed'
- end
- post ":id/#{issuable_collection_name}/:#{issuable_key}/time_estimate" do
- authorize! update_issuable_key, load_issuable
-
- status :ok
- update_issuable(time_estimate: Gitlab::TimeTrackingFormatter.parse(params.delete(:duration)))
- end
-
- desc "Reset the time estimate for a project #{issuable_name}"
- params do
- requires issuable_key, type: Integer, desc: "The ID of a project #{issuable_name}"
- end
- post ":id/#{issuable_collection_name}/:#{issuable_key}/reset_time_estimate" do
- authorize! update_issuable_key, load_issuable
-
- status :ok
- update_issuable(time_estimate: 0)
- end
-
- desc "Add spent time for a project #{issuable_name}"
- params do
- requires issuable_key, type: Integer, desc: "The ID of a project #{issuable_name}"
- requires :duration, type: String, desc: 'The duration to be parsed'
- end
- post ":id/#{issuable_collection_name}/:#{issuable_key}/add_spent_time" do
- authorize! update_issuable_key, load_issuable
-
- update_issuable(spend_time: {
- duration: Gitlab::TimeTrackingFormatter.parse(params.delete(:duration)),
- user_id: current_user.id
- })
- end
-
- desc "Reset spent time for a project #{issuable_name}"
- params do
- requires issuable_key, type: Integer, desc: "The ID of a project #{issuable_name}"
- end
- post ":id/#{issuable_collection_name}/:#{issuable_key}/reset_spent_time" do
- authorize! update_issuable_key, load_issuable
-
- status :ok
- update_issuable(spend_time: { duration: :reset, user_id: current_user.id })
- end
-
- desc "Show time stats for a project #{issuable_name}"
- params do
- requires issuable_key, type: Integer, desc: "The ID of a project #{issuable_name}"
- end
- get ":id/#{issuable_collection_name}/:#{issuable_key}/time_stats" do
- authorize! read_issuable_key, load_issuable
-
- present load_issuable, with: ::API::Entities::IssuableTimeStats
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/todos.rb b/lib/api/v3/todos.rb
deleted file mode 100644
index 3e2c61f6dbd..00000000000
--- a/lib/api/v3/todos.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-module API
- module V3
- class Todos < Grape::API
- before { authenticate! }
-
- resource :todos do
- desc 'Mark a todo as done' do
- success ::API::Entities::Todo
- end
- params do
- requires :id, type: Integer, desc: 'The ID of the todo being marked as done'
- end
- delete ':id' do
- TodoService.new.mark_todos_as_done_by_ids(params[:id], current_user)
- todo = current_user.todos.find(params[:id])
-
- present todo, with: ::API::Entities::Todo, current_user: current_user
- end
-
- desc 'Mark all todos as done'
- delete do
- status(200)
-
- todos = TodosFinder.new(current_user, params).execute
- TodoService.new.mark_todos_as_done(todos, current_user).size
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/triggers.rb b/lib/api/v3/triggers.rb
deleted file mode 100644
index 969bb2a05de..00000000000
--- a/lib/api/v3/triggers.rb
+++ /dev/null
@@ -1,112 +0,0 @@
-module API
- module V3
- class Triggers < Grape::API
- include PaginationParams
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Trigger a GitLab project build' do
- success ::API::V3::Entities::TriggerRequest
- end
- params do
- requires :ref, type: String, desc: 'The commit sha or name of a branch or tag'
- requires :token, type: String, desc: 'The unique token of trigger'
- optional :variables, type: Hash, desc: 'The list of variables to be injected into build'
- end
- post ":id/(ref/:ref/)trigger/builds", requirements: { ref: /.+/ } do
- Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42121')
-
- # validate variables
- params[:variables] = params[:variables].to_h
- unless params[:variables].all? { |key, value| key.is_a?(String) && value.is_a?(String) }
- render_api_error!('variables needs to be a map of key-valued strings', 400)
- end
-
- project = find_project(params[:id])
- not_found! unless project
-
- result = Ci::PipelineTriggerService.new(project, nil, params).execute
- not_found! unless result
-
- if result[:http_status]
- render_api_error!(result[:message], result[:http_status])
- else
- pipeline = result[:pipeline]
-
- # We switched to Ci::PipelineVariable from Ci::TriggerRequest.variables.
- # Ci::TriggerRequest doesn't save variables anymore.
- # Here is copying Ci::PipelineVariable to Ci::TriggerRequest.variables for presenting the variables.
- # The same endpoint in v4 API pressents Pipeline instead of TriggerRequest, so it doesn't need such a process.
- trigger_request = pipeline.trigger_requests.last
- trigger_request.variables = params[:variables]
-
- present trigger_request, with: ::API::V3::Entities::TriggerRequest
- end
- end
-
- desc 'Get triggers list' do
- success ::API::V3::Entities::Trigger
- end
- params do
- use :pagination
- end
- get ':id/triggers' do
- authenticate!
- authorize! :admin_build, user_project
-
- triggers = user_project.triggers.includes(:trigger_requests)
-
- present paginate(triggers), with: ::API::V3::Entities::Trigger
- end
-
- desc 'Get specific trigger of a project' do
- success ::API::V3::Entities::Trigger
- end
- params do
- requires :token, type: String, desc: 'The unique token of trigger'
- end
- get ':id/triggers/:token' do
- authenticate!
- authorize! :admin_build, user_project
-
- trigger = user_project.triggers.find_by(token: params[:token].to_s)
- break not_found!('Trigger') unless trigger
-
- present trigger, with: ::API::V3::Entities::Trigger
- end
-
- desc 'Create a trigger' do
- success ::API::V3::Entities::Trigger
- end
- post ':id/triggers' do
- authenticate!
- authorize! :admin_build, user_project
-
- trigger = user_project.triggers.create
-
- present trigger, with: ::API::V3::Entities::Trigger
- end
-
- desc 'Delete a trigger' do
- success ::API::V3::Entities::Trigger
- end
- params do
- requires :token, type: String, desc: 'The unique token of trigger'
- end
- delete ':id/triggers/:token' do
- authenticate!
- authorize! :admin_build, user_project
-
- trigger = user_project.triggers.find_by(token: params[:token].to_s)
- break not_found!('Trigger') unless trigger
-
- trigger.destroy
-
- present trigger, with: ::API::V3::Entities::Trigger
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/users.rb b/lib/api/v3/users.rb
deleted file mode 100644
index cf106f2552d..00000000000
--- a/lib/api/v3/users.rb
+++ /dev/null
@@ -1,204 +0,0 @@
-module API
- module V3
- class Users < Grape::API
- include PaginationParams
- include APIGuard
-
- allow_access_with_scope :read_user, if: -> (request) { request.get? }
-
- before do
- authenticate!
- end
-
- resource :users, requirements: { uid: /[0-9]*/, id: /[0-9]*/ } do
- helpers do
- params :optional_attributes do
- optional :skype, type: String, desc: 'The Skype username'
- optional :linkedin, type: String, desc: 'The LinkedIn username'
- optional :twitter, type: String, desc: 'The Twitter username'
- optional :website_url, type: String, desc: 'The website of the user'
- optional :organization, type: String, desc: 'The organization of the user'
- optional :projects_limit, type: Integer, desc: 'The number of projects a user can create'
- optional :extern_uid, type: String, desc: 'The external authentication provider UID'
- optional :provider, type: String, desc: 'The external provider'
- optional :bio, type: String, desc: 'The biography of the user'
- optional :location, type: String, desc: 'The location of the user'
- optional :admin, type: Boolean, desc: 'Flag indicating the user is an administrator'
- optional :can_create_group, type: Boolean, desc: 'Flag indicating the user can create groups'
- optional :confirm, type: Boolean, default: true, desc: 'Flag indicating the account needs to be confirmed'
- optional :external, type: Boolean, desc: 'Flag indicating the user is an external user'
- all_or_none_of :extern_uid, :provider
- end
- end
-
- desc 'Create a user. Available only for admins.' do
- success ::API::Entities::UserPublic
- end
- params do
- requires :email, type: String, desc: 'The email of the user'
- optional :password, type: String, desc: 'The password of the new user'
- optional :reset_password, type: Boolean, desc: 'Flag indicating the user will be sent a password reset token'
- at_least_one_of :password, :reset_password
- requires :name, type: String, desc: 'The name of the user'
- requires :username, type: String, desc: 'The username of the user'
- use :optional_attributes
- end
- post do
- authenticated_as_admin!
-
- params = declared_params(include_missing: false)
- user = ::Users::CreateService.new(current_user, params.merge!(skip_confirmation: !params[:confirm])).execute
-
- if user.persisted?
- present user, with: ::API::Entities::UserPublic
- else
- conflict!('Email has already been taken') if User
- .where(email: user.email)
- .count > 0
-
- conflict!('Username has already been taken') if User
- .where(username: user.username)
- .count > 0
-
- render_validation_error!(user)
- end
- end
-
- desc 'Get the SSH keys of a specified user. Available only for admins.' do
- success ::API::Entities::SSHKey
- end
- params do
- requires :id, type: Integer, desc: 'The ID of the user'
- use :pagination
- end
- get ':id/keys' do
- authenticated_as_admin!
-
- user = User.find_by(id: params[:id])
- not_found!('User') unless user
-
- present paginate(user.keys), with: ::API::Entities::SSHKey
- end
-
- desc 'Get the emails addresses of a specified user. Available only for admins.' do
- success ::API::Entities::Email
- end
- params do
- requires :id, type: Integer, desc: 'The ID of the user'
- use :pagination
- end
- get ':id/emails' do
- authenticated_as_admin!
- user = User.find_by(id: params[:id])
- not_found!('User') unless user
-
- present user.emails, with: ::API::Entities::Email
- end
-
- desc 'Block a user. Available only for admins.'
- params do
- requires :id, type: Integer, desc: 'The ID of the user'
- end
- put ':id/block' do
- authenticated_as_admin!
- user = User.find_by(id: params[:id])
- not_found!('User') unless user
-
- if !user.ldap_blocked?
- user.block
- else
- forbidden!('LDAP blocked users cannot be modified by the API')
- end
- end
-
- desc 'Unblock a user. Available only for admins.'
- params do
- requires :id, type: Integer, desc: 'The ID of the user'
- end
- put ':id/unblock' do
- authenticated_as_admin!
- user = User.find_by(id: params[:id])
- not_found!('User') unless user
-
- if user.ldap_blocked?
- forbidden!('LDAP blocked users cannot be unblocked by the API')
- else
- user.activate
- end
- end
-
- desc 'Get the contribution events of a specified user' do
- detail 'This feature was introduced in GitLab 8.13.'
- success ::API::V3::Entities::Event
- end
- params do
- requires :id, type: Integer, desc: 'The ID of the user'
- use :pagination
- end
- get ':id/events' do
- user = User.find_by(id: params[:id])
- not_found!('User') unless user
-
- events = user.events
- .merge(ProjectsFinder.new(current_user: current_user).execute)
- .references(:project)
- .with_associations
- .recent
-
- present paginate(events), with: ::API::V3::Entities::Event
- end
-
- desc 'Delete an existing SSH key from a specified user. Available only for admins.' do
- success ::API::Entities::SSHKey
- end
- params do
- requires :id, type: Integer, desc: 'The ID of the user'
- requires :key_id, type: Integer, desc: 'The ID of the SSH key'
- end
- delete ':id/keys/:key_id' do
- authenticated_as_admin!
-
- user = User.find_by(id: params[:id])
- not_found!('User') unless user
-
- key = user.keys.find_by(id: params[:key_id])
- not_found!('Key') unless key
-
- present key.destroy, with: ::API::Entities::SSHKey
- end
- end
-
- resource :user do
- desc "Get the currently authenticated user's SSH keys" do
- success ::API::Entities::SSHKey
- end
- params do
- use :pagination
- end
- get "keys" do
- present current_user.keys, with: ::API::Entities::SSHKey
- end
-
- desc "Get the currently authenticated user's email addresses" do
- success ::API::Entities::Email
- end
- get "emails" do
- present current_user.emails, with: ::API::Entities::Email
- end
-
- desc 'Delete an SSH key from the currently authenticated user' do
- success ::API::Entities::SSHKey
- end
- params do
- requires :key_id, type: Integer, desc: 'The ID of the SSH key'
- end
- delete "keys/:key_id" do
- key = current_user.keys.find_by(id: params[:key_id])
- not_found!('Key') unless key
-
- present key.destroy, with: ::API::Entities::SSHKey
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/variables.rb b/lib/api/v3/variables.rb
deleted file mode 100644
index 83972b1e7ce..00000000000
--- a/lib/api/v3/variables.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-module API
- module V3
- class Variables < Grape::API
- include PaginationParams
-
- before { authenticate! }
- before { authorize! :admin_build, user_project }
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
-
- resource :projects, requirements: { id: %r{[^/]+} } do
- desc 'Delete an existing variable from a project' do
- success ::API::Entities::Variable
- end
- params do
- requires :key, type: String, desc: 'The key of the variable'
- end
- delete ':id/variables/:key' do
- variable = user_project.variables.find_by(key: params[:key])
- not_found!('Variable') unless variable
-
- present variable.destroy, with: ::API::Entities::Variable
- end
- end
- end
- end
-end
diff --git a/lib/bitbucket/representation/issue.rb b/lib/bitbucket/representation/issue.rb
index 054064395c3..44bcbc250b3 100644
--- a/lib/bitbucket/representation/issue.rb
+++ b/lib/bitbucket/representation/issue.rb
@@ -12,7 +12,7 @@ module Bitbucket
end
def author
- raw.fetch('reporter', {}).fetch('username', nil)
+ raw.dig('reporter', 'username')
end
def description
diff --git a/lib/feature.rb b/lib/feature.rb
index 6474de6e56d..314ae224d90 100644
--- a/lib/feature.rb
+++ b/lib/feature.rb
@@ -63,8 +63,15 @@ class Feature
end
def flipper
- Thread.current[:flipper] ||=
- Flipper.new(flipper_adapter).tap { |flip| flip.memoize = true }
+ if RequestStore.active?
+ RequestStore[:flipper] ||= build_flipper_instance
+ else
+ @flipper ||= build_flipper_instance
+ end
+ end
+
+ def build_flipper_instance
+ Flipper.new(flipper_adapter).tap { |flip| flip.memoize = true }
end
# This method is called from config/initializers/flipper.rb and can be used
diff --git a/lib/gitlab/auth.rb b/lib/gitlab/auth.rb
index 8e5a985edd7..0f7a7b0ce8d 100644
--- a/lib/gitlab/auth.rb
+++ b/lib/gitlab/auth.rb
@@ -14,6 +14,25 @@ module Gitlab
DEFAULT_SCOPES = [:api].freeze
class << self
+ def omniauth_customized_providers
+ @omniauth_customized_providers ||= %w[bitbucket jwt]
+ end
+
+ def omniauth_setup_providers(provider_names)
+ provider_names.each do |provider|
+ omniauth_setup_a_provider(provider)
+ end
+ end
+
+ def omniauth_setup_a_provider(provider)
+ case provider
+ when 'kerberos'
+ require 'omniauth-kerberos'
+ when *omniauth_customized_providers
+ require_dependency "omni_auth/strategies/#{provider}"
+ end
+ end
+
def find_for_git_client(login, password, project:, ip:)
raise "Must provide an IP for rate limiting" if ip.nil?
diff --git a/lib/gitlab/auth/request_authenticator.rb b/lib/gitlab/auth/request_authenticator.rb
index a0b5cd868c3..66de52506ce 100644
--- a/lib/gitlab/auth/request_authenticator.rb
+++ b/lib/gitlab/auth/request_authenticator.rb
@@ -16,7 +16,7 @@ module Gitlab
end
def find_sessionless_user
- find_user_from_access_token || find_user_from_rss_token
+ find_user_from_access_token || find_user_from_feed_token
rescue Gitlab::Auth::AuthenticationError
nil
end
diff --git a/lib/gitlab/auth/user_auth_finders.rb b/lib/gitlab/auth/user_auth_finders.rb
index 4dc23f977da..c7993665421 100644
--- a/lib/gitlab/auth/user_auth_finders.rb
+++ b/lib/gitlab/auth/user_auth_finders.rb
@@ -25,13 +25,15 @@ module Gitlab
current_request.env['warden']&.authenticate if verified_request?
end
- def find_user_from_rss_token
- return unless current_request.path.ends_with?('.atom') || current_request.format.atom?
+ def find_user_from_feed_token
+ return unless rss_request? || ics_request?
- token = current_request.params[:rss_token].presence
+ # NOTE: feed_token was renamed from rss_token but both needs to be supported because
+ # users might have already added the feed to their RSS reader before the rename
+ token = current_request.params[:feed_token].presence || current_request.params[:rss_token].presence
return unless token
- User.find_by_rss_token(token) || raise(UnauthorizedError)
+ User.find_by_feed_token(token) || raise(UnauthorizedError)
end
def find_user_from_access_token
@@ -104,6 +106,14 @@ module Gitlab
def current_request
@current_request ||= ensure_action_dispatch_request(request)
end
+
+ def rss_request?
+ current_request.path.ends_with?('.atom') || current_request.format.atom?
+ end
+
+ def ics_request?
+ current_request.path.ends_with?('.ics') || current_request.format.ics?
+ end
end
end
end
diff --git a/lib/gitlab/ci/pipeline/chain/populate.rb b/lib/gitlab/ci/pipeline/chain/populate.rb
index 69b8a8fc68f..f34c11ca3c2 100644
--- a/lib/gitlab/ci/pipeline/chain/populate.rb
+++ b/lib/gitlab/ci/pipeline/chain/populate.rb
@@ -8,6 +8,9 @@ module Gitlab
PopulateError = Class.new(StandardError)
def perform!
+ # Allocate next IID. This operation must be outside of transactions of pipeline creations.
+ pipeline.ensure_project_iid!
+
##
# Populate pipeline with block argument of CreatePipelineService#execute.
#
diff --git a/lib/gitlab/ci/trace/http_io.rb b/lib/gitlab/ci/trace/http_io.rb
index cff924e27ef..8788af57a67 100644
--- a/lib/gitlab/ci/trace/http_io.rb
+++ b/lib/gitlab/ci/trace/http_io.rb
@@ -148,7 +148,7 @@ module Gitlab
def get_chunk
unless in_range?
- response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
+ response = Net::HTTP.start(uri.hostname, uri.port, proxy_from_env: true, use_ssl: uri.scheme == 'https') do |http|
http.request(request)
end
diff --git a/lib/gitlab/contributions_calendar.rb b/lib/gitlab/contributions_calendar.rb
index d7369060cc5..4c28489f45a 100644
--- a/lib/gitlab/contributions_calendar.rb
+++ b/lib/gitlab/contributions_calendar.rb
@@ -85,7 +85,7 @@ module Gitlab
.select(t[:project_id], t[:target_type], t[:action], "date(created_at + #{date_interval}) AS date", 'count(id) as total_amount')
.group(t[:project_id], t[:target_type], t[:action], "date(created_at + #{date_interval})")
.where(conditions)
- .having(t[:project_id].in(Arel::Nodes::SqlLiteral.new(authed_projects.to_sql)))
+ .where("events.project_id in (#{authed_projects.to_sql})") # rubocop:disable GitlabSecurity/SqlInjection
end
end
end
diff --git a/lib/gitlab/cycle_analytics/summary/commit.rb b/lib/gitlab/cycle_analytics/summary/commit.rb
index bea78862757..0a88e052f60 100644
--- a/lib/gitlab/cycle_analytics/summary/commit.rb
+++ b/lib/gitlab/cycle_analytics/summary/commit.rb
@@ -7,7 +7,9 @@ module Gitlab
end
def value
- @value ||= count_commits
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ @value ||= count_commits
+ end
end
private
diff --git a/lib/gitlab/database/median.rb b/lib/gitlab/database/median.rb
index 74fed447289..3cac007a42c 100644
--- a/lib/gitlab/database/median.rb
+++ b/lib/gitlab/database/median.rb
@@ -143,8 +143,13 @@ module Gitlab
.order(arel_table[column_sym])
).as('row_id')
- count = arel_table.from(arel_table.alias)
- .project('COUNT(*)')
+ arel_from = if Gitlab.rails5?
+ arel_table.from.from(arel_table.alias)
+ else
+ arel_table.from(arel_table.alias)
+ end
+
+ count = arel_from.project('COUNT(*)')
.where(arel_table[partition_column].eq(arel_table.alias[partition_column]))
.as('ct')
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb
index 765fb0289a8..2820293ad5c 100644
--- a/lib/gitlab/diff/file.rb
+++ b/lib/gitlab/diff/file.rb
@@ -78,9 +78,12 @@ module Gitlab
# Returns the raw diff content up to the given line index
def diff_hunk(diff_line)
- # Adding 2 because of the @@ diff header and Enum#take should consider
- # an extra line, because we're passing an index.
- raw_diff.each_line.take(diff_line.index + 2).join
+ diff_line_index = diff_line.index
+ # @@ (match) header is not kept if it's found in the top of the file,
+ # therefore we should keep an extra line on this scenario.
+ diff_line_index += 1 unless diff_lines.first.match?
+
+ diff_lines.select { |line| line.index <= diff_line_index }.map(&:text).join("\n")
end
def old_sha
diff --git a/lib/gitlab/diff/line.rb b/lib/gitlab/diff/line.rb
index 0603141e441..a1e904cfef4 100644
--- a/lib/gitlab/diff/line.rb
+++ b/lib/gitlab/diff/line.rb
@@ -53,6 +53,10 @@ module Gitlab
%w[match new-nonewline old-nonewline].include?(type)
end
+ def match?
+ type == :match
+ end
+
def discussable?
!meta?
end
diff --git a/lib/gitlab/ee_compat_check.rb b/lib/gitlab/ee_compat_check.rb
index 8cf59fa8e28..8c72d00c1f3 100644
--- a/lib/gitlab/ee_compat_check.rb
+++ b/lib/gitlab/ee_compat_check.rb
@@ -138,8 +138,8 @@ module Gitlab
def ee_branch_presence_check!
ee_remotes.keys.each do |remote|
- [ee_branch_prefix, ee_branch_suffix].each do |branch|
- _, status = step("Fetching #{remote}/#{ee_branch_prefix}", %W[git fetch #{remote} #{branch}])
+ [ce_branch, ee_branch_prefix, ee_branch_suffix].each do |branch|
+ _, status = step("Fetching #{remote}/#{branch}", %W[git fetch #{remote} #{branch}])
if status.zero?
@ee_remote_with_branch = remote
diff --git a/lib/gitlab/file_finder.rb b/lib/gitlab/file_finder.rb
index 8c082c0c336..f42088f980e 100644
--- a/lib/gitlab/file_finder.rb
+++ b/lib/gitlab/file_finder.rb
@@ -32,17 +32,13 @@ module Gitlab
end
def find_by_filename(query, except: [])
- filenames = repository.search_files_by_name(query, ref).first(BATCH_SIZE)
- filenames.delete_if { |filename| except.include?(filename) } unless except.empty?
+ filenames = search_filenames(query, except)
- blob_refs = filenames.map { |filename| [ref, filename] }
- blobs = Gitlab::Git::Blob.batch(repository, blob_refs, blob_size_limit: 1024)
-
- blobs.map do |blob|
+ blobs(filenames).map do |blob|
Gitlab::SearchResults::FoundBlob.new(
id: blob.id,
filename: blob.path,
- basename: File.basename(blob.path),
+ basename: File.basename(blob.path, File.extname(blob.path)),
ref: ref,
startline: 1,
data: blob.data,
@@ -50,5 +46,21 @@ module Gitlab
)
end
end
+
+ def search_filenames(query, except)
+ filenames = repository.search_files_by_name(query, ref).first(BATCH_SIZE)
+
+ filenames.delete_if { |filename| except.include?(filename) } unless except.empty?
+
+ filenames
+ end
+
+ def blob_refs(filenames)
+ filenames.map { |filename| [ref, filename] }
+ end
+
+ def blobs(filenames)
+ Gitlab::Git::Blob.batch(repository, blob_refs(filenames), blob_size_limit: 1024)
+ end
end
end
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 1a21625a322..4cbf20bfe76 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -1185,15 +1185,17 @@ module Gitlab
end
def compare_source_branch(target_branch_name, source_repository, source_branch_name, straight:)
- with_repo_branch_commit(source_repository, source_branch_name) do |commit|
- break unless commit
-
- Gitlab::Git::Compare.new(
- self,
- target_branch_name,
- commit.sha,
- straight: straight
- )
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ with_repo_branch_commit(source_repository, source_branch_name) do |commit|
+ break unless commit
+
+ Gitlab::Git::Compare.new(
+ self,
+ target_branch_name,
+ commit.sha,
+ straight: straight
+ )
+ end
end
end
@@ -1455,7 +1457,7 @@ module Gitlab
gitaly_repository_client.cleanup if is_enabled && exists?
end
rescue Gitlab::Git::CommandError => e # Don't fail if we can't cleanup
- Rails.logger.error("Unable to clean repository on storage #{storage} with path #{path}: #{e.message}")
+ Rails.logger.error("Unable to clean repository on storage #{storage} with relative path #{relative_path}: #{e.message}")
Gitlab::Metrics.counter(
:failed_repository_cleanup_total,
'Number of failed repository cleanup events'
diff --git a/lib/gitlab/git/storage/checker.rb b/lib/gitlab/git/storage/checker.rb
index 2f611cef37b..391f0d70583 100644
--- a/lib/gitlab/git/storage/checker.rb
+++ b/lib/gitlab/git/storage/checker.rb
@@ -35,7 +35,7 @@ module Gitlab
def initialize(storage, logger = Rails.logger)
@storage = storage
config = Gitlab.config.repositories.storages[@storage]
- @storage_path = config.legacy_disk_path
+ @storage_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access { config.legacy_disk_path }
@logger = logger
@hostname = Gitlab::Environment.hostname
diff --git a/lib/gitlab/git/storage/circuit_breaker.rb b/lib/gitlab/git/storage/circuit_breaker.rb
index e35054466ff..62427ac9cc4 100644
--- a/lib/gitlab/git/storage/circuit_breaker.rb
+++ b/lib/gitlab/git/storage/circuit_breaker.rb
@@ -22,13 +22,14 @@ module Gitlab
def self.build(storage, hostname = Gitlab::Environment.hostname)
config = Gitlab.config.repositories.storages[storage]
-
- if !config.present?
- NullCircuitBreaker.new(storage, hostname, error: Misconfiguration.new("Storage '#{storage}' is not configured"))
- elsif !config.legacy_disk_path.present?
- NullCircuitBreaker.new(storage, hostname, error: Misconfiguration.new("Path for storage '#{storage}' is not configured"))
- else
- new(storage, hostname)
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ if !config.present?
+ NullCircuitBreaker.new(storage, hostname, error: Misconfiguration.new("Storage '#{storage}' is not configured"))
+ elsif !config.legacy_disk_path.present?
+ NullCircuitBreaker.new(storage, hostname, error: Misconfiguration.new("Path for storage '#{storage}' is not configured"))
+ else
+ new(storage, hostname)
+ end
end
end
diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb
index 0abae70c443..550294916a4 100644
--- a/lib/gitlab/gitaly_client.rb
+++ b/lib/gitlab/gitaly_client.rb
@@ -33,6 +33,11 @@ module Gitlab
MAXIMUM_GITALY_CALLS = 35
CLIENT_NAME = (Sidekiq.server? ? 'gitlab-sidekiq' : 'gitlab-web').freeze
+ # We have a mechanism to let GitLab automatically opt in to all Gitaly
+ # features. We want to be able to exclude some features from automatic
+ # opt-in. That is what EXPLICIT_OPT_IN_REQUIRED is for.
+ EXPLICIT_OPT_IN_REQUIRED = [Gitlab::GitalyClient::StorageSettings::DISK_ACCESS_DENIED_FLAG].freeze
+
MUTEX = Mutex.new
class << self
@@ -234,7 +239,7 @@ module Gitlab
when MigrationStatus::OPT_OUT
true
when MigrationStatus::OPT_IN
- opt_into_all_features?
+ opt_into_all_features? && !EXPLICIT_OPT_IN_REQUIRED.include?(feature_name)
else
false
end
diff --git a/lib/gitlab/gitaly_client/commit_service.rb b/lib/gitlab/gitaly_client/commit_service.rb
index 1f5f88bf792..a4cc64de80d 100644
--- a/lib/gitlab/gitaly_client/commit_service.rb
+++ b/lib/gitlab/gitaly_client/commit_service.rb
@@ -78,7 +78,7 @@ module Gitlab
def tree_entry(ref, path, limit = nil)
request = Gitaly::TreeEntryRequest.new(
repository: @gitaly_repo,
- revision: ref,
+ revision: encode_binary(ref),
path: encode_binary(path),
limit: limit.to_i
)
diff --git a/lib/gitlab/gitaly_client/storage_settings.rb b/lib/gitlab/gitaly_client/storage_settings.rb
index 9a576e463e3..02fcb413abd 100644
--- a/lib/gitlab/gitaly_client/storage_settings.rb
+++ b/lib/gitlab/gitaly_client/storage_settings.rb
@@ -4,6 +4,8 @@ module Gitlab
# where production code (app, config, db, lib) touches Git repositories
# directly.
class StorageSettings
+ extend Gitlab::TemporarilyAllow
+
DirectPathAccessError = Class.new(StandardError)
InvalidConfigurationError = Class.new(StandardError)
@@ -17,7 +19,21 @@ module Gitlab
# This class will give easily recognizable NoMethodErrors
Deprecated = Class.new
- attr_reader :legacy_disk_path
+ MUTEX = Mutex.new
+
+ DISK_ACCESS_DENIED_FLAG = :deny_disk_access
+ ALLOW_KEY = :allow_disk_access
+
+ # If your code needs this method then your code needs to be fixed.
+ def self.allow_disk_access
+ temporarily_allow(ALLOW_KEY) { yield }
+ end
+
+ def self.disk_access_denied?
+ !temporarily_allowed?(ALLOW_KEY) && GitalyClient.feature_enabled?(DISK_ACCESS_DENIED_FLAG)
+ rescue
+ false # Err on the side of caution, don't break gitlab for people
+ end
def initialize(storage)
raise InvalidConfigurationError, "expected a Hash, got a #{storage.class.name}" unless storage.is_a?(Hash)
@@ -34,6 +50,14 @@ module Gitlab
@hash.fetch(:gitaly_address)
end
+ def legacy_disk_path
+ if self.class.disk_access_denied?
+ raise DirectPathAccessError, "git disk access denied via the gitaly_#{DISK_ACCESS_DENIED_FLAG} feature"
+ end
+
+ @legacy_disk_path
+ end
+
private
def method_missing(m, *args, &block)
diff --git a/lib/gitlab/gitlab_import/client.rb b/lib/gitlab/gitlab_import/client.rb
index 5482504e72e..22719e9a003 100644
--- a/lib/gitlab/gitlab_import/client.rb
+++ b/lib/gitlab/gitlab_import/client.rb
@@ -29,28 +29,28 @@ module Gitlab
end
def user
- api.get("/api/v3/user").parsed
+ api.get("/api/v4/user").parsed
end
def issues(project_identifier)
lazy_page_iterator(PER_PAGE) do |page|
- api.get("/api/v3/projects/#{project_identifier}/issues?per_page=#{PER_PAGE}&page=#{page}").parsed
+ api.get("/api/v4/projects/#{project_identifier}/issues?per_page=#{PER_PAGE}&page=#{page}").parsed
end
end
def issue_comments(project_identifier, issue_id)
lazy_page_iterator(PER_PAGE) do |page|
- api.get("/api/v3/projects/#{project_identifier}/issues/#{issue_id}/notes?per_page=#{PER_PAGE}&page=#{page}").parsed
+ api.get("/api/v4/projects/#{project_identifier}/issues/#{issue_id}/notes?per_page=#{PER_PAGE}&page=#{page}").parsed
end
end
def project(id)
- api.get("/api/v3/projects/#{id}").parsed
+ api.get("/api/v4/projects/#{id}").parsed
end
def projects
lazy_page_iterator(PER_PAGE) do |page|
- api.get("/api/v3/projects?per_page=#{PER_PAGE}&page=#{page}").parsed
+ api.get("/api/v4/projects?per_page=#{PER_PAGE}&page=#{page}").parsed
end
end
diff --git a/lib/gitlab/gitlab_import/importer.rb b/lib/gitlab/gitlab_import/importer.rb
index e44d7934fda..195672f5a12 100644
--- a/lib/gitlab/gitlab_import/importer.rb
+++ b/lib/gitlab/gitlab_import/importer.rb
@@ -25,7 +25,7 @@ module Gitlab
body = @formatter.author_line(issue["author"]["name"])
body += issue["description"]
- comments = client.issue_comments(project_identifier, issue["id"])
+ comments = client.issue_comments(project_identifier, issue["iid"])
if comments.any?
body += @formatter.comments_header
diff --git a/lib/gitlab/gitlab_import/project_creator.rb b/lib/gitlab/gitlab_import/project_creator.rb
index 3d0418261bb..430b8c10058 100644
--- a/lib/gitlab/gitlab_import/project_creator.rb
+++ b/lib/gitlab/gitlab_import/project_creator.rb
@@ -17,7 +17,7 @@ module Gitlab
path: repo["path"],
description: repo["description"],
namespace_id: namespace.id,
- visibility_level: repo["visibility_level"],
+ visibility_level: Gitlab::VisibilityLevel.level_value(repo["visibility"]),
import_type: "gitlab",
import_source: repo["path_with_namespace"],
import_url: repo["http_url_to_repo"].sub("://", "://oauth2:#{@session_data[:gitlab_access_token]}@")
diff --git a/lib/gitlab/gon_helper.rb b/lib/gitlab/gon_helper.rb
index 0d31934347f..deaa14c8434 100644
--- a/lib/gitlab/gon_helper.rb
+++ b/lib/gitlab/gon_helper.rb
@@ -11,7 +11,7 @@ module Gitlab
gon.asset_host = ActionController::Base.asset_host
gon.webpack_public_path = webpack_public_path
gon.relative_url_root = Gitlab.config.gitlab.relative_url_root
- gon.shortcuts_path = help_page_path('shortcuts')
+ gon.shortcuts_path = Gitlab::Routing.url_helpers.help_page_path('shortcuts')
gon.user_color_scheme = Gitlab::ColorSchemes.for_user(current_user).css_class
gon.sentry_dsn = Gitlab::CurrentSettings.clientside_sentry_dsn if Gitlab::CurrentSettings.clientside_sentry_enabled
gon.gitlab_url = Gitlab.config.gitlab.url
diff --git a/lib/gitlab/hashed_storage/rake_helper.rb b/lib/gitlab/hashed_storage/rake_helper.rb
new file mode 100644
index 00000000000..8aba42ccfce
--- /dev/null
+++ b/lib/gitlab/hashed_storage/rake_helper.rb
@@ -0,0 +1,71 @@
+module Gitlab
+ module HashedStorage
+ module RakeHelper
+ def self.batch_size
+ ENV.fetch('BATCH', 200).to_i
+ end
+
+ def self.listing_limit
+ ENV.fetch('LIMIT', 500).to_i
+ end
+
+ def self.project_id_batches(&block)
+ Project.with_unmigrated_storage.in_batches(of: batch_size, start: ENV['ID_FROM'], finish: ENV['ID_TO']) do |relation| # rubocop: disable Cop/InBatches
+ ids = relation.pluck(:id)
+
+ yield ids.min, ids.max
+ end
+ end
+
+ def self.legacy_attachments_relation
+ Upload.joins(<<~SQL).where('projects.storage_version < :version OR projects.storage_version IS NULL', version: Project::HASHED_STORAGE_FEATURES[:attachments])
+ JOIN projects
+ ON (uploads.model_type='Project' AND uploads.model_id=projects.id)
+ SQL
+ end
+
+ def self.hashed_attachments_relation
+ Upload.joins(<<~SQL).where('projects.storage_version >= :version', version: Project::HASHED_STORAGE_FEATURES[:attachments])
+ JOIN projects
+ ON (uploads.model_type='Project' AND uploads.model_id=projects.id)
+ SQL
+ end
+
+ def self.relation_summary(relation_name, relation)
+ relation_count = relation.count
+ $stdout.puts "* Found #{relation_count} #{relation_name}".color(:green)
+
+ relation_count
+ end
+
+ def self.projects_list(relation_name, relation)
+ listing(relation_name, relation.with_route) do |project|
+ $stdout.puts " - #{project.full_path} (id: #{project.id})".color(:red)
+ end
+ end
+
+ def self.attachments_list(relation_name, relation)
+ listing(relation_name, relation) do |upload|
+ $stdout.puts " - #{upload.path} (id: #{upload.id})".color(:red)
+ end
+ end
+
+ def self.listing(relation_name, relation)
+ relation_count = relation_summary(relation_name, relation)
+ return unless relation_count > 0
+
+ limit = listing_limit
+
+ if relation_count > limit
+ $stdout.puts " ! Displaying first #{limit} #{relation_name}..."
+ end
+
+ relation.find_each(batch_size: batch_size).with_index do |element, index|
+ yield element
+
+ break if index + 1 >= limit
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/health_checks/fs_shards_check.rb b/lib/gitlab/health_checks/fs_shards_check.rb
index 6e554383270..fcbf266b80b 100644
--- a/lib/gitlab/health_checks/fs_shards_check.rb
+++ b/lib/gitlab/health_checks/fs_shards_check.rb
@@ -77,7 +77,9 @@ module Gitlab
end
def storage_path(storage_name)
- storages_paths[storage_name]&.legacy_disk_path
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ storages_paths[storage_name]&.legacy_disk_path
+ end
end
# All below test methods use shell commands to perform actions on storage volumes.
diff --git a/lib/gitlab/import_export/attribute_cleaner.rb b/lib/gitlab/import_export/attribute_cleaner.rb
index 34169319b26..7c9fc5c15bb 100644
--- a/lib/gitlab/import_export/attribute_cleaner.rb
+++ b/lib/gitlab/import_export/attribute_cleaner.rb
@@ -7,14 +7,15 @@ module Gitlab
new(*args).clean
end
- def initialize(relation_hash:, relation_class:)
+ def initialize(relation_hash:, relation_class:, excluded_keys: [])
@relation_hash = relation_hash
@relation_class = relation_class
+ @excluded_keys = excluded_keys
end
def clean
@relation_hash.reject do |key, _value|
- prohibited_key?(key) || !@relation_class.attribute_method?(key)
+ prohibited_key?(key) || !@relation_class.attribute_method?(key) || excluded_key?(key)
end.except('id')
end
@@ -23,6 +24,12 @@ module Gitlab
def prohibited_key?(key)
key.end_with?('_id') && !ALLOWED_REFERENCES.include?(key)
end
+
+ def excluded_key?(key)
+ return false if @excluded_keys.empty?
+
+ @excluded_keys.include?(key)
+ end
end
end
end
diff --git a/lib/gitlab/import_export/attributes_finder.rb b/lib/gitlab/import_export/attributes_finder.rb
index 56042ddecbf..0c8fda07294 100644
--- a/lib/gitlab/import_export/attributes_finder.rb
+++ b/lib/gitlab/import_export/attributes_finder.rb
@@ -32,6 +32,10 @@ module Gitlab
@methods[key].nil? ? {} : { methods: @methods[key] }
end
+ def find_excluded_keys(klass_name)
+ @excluded_attributes[klass_name.to_sym]&.map(&:to_s) || []
+ end
+
private
def find_attributes_only(value)
diff --git a/lib/gitlab/import_export/import_export.yml b/lib/gitlab/import_export/import_export.yml
index 21ac7f7e0b6..da3667faf7a 100644
--- a/lib/gitlab/import_export/import_export.yml
+++ b/lib/gitlab/import_export/import_export.yml
@@ -28,6 +28,7 @@ project_tree:
- project_members:
- :user
- merge_requests:
+ - :metrics
- notes:
- :author
- events:
@@ -98,8 +99,6 @@ excluded_attributes:
- :import_jid
- :created_at
- :updated_at
- - :import_jid
- - :import_jid
- :id
- :star_count
- :last_activity_at
diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb
index d5590dde40f..4eb67fbe11e 100644
--- a/lib/gitlab/import_export/project_tree_restorer.rb
+++ b/lib/gitlab/import_export/project_tree_restorer.rb
@@ -88,16 +88,18 @@ module Gitlab
end
def project_params
- @project_params ||= json_params.merge(override_params)
+ @project_params ||= begin
+ attrs = json_params.merge(override_params)
+
+ # Cleaning all imported and overridden params
+ Gitlab::ImportExport::AttributeCleaner.clean(relation_hash: attrs,
+ relation_class: Project,
+ excluded_keys: excluded_keys_for_relation(:project))
+ end
end
def override_params
- return {} unless params = @project.import_data&.data&.fetch('override_params', nil)
-
- @override_params ||= params.select do |key, _value|
- Project.column_names.include?(key.to_s) &&
- !reader.project_tree[:except].include?(key.to_sym)
- end
+ @override_params ||= @project.import_data&.data&.fetch('override_params', nil) || {}
end
def json_params
@@ -171,7 +173,8 @@ module Gitlab
relation_hash: parsed_relation_hash(relation_hash, relation.to_sym),
members_mapper: members_mapper,
user: @user,
- project: @restored_project)
+ project: @restored_project,
+ excluded_keys: excluded_keys_for_relation(relation))
end.compact
relation_hash_list.is_a?(Array) ? relation_array : relation_array.first
@@ -192,6 +195,10 @@ module Gitlab
def reader
@reader ||= Gitlab::ImportExport::Reader.new(shared: @shared)
end
+
+ def excluded_keys_for_relation(relation)
+ @reader.attributes_finder.find_excluded_keys(relation)
+ end
end
end
end
diff --git a/lib/gitlab/import_export/reader.rb b/lib/gitlab/import_export/reader.rb
index eb7f5120592..e621c40fc7a 100644
--- a/lib/gitlab/import_export/reader.rb
+++ b/lib/gitlab/import_export/reader.rb
@@ -1,7 +1,7 @@
module Gitlab
module ImportExport
class Reader
- attr_reader :tree
+ attr_reader :tree, :attributes_finder
def initialize(shared:)
@shared = shared
diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb
index 4a41a69840b..c5cf290f191 100644
--- a/lib/gitlab/import_export/relation_factory.rb
+++ b/lib/gitlab/import_export/relation_factory.rb
@@ -18,9 +18,10 @@ module Gitlab
label: :project_label,
custom_attributes: 'ProjectCustomAttribute',
project_badges: 'Badge',
+ metrics: 'MergeRequest::Metrics',
ci_cd_settings: 'ProjectCiCdSetting' }.freeze
- USER_REFERENCES = %w[author_id assignee_id updated_by_id user_id created_by_id last_edited_by_id merge_user_id resolved_by_id closed_by_id].freeze
+ USER_REFERENCES = %w[author_id assignee_id updated_by_id merged_by_id latest_closed_by_id user_id created_by_id last_edited_by_id merge_user_id resolved_by_id closed_by_id].freeze
PROJECT_REFERENCES = %w[project_id source_project_id target_project_id].freeze
@@ -36,13 +37,30 @@ module Gitlab
new(*args).create
end
- def initialize(relation_sym:, relation_hash:, members_mapper:, user:, project:)
+ def self.relation_class(relation_name)
+ # There are scenarios where the model is pluralized (e.g.
+ # MergeRequest::Metrics), and we don't want to force it to singular
+ # with #classify.
+ relation_name.to_s.classify.constantize
+ rescue NameError
+ relation_name.to_s.constantize
+ end
+
+ def initialize(relation_sym:, relation_hash:, members_mapper:, user:, project:, excluded_keys: [])
@relation_name = OVERRIDES[relation_sym] || relation_sym
@relation_hash = relation_hash.except('noteable_id')
@members_mapper = members_mapper
@user = user
@project = project
@imported_object_retries = 0
+
+ # Remove excluded keys from relation_hash
+ # We don't do this in the parsed_relation_hash because of the 'transformed attributes'
+ # For example, MergeRequestDiffFiles exports its diff attribute as utf8_diff. Then,
+ # in the create method that attribute is renamed to diff. And because diff is an excluded key,
+ # if we clean the excluded keys in the parsed_relation_hash, it will be removed
+ # from the object attributes and the export will fail.
+ @relation_hash.except!(*excluded_keys)
end
# Creates an object from an actual model with name "relation_sym" with params from
@@ -187,7 +205,7 @@ module Gitlab
end
def relation_class
- @relation_class ||= @relation_name.to_s.classify.constantize
+ @relation_class ||= self.class.relation_class(@relation_name)
end
def imported_object
diff --git a/lib/gitlab/import_formatter.rb b/lib/gitlab/import_formatter.rb
index 3e54456e936..4e611e7f16c 100644
--- a/lib/gitlab/import_formatter.rb
+++ b/lib/gitlab/import_formatter.rb
@@ -9,6 +9,7 @@ module Gitlab
end
def author_line(author)
+ author ||= "Anonymous"
"*Created by: #{author}*\n\n"
end
end
diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb
index 2e9b6e302f5..38bdc61d8ab 100644
--- a/lib/gitlab/project_search_results.rb
+++ b/lib/gitlab/project_search_results.rb
@@ -106,7 +106,8 @@ module Gitlab
project_wiki = ProjectWiki.new(project)
unless project_wiki.empty?
- project_wiki.search_files(query)
+ ref = repository_ref || project.wiki.default_branch
+ Gitlab::WikiFileFinder.new(project, ref).find(query)
else
[]
end
diff --git a/lib/gitlab/query_limiting/active_support_subscriber.rb b/lib/gitlab/query_limiting/active_support_subscriber.rb
index 4c83581c4b1..3c4ff5d1928 100644
--- a/lib/gitlab/query_limiting/active_support_subscriber.rb
+++ b/lib/gitlab/query_limiting/active_support_subscriber.rb
@@ -4,7 +4,7 @@ module Gitlab
attach_to :active_record
def sql(event)
- unless event.payload[:name] == 'CACHE'
+ unless event.payload.fetch(:cached, event.payload[:name] == 'CACHE')
Transaction.current&.increment
end
end
diff --git a/lib/gitlab/slash_commands/command.rb b/lib/gitlab/slash_commands/command.rb
index bb778f37096..c82320a6036 100644
--- a/lib/gitlab/slash_commands/command.rb
+++ b/lib/gitlab/slash_commands/command.rb
@@ -1,13 +1,15 @@
module Gitlab
module SlashCommands
class Command < BaseCommand
- COMMANDS = [
- Gitlab::SlashCommands::IssueShow,
- Gitlab::SlashCommands::IssueNew,
- Gitlab::SlashCommands::IssueSearch,
- Gitlab::SlashCommands::IssueMove,
- Gitlab::SlashCommands::Deploy
- ].freeze
+ def self.commands
+ [
+ Gitlab::SlashCommands::IssueShow,
+ Gitlab::SlashCommands::IssueNew,
+ Gitlab::SlashCommands::IssueSearch,
+ Gitlab::SlashCommands::IssueMove,
+ Gitlab::SlashCommands::Deploy
+ ]
+ end
def execute
command, match = match_command
@@ -37,7 +39,7 @@ module Gitlab
private
def available_commands
- COMMANDS.select do |klass|
+ self.class.commands.keep_if do |klass|
klass.available?(project)
end
end
diff --git a/lib/gitlab/temporarily_allow.rb b/lib/gitlab/temporarily_allow.rb
new file mode 100644
index 00000000000..880e55f71df
--- /dev/null
+++ b/lib/gitlab/temporarily_allow.rb
@@ -0,0 +1,42 @@
+module Gitlab
+ module TemporarilyAllow
+ TEMPORARILY_ALLOW_MUTEX = Mutex.new
+
+ def temporarily_allow(key)
+ temporarily_allow_add(key, 1)
+ yield
+ ensure
+ temporarily_allow_add(key, -1)
+ end
+
+ def temporarily_allowed?(key)
+ if RequestStore.active?
+ temporarily_allow_request_store[key] > 0
+ else
+ TEMPORARILY_ALLOW_MUTEX.synchronize do
+ temporarily_allow_ivar[key] > 0
+ end
+ end
+ end
+
+ private
+
+ def temporarily_allow_ivar
+ @temporarily_allow ||= Hash.new(0)
+ end
+
+ def temporarily_allow_request_store
+ RequestStore[:temporarily_allow] ||= Hash.new(0)
+ end
+
+ def temporarily_allow_add(key, value)
+ if RequestStore.active?
+ temporarily_allow_request_store[key] += value
+ else
+ TEMPORARILY_ALLOW_MUTEX.synchronize do
+ temporarily_allow_ivar[key] += value
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/url_blocker.rb b/lib/gitlab/url_blocker.rb
index db97f65bd54..20be193ea0c 100644
--- a/lib/gitlab/url_blocker.rb
+++ b/lib/gitlab/url_blocker.rb
@@ -5,7 +5,7 @@ module Gitlab
BlockedUrlError = Class.new(StandardError)
class << self
- def validate!(url, allow_localhost: false, allow_local_network: true, valid_ports: [])
+ def validate!(url, allow_localhost: false, allow_local_network: true, ports: [], protocols: [])
return true if url.nil?
begin
@@ -18,7 +18,8 @@ module Gitlab
return true if internal?(uri)
port = uri.port || uri.default_port
- validate_port!(port, valid_ports) if valid_ports.any?
+ validate_protocol!(uri.scheme, protocols)
+ validate_port!(port, ports) if ports.any?
validate_user!(uri.user)
validate_hostname!(uri.hostname)
@@ -44,13 +45,19 @@ module Gitlab
private
- def validate_port!(port, valid_ports)
+ def validate_port!(port, ports)
return if port.blank?
# Only ports under 1024 are restricted
return if port >= 1024
- return if valid_ports.include?(port)
+ return if ports.include?(port)
- raise BlockedUrlError, "Only allowed ports are #{valid_ports.join(', ')}, and any over 1024"
+ raise BlockedUrlError, "Only allowed ports are #{ports.join(', ')}, and any over 1024"
+ end
+
+ def validate_protocol!(protocol, protocols)
+ if protocol.blank? || (protocols.any? && !protocols.include?(protocol))
+ raise BlockedUrlError, "Only allowed protocols are #{protocols.join(', ')}"
+ end
end
def validate_user!(value)
diff --git a/lib/gitlab/webpack/dev_server_middleware.rb b/lib/gitlab/webpack/dev_server_middleware.rb
index b9a75eaac63..529f7d6a8d6 100644
--- a/lib/gitlab/webpack/dev_server_middleware.rb
+++ b/lib/gitlab/webpack/dev_server_middleware.rb
@@ -15,6 +15,11 @@ module Gitlab
def perform_request(env)
if @proxy_path && env['PATH_INFO'].start_with?("/#{@proxy_path}")
+ if relative_url_root = Rails.application.config.relative_url_root
+ env['SCRIPT_NAME'] = ""
+ env['REQUEST_PATH'].sub!(/\A#{Regexp.escape(relative_url_root)}/, '')
+ end
+
super(env)
else
@app.call(env)
diff --git a/lib/gitlab/wiki_file_finder.rb b/lib/gitlab/wiki_file_finder.rb
new file mode 100644
index 00000000000..f97278f05cd
--- /dev/null
+++ b/lib/gitlab/wiki_file_finder.rb
@@ -0,0 +1,23 @@
+module Gitlab
+ class WikiFileFinder < FileFinder
+ attr_reader :repository
+
+ def initialize(project, ref)
+ @project = project
+ @ref = ref
+ @repository = project.wiki.repository
+ end
+
+ private
+
+ def search_filenames(query, except)
+ safe_query = Regexp.escape(query.tr(' ', '-'))
+ safe_query = Regexp.new(safe_query, Regexp::IGNORECASE)
+ filenames = repository.ls_files(ref)
+
+ filenames.delete_if { |filename| except.include?(filename) } unless except.empty?
+
+ filenames.grep(safe_query).first(BATCH_SIZE)
+ end
+ end
+end
diff --git a/lib/mattermost/command.rb b/lib/mattermost/command.rb
index 33e450d7f0a..704813dfdf0 100644
--- a/lib/mattermost/command.rb
+++ b/lib/mattermost/command.rb
@@ -1,7 +1,7 @@
module Mattermost
class Command < Client
def create(params)
- response = session_post("/api/v3/teams/#{params[:team_id]}/commands/create",
+ response = session_post('/api/v4/commands',
body: params.to_json)
response['token']
diff --git a/lib/mattermost/session.rb b/lib/mattermost/session.rb
index 85f78e44f32..2aa7a2f64d8 100644
--- a/lib/mattermost/session.rb
+++ b/lib/mattermost/session.rb
@@ -112,7 +112,7 @@ module Mattermost
end
def destroy
- post('/api/v3/users/logout')
+ post('/api/v4/users/logout')
end
def oauth_uri
@@ -120,7 +120,7 @@ module Mattermost
@oauth_uri = nil
- response = get("/api/v3/oauth/gitlab/login", follow_redirects: false)
+ response = get('/oauth/gitlab/login', follow_redirects: false, format: 'text/html')
return unless (300...400) === response.code
redirect_uri = response.headers['location']
diff --git a/lib/mattermost/team.rb b/lib/mattermost/team.rb
index 75513a9ba04..95c2f6f9d6b 100644
--- a/lib/mattermost/team.rb
+++ b/lib/mattermost/team.rb
@@ -1,14 +1,14 @@
module Mattermost
class Team < Client
- # Returns **all** teams for an admin
+ # Returns all teams that the current user is a member of
def all
- session_get('/api/v3/teams/all').values
+ session_get("/api/v4/users/me/teams")
end
# Creates a team on the linked Mattermost instance, the team admin will be the
# `current_user` passed to the Mattermost::Client instance
def create(name:, display_name:, type:)
- session_post('/api/v3/teams/create', body: {
+ session_post('/api/v4/teams', body: {
name: name,
display_name: display_name,
type: type
diff --git a/lib/omni_auth/strategies/jwt.rb b/lib/omni_auth/strategies/jwt.rb
index 2349b2a28aa..ebdb5c7faf0 100644
--- a/lib/omni_auth/strategies/jwt.rb
+++ b/lib/omni_auth/strategies/jwt.rb
@@ -3,7 +3,7 @@ require 'jwt'
module OmniAuth
module Strategies
- class JWT
+ class Jwt
ClaimInvalid = Class.new(StandardError)
include OmniAuth::Strategy
@@ -56,7 +56,5 @@ module OmniAuth
fail! :claim_invalid, e
end
end
-
- class Jwt < JWT; end
end
end
diff --git a/lib/peek/rblineprof/custom_controller_helpers.rb b/lib/peek/rblineprof/custom_controller_helpers.rb
index 7cfe76b7b71..da24a36603e 100644
--- a/lib/peek/rblineprof/custom_controller_helpers.rb
+++ b/lib/peek/rblineprof/custom_controller_helpers.rb
@@ -41,10 +41,10 @@ module Peek
]
end.sort_by{ |a,b,c,d,e,f| -f }
- output = "<div class='modal-dialog modal-full'><div class='modal-content'>"
+ output = "<div class='modal-dialog modal-lg'><div class='modal-content'>"
output << "<div class='modal-header'>"
- output << "<button class='close btn btn-link btn-sm' type='button' data-dismiss='modal'>X</button>"
output << "<h4>Line profiling: #{human_description(params[:lineprofiler])}</h4>"
+ output << "<button class='close' type='button' data-dismiss='modal' aria-label='close'><span aria-hidden='true'>&times;</span></button>"
output << "</div>"
output << "<div class='modal-body'>"
diff --git a/lib/rspec_flaky/listener.rb b/lib/rspec_flaky/listener.rb
index 5b5e4f7c7de..9cd0c38cb55 100644
--- a/lib/rspec_flaky/listener.rb
+++ b/lib/rspec_flaky/listener.rb
@@ -1,10 +1,10 @@
require 'json'
-require_relative 'config'
-require_relative 'example'
-require_relative 'flaky_example'
-require_relative 'flaky_examples_collection'
-require_relative 'report'
+require_dependency 'rspec_flaky/config'
+require_dependency 'rspec_flaky/example'
+require_dependency 'rspec_flaky/flaky_example'
+require_dependency 'rspec_flaky/flaky_examples_collection'
+require_dependency 'rspec_flaky/report'
module RspecFlaky
class Listener
diff --git a/lib/rspec_flaky/report.rb b/lib/rspec_flaky/report.rb
index a8730d3b7c7..1c362fdd20d 100644
--- a/lib/rspec_flaky/report.rb
+++ b/lib/rspec_flaky/report.rb
@@ -1,8 +1,8 @@
require 'json'
require 'time'
-require_relative 'config'
-require_relative 'flaky_examples_collection'
+require_dependency 'rspec_flaky/config'
+require_dependency 'rspec_flaky/flaky_examples_collection'
module RspecFlaky
# This class is responsible for loading/saving JSON reports, and pruning
diff --git a/lib/support/nginx/gitlab b/lib/support/nginx/gitlab
index 0e27a28ea6e..72eb8adcce2 100644
--- a/lib/support/nginx/gitlab
+++ b/lib/support/nginx/gitlab
@@ -31,27 +31,27 @@ map $http_upgrade $connection_upgrade_gitlab {
log_format gitlab_access $remote_addr - $remote_user [$time_local] "$request_method $gitlab_filtered_request_uri $server_protocol" $status $body_bytes_sent "$gitlab_filtered_http_referer" "$http_user_agent";
## Remove private_token from the request URI
-# In: /foo?private_token=unfiltered&authenticity_token=unfiltered&rss_token=unfiltered&...
-# Out: /foo?private_token=[FILTERED]&authenticity_token=unfiltered&rss_token=unfiltered&...
+# In: /foo?private_token=unfiltered&authenticity_token=unfiltered&feed_token=unfiltered&...
+# Out: /foo?private_token=[FILTERED]&authenticity_token=unfiltered&feed_token=unfiltered&...
map $request_uri $gitlab_temp_request_uri_1 {
default $request_uri;
~(?i)^(?<start>.*)(?<temp>[\?&]private[\-_]token)=[^&]*(?<rest>.*)$ "$start$temp=[FILTERED]$rest";
}
## Remove authenticity_token from the request URI
-# In: /foo?private_token=[FILTERED]&authenticity_token=unfiltered&rss_token=unfiltered&...
-# Out: /foo?private_token=[FILTERED]&authenticity_token=[FILTERED]&rss_token=unfiltered&...
+# In: /foo?private_token=[FILTERED]&authenticity_token=unfiltered&feed_token=unfiltered&...
+# Out: /foo?private_token=[FILTERED]&authenticity_token=[FILTERED]&feed_token=unfiltered&...
map $gitlab_temp_request_uri_1 $gitlab_temp_request_uri_2 {
default $gitlab_temp_request_uri_1;
~(?i)^(?<start>.*)(?<temp>[\?&]authenticity[\-_]token)=[^&]*(?<rest>.*)$ "$start$temp=[FILTERED]$rest";
}
-## Remove rss_token from the request URI
-# In: /foo?private_token=[FILTERED]&authenticity_token=[FILTERED]&rss_token=unfiltered&...
-# Out: /foo?private_token=[FILTERED]&authenticity_token=[FILTERED]&rss_token=[FILTERED]&...
+## Remove feed_token from the request URI
+# In: /foo?private_token=[FILTERED]&authenticity_token=[FILTERED]&feed_token=unfiltered&...
+# Out: /foo?private_token=[FILTERED]&authenticity_token=[FILTERED]&feed_token=[FILTERED]&...
map $gitlab_temp_request_uri_2 $gitlab_filtered_request_uri {
default $gitlab_temp_request_uri_2;
- ~(?i)^(?<start>.*)(?<temp>[\?&]rss[\-_]token)=[^&]*(?<rest>.*)$ "$start$temp=[FILTERED]$rest";
+ ~(?i)^(?<start>.*)(?<temp>[\?&]feed[\-_]token)=[^&]*(?<rest>.*)$ "$start$temp=[FILTERED]$rest";
}
## A version of the referer without the query string
diff --git a/lib/support/nginx/gitlab-ssl b/lib/support/nginx/gitlab-ssl
index 8218d68f9ba..2e3799d5e1b 100644
--- a/lib/support/nginx/gitlab-ssl
+++ b/lib/support/nginx/gitlab-ssl
@@ -36,27 +36,27 @@ map $http_upgrade $connection_upgrade_gitlab_ssl {
log_format gitlab_ssl_access $remote_addr - $remote_user [$time_local] "$request_method $gitlab_ssl_filtered_request_uri $server_protocol" $status $body_bytes_sent "$gitlab_ssl_filtered_http_referer" "$http_user_agent";
## Remove private_token from the request URI
-# In: /foo?private_token=unfiltered&authenticity_token=unfiltered&rss_token=unfiltered&...
-# Out: /foo?private_token=[FILTERED]&authenticity_token=unfiltered&rss_token=unfiltered&...
+# In: /foo?private_token=unfiltered&authenticity_token=unfiltered&feed_token=unfiltered&...
+# Out: /foo?private_token=[FILTERED]&authenticity_token=unfiltered&feed_token=unfiltered&...
map $request_uri $gitlab_ssl_temp_request_uri_1 {
default $request_uri;
~(?i)^(?<start>.*)(?<temp>[\?&]private[\-_]token)=[^&]*(?<rest>.*)$ "$start$temp=[FILTERED]$rest";
}
## Remove authenticity_token from the request URI
-# In: /foo?private_token=[FILTERED]&authenticity_token=unfiltered&rss_token=unfiltered&...
-# Out: /foo?private_token=[FILTERED]&authenticity_token=[FILTERED]&rss_token=unfiltered&...
+# In: /foo?private_token=[FILTERED]&authenticity_token=unfiltered&feed_token=unfiltered&...
+# Out: /foo?private_token=[FILTERED]&authenticity_token=[FILTERED]&feed_token=unfiltered&...
map $gitlab_ssl_temp_request_uri_1 $gitlab_ssl_temp_request_uri_2 {
default $gitlab_ssl_temp_request_uri_1;
~(?i)^(?<start>.*)(?<temp>[\?&]authenticity[\-_]token)=[^&]*(?<rest>.*)$ "$start$temp=[FILTERED]$rest";
}
-## Remove rss_token from the request URI
-# In: /foo?private_token=[FILTERED]&authenticity_token=[FILTERED]&rss_token=unfiltered&...
-# Out: /foo?private_token=[FILTERED]&authenticity_token=[FILTERED]&rss_token=[FILTERED]&...
+## Remove feed_token from the request URI
+# In: /foo?private_token=[FILTERED]&authenticity_token=[FILTERED]&feed_token=unfiltered&...
+# Out: /foo?private_token=[FILTERED]&authenticity_token=[FILTERED]&feed_token=[FILTERED]&...
map $gitlab_ssl_temp_request_uri_2 $gitlab_ssl_filtered_request_uri {
default $gitlab_ssl_temp_request_uri_2;
- ~(?i)^(?<start>.*)(?<temp>[\?&]rss[\-_]token)=[^&]*(?<rest>.*)$ "$start$temp=[FILTERED]$rest";
+ ~(?i)^(?<start>.*)(?<temp>[\?&]feed[\-_]token)=[^&]*(?<rest>.*)$ "$start$temp=[FILTERED]$rest";
}
## A version of the referer without the query string
diff --git a/lib/tasks/gitlab/storage.rake b/lib/tasks/gitlab/storage.rake
index 6e8bd9078c8..68d6f9d7cb1 100644
--- a/lib/tasks/gitlab/storage.rake
+++ b/lib/tasks/gitlab/storage.rake
@@ -3,6 +3,7 @@ namespace :gitlab do
desc 'GitLab | Storage | Migrate existing projects to Hashed Storage'
task migrate_to_hashed: :environment do
legacy_projects_count = Project.with_unmigrated_storage.count
+ helper = Gitlab::HashedStorage::RakeHelper
if legacy_projects_count == 0
puts 'There are no projects requiring storage migration. Nothing to do!'
@@ -10,9 +11,9 @@ namespace :gitlab do
next
end
- print "Enqueuing migration of #{legacy_projects_count} projects in batches of #{batch_size}"
+ print "Enqueuing migration of #{legacy_projects_count} projects in batches of #{helper.batch_size}"
- project_id_batches do |start, finish|
+ helper.project_id_batches do |start, finish|
StorageMigratorWorker.perform_async(start, finish)
print '.'
@@ -23,118 +24,50 @@ namespace :gitlab do
desc 'Gitlab | Storage | Summary of existing projects using Legacy Storage'
task legacy_projects: :environment do
- relation_summary('projects', Project.without_storage_feature(:repository))
+ helper = Gitlab::HashedStorage::RakeHelper
+ helper.relation_summary('projects using Legacy Storage', Project.without_storage_feature(:repository))
end
desc 'Gitlab | Storage | List existing projects using Legacy Storage'
task list_legacy_projects: :environment do
- projects_list('projects using Legacy Storage', Project.without_storage_feature(:repository))
+ helper = Gitlab::HashedStorage::RakeHelper
+ helper.projects_list('projects using Legacy Storage', Project.without_storage_feature(:repository))
end
desc 'Gitlab | Storage | Summary of existing projects using Hashed Storage'
task hashed_projects: :environment do
- relation_summary('projects using Hashed Storage', Project.with_storage_feature(:repository))
+ helper = Gitlab::HashedStorage::RakeHelper
+ helper.relation_summary('projects using Hashed Storage', Project.with_storage_feature(:repository))
end
desc 'Gitlab | Storage | List existing projects using Hashed Storage'
task list_hashed_projects: :environment do
- projects_list('projects using Hashed Storage', Project.with_storage_feature(:repository))
+ helper = Gitlab::HashedStorage::RakeHelper
+ helper.projects_list('projects using Hashed Storage', Project.with_storage_feature(:repository))
end
desc 'Gitlab | Storage | Summary of project attachments using Legacy Storage'
task legacy_attachments: :environment do
- relation_summary('attachments using Legacy Storage', legacy_attachments_relation)
+ helper = Gitlab::HashedStorage::RakeHelper
+ helper.relation_summary('attachments using Legacy Storage', helper.legacy_attachments_relation)
end
desc 'Gitlab | Storage | List existing project attachments using Legacy Storage'
task list_legacy_attachments: :environment do
- attachments_list('attachments using Legacy Storage', legacy_attachments_relation)
+ helper = Gitlab::HashedStorage::RakeHelper
+ helper.attachments_list('attachments using Legacy Storage', helper.legacy_attachments_relation)
end
desc 'Gitlab | Storage | Summary of project attachments using Hashed Storage'
task hashed_attachments: :environment do
- relation_summary('attachments using Hashed Storage', hashed_attachments_relation)
+ helper = Gitlab::HashedStorage::RakeHelper
+ helper.relation_summary('attachments using Hashed Storage', helper.hashed_attachments_relation)
end
desc 'Gitlab | Storage | List existing project attachments using Hashed Storage'
task list_hashed_attachments: :environment do
- attachments_list('attachments using Hashed Storage', hashed_attachments_relation)
- end
-
- def batch_size
- ENV.fetch('BATCH', 200).to_i
- end
-
- def project_id_batches(&block)
- Project.with_unmigrated_storage.in_batches(of: batch_size, start: ENV['ID_FROM'], finish: ENV['ID_TO']) do |relation| # rubocop: disable Cop/InBatches
- ids = relation.pluck(:id)
-
- yield ids.min, ids.max
- end
- end
-
- def legacy_attachments_relation
- Upload.joins(<<~SQL).where('projects.storage_version < :version OR projects.storage_version IS NULL', version: Project::HASHED_STORAGE_FEATURES[:attachments])
- JOIN projects
- ON (uploads.model_type='Project' AND uploads.model_id=projects.id)
- SQL
- end
-
- def hashed_attachments_relation
- Upload.joins(<<~SQL).where('projects.storage_version >= :version', version: Project::HASHED_STORAGE_FEATURES[:attachments])
- JOIN projects
- ON (uploads.model_type='Project' AND uploads.model_id=projects.id)
- SQL
- end
-
- def relation_summary(relation_name, relation)
- relation_count = relation.count
- puts "* Found #{relation_count} #{relation_name}".color(:green)
-
- relation_count
- end
-
- def projects_list(relation_name, relation)
- relation_count = relation_summary(relation_name, relation)
-
- projects = relation.with_route
- limit = ENV.fetch('LIMIT', 500).to_i
-
- return unless relation_count > 0
-
- puts " ! Displaying first #{limit} #{relation_name}..." if relation_count > limit
-
- counter = 0
- projects.find_in_batches(batch_size: batch_size) do |batch|
- batch.each do |project|
- counter += 1
-
- puts " - #{project.full_path} (id: #{project.id})".color(:red)
-
- return if counter >= limit # rubocop:disable Lint/NonLocalExitFromIterator, Cop/AvoidReturnFromBlocks
- end
- end
- end
-
- def attachments_list(relation_name, relation)
- relation_count = relation_summary(relation_name, relation)
-
- limit = ENV.fetch('LIMIT', 500).to_i
-
- return unless relation_count > 0
-
- puts " ! Displaying first #{limit} #{relation_name}..." if relation_count > limit
-
- counter = 0
- relation.find_in_batches(batch_size: batch_size) do |batch|
- batch.each do |upload|
- counter += 1
-
- puts " - #{upload.path} (id: #{upload.id})".color(:red)
-
- return if counter >= limit # rubocop:disable Lint/NonLocalExitFromIterator, Cop/AvoidReturnFromBlocks
- end
- end
+ helper = Gitlab::HashedStorage::RakeHelper
+ helper.attachments_list('attachments using Hashed Storage', helper.hashed_attachments_relation)
end
end
end
diff --git a/lib/tasks/lint.rake b/lib/tasks/lint.rake
index fe5032cae18..8b86a5c72a5 100644
--- a/lib/tasks/lint.rake
+++ b/lib/tasks/lint.rake
@@ -30,11 +30,12 @@ unless Rails.env.production?
lint:static_verification
].each do |task|
pid = Process.fork do
- rd, wr = IO.pipe
+ rd_out, wr_out = IO.pipe
+ rd_err, wr_err = IO.pipe
stdout = $stdout.dup
stderr = $stderr.dup
- $stdout.reopen(wr)
- $stderr.reopen(wr)
+ $stdout.reopen(wr_out)
+ $stderr.reopen(wr_err)
begin
begin
@@ -48,14 +49,13 @@ unless Rails.env.production?
ensure
$stdout.reopen(stdout)
$stderr.reopen(stderr)
- wr.close
+ wr_out.close
+ wr_err.close
- if msg
- warn "\n#{msg}\n\n"
- IO.copy_stream(rd, $stderr)
- else
- IO.copy_stream(rd, $stdout)
- end
+ warn "\n#{msg}\n\n" if msg
+
+ IO.copy_stream(rd_out, $stdout)
+ IO.copy_stream(rd_err, $stderr)
end
end
diff --git a/lib/tasks/tokens.rake b/lib/tasks/tokens.rake
index 693597afdf8..81829668de8 100644
--- a/lib/tasks/tokens.rake
+++ b/lib/tasks/tokens.rake
@@ -6,9 +6,9 @@ namespace :tokens do
reset_all_users_token(:reset_incoming_email_token!)
end
- desc "Reset all GitLab RSS tokens"
- task reset_all_rss: :environment do
- reset_all_users_token(:reset_rss_token!)
+ desc "Reset all GitLab feed tokens"
+ task reset_all_feed: :environment do
+ reset_all_users_token(:reset_feed_token!)
end
def reset_all_users_token(reset_token_method)
@@ -31,8 +31,8 @@ class TmpUser < ActiveRecord::Base
save!(validate: false)
end
- def reset_rss_token!
- write_new_token(:rss_token)
+ def reset_feed_token!
+ write_new_token(:feed_token)
save!(validate: false)
end
end