diff options
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/commits.rb | 10 | ||||
-rw-r--r-- | lib/api/discussions.rb | 2 | ||||
-rw-r--r-- | lib/api/entities.rb | 5 | ||||
-rw-r--r-- | lib/api/helpers.rb | 2 | ||||
-rw-r--r-- | lib/api/helpers/issues_helpers.rb | 8 | ||||
-rw-r--r-- | lib/api/helpers/projects_helpers.rb | 75 | ||||
-rw-r--r-- | lib/api/helpers/protected_branches_helpers.rb | 13 | ||||
-rw-r--r-- | lib/api/helpers/services_helpers.rb | 6 | ||||
-rw-r--r-- | lib/api/helpers/settings_helpers.rb | 19 | ||||
-rw-r--r-- | lib/api/issues.rb | 14 | ||||
-rw-r--r-- | lib/api/merge_requests.rb | 35 | ||||
-rw-r--r-- | lib/api/project_import.rb | 3 | ||||
-rw-r--r-- | lib/api/projects.rb | 23 | ||||
-rw-r--r-- | lib/api/protected_branches.rb | 26 | ||||
-rw-r--r-- | lib/api/settings.rb | 52 |
15 files changed, 124 insertions, 169 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 65eb9bfb87e..80913f4ca07 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -96,17 +96,27 @@ module API end end optional :start_branch, type: String, desc: 'Name of the branch to start the new commit from' + optional :start_project, types: [Integer, String], desc: 'The ID or path of the project to start the commit from' optional :author_email, type: String, desc: 'Author email for commit' optional :author_name, type: String, desc: 'Author name for commit' optional :stats, type: Boolean, default: true, desc: 'Include commit stats' optional :force, type: Boolean, default: false, desc: 'When `true` overwrites the target branch with a new commit based on the `start_branch`' end post ':id/repository/commits' do + if params[:start_project] + start_project = find_project!(params[:start_project]) + + unless user_project.forked_from?(start_project) + forbidden!("Project is not included in the fork network for #{start_project.full_name}") + end + end + authorize_push_to_branch!(params[:branch]) attrs = declared_params attrs[:branch_name] = attrs.delete(:branch) attrs[:start_branch] ||= attrs[:branch_name] + attrs[:start_project] = start_project if start_project result = ::Files::MultiService.new(user_project, current_user, attrs).execute diff --git a/lib/api/discussions.rb b/lib/api/discussions.rb index 5928ee1657b..693172b7d08 100644 --- a/lib/api/discussions.rb +++ b/lib/api/discussions.rb @@ -206,7 +206,7 @@ module API delete_note(noteable, params[:note_id]) end - if Noteable::RESOLVABLE_TYPES.include?(noteable_type.to_s) + if Noteable.resolvable_types.include?(noteable_type.to_s) desc "Resolve/unresolve an existing #{noteable_type.to_s.downcase} discussion" do success Entities::Discussion end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 96a1ccefbe5..b1b6e7bd7b9 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -239,6 +239,7 @@ module API end end + expose :empty_repo?, as: :empty_repo expose :archived?, as: :archived expose :visibility expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group } @@ -302,6 +303,7 @@ module API expose :commit_count expose :storage_size expose :repository_size + expose :wiki_size expose :lfs_objects_size expose :build_artifacts_size, as: :job_artifacts_size end @@ -354,6 +356,7 @@ module API with_options format_with: -> (value) { value.to_i } do expose :storage_size expose :repository_size + expose :wiki_size expose :lfs_objects_size expose :build_artifacts_size, as: :job_artifacts_size end @@ -696,7 +699,7 @@ module API # See https://gitlab.com/gitlab-org/gitlab-ce/issues/42344 for more # information. expose :merge_status do |merge_request| - merge_request.check_if_can_be_merged + merge_request.check_mergeability merge_request.merge_status end expose :diff_head_sha, as: :sha diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 7e4539d0419..00bcf6b055b 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -445,7 +445,7 @@ module API end def present_carrierwave_file!(file, supports_direct_download: true) - return not_found! unless file.exists? + return not_found! unless file&.exists? if file.file_storage? present_disk_file!(file.path, file.filename) diff --git a/lib/api/helpers/issues_helpers.rb b/lib/api/helpers/issues_helpers.rb index fc66cec5341..5b7199fddb0 100644 --- a/lib/api/helpers/issues_helpers.rb +++ b/lib/api/helpers/issues_helpers.rb @@ -3,6 +3,14 @@ module API module Helpers module IssuesHelpers + extend Grape::API::Helpers + + params :optional_issue_params_ee do + end + + params :optional_issues_params_ee do + end + def self.update_params_at_least_one_of [ :assignee_id, diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index aaf32dafca4..813e46e9520 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -4,48 +4,45 @@ module API module Helpers module ProjectsHelpers extend ActiveSupport::Concern + extend Grape::API::Helpers - included do - helpers do - params :optional_project_params_ce do - optional :description, type: String, desc: 'The description of the project' - optional :ci_config_path, type: String, desc: 'The path to CI config file. Defaults to `.gitlab-ci.yml`' - 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 :jobs_enabled, type: Boolean, desc: 'Flag indication if jobs 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 :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The visibility of the project.' - 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_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' - optional :tag_list, type: Array[String], desc: 'The list of tags for a project' - optional :avatar, type: File, desc: 'Avatar image for project' - optional :printing_merge_request_link_enabled, type: Boolean, desc: 'Show link to create/view merge request when pushing from the command line' - optional :merge_method, type: String, values: %w(ff rebase_merge merge), desc: 'The merge method used when merging merge requests' - optional :initialize_with_readme, type: Boolean, desc: "Initialize a project with a README.md" - optional :external_authorization_classification_label, type: String, desc: 'The classification label for the project' - end + params :optional_project_params_ce do + optional :description, type: String, desc: 'The description of the project' + optional :ci_config_path, type: String, desc: 'The path to CI config file. Defaults to `.gitlab-ci.yml`' + 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 :jobs_enabled, type: Boolean, desc: 'Flag indication if jobs 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 :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The visibility of the project.' + 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_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' + optional :tag_list, type: Array[String], desc: 'The list of tags for a project' + optional :avatar, type: File, desc: 'Avatar image for project' + optional :printing_merge_request_link_enabled, type: Boolean, desc: 'Show link to create/view merge request when pushing from the command line' + optional :merge_method, type: String, values: %w(ff rebase_merge merge), desc: 'The merge method used when merging merge requests' + optional :initialize_with_readme, type: Boolean, desc: "Initialize a project with a README.md" + optional :external_authorization_classification_label, type: String, desc: 'The classification label for the project' + end + + params :optional_project_params_ee do + end - if Gitlab.ee? - params :optional_project_params_ee do - optional :repository_storage, type: String, desc: 'Which storage shard the repository is on. Available only to admins' - optional :approvals_before_merge, type: Integer, desc: 'How many approvers should approve merge request by default' - optional :mirror, type: Boolean, desc: 'Enables pull mirroring in a project' - optional :mirror_trigger_builds, type: Boolean, desc: 'Pull mirroring triggers builds' - end - end + params :optional_project_params do + use :optional_project_params_ce + use :optional_project_params_ee + end + + params :optional_filter_params_ee do + end - params :optional_project_params do - use :optional_project_params_ce - use :optional_project_params_ee if Gitlab.ee? - end - end + params :optional_update_params_ee do end def self.update_params_at_least_one_of diff --git a/lib/api/helpers/protected_branches_helpers.rb b/lib/api/helpers/protected_branches_helpers.rb new file mode 100644 index 00000000000..0fc6841d79a --- /dev/null +++ b/lib/api/helpers/protected_branches_helpers.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module API + module Helpers + module ProtectedBranchesHelpers + extend ActiveSupport::Concern + extend Grape::API::Helpers + + params :optional_params_ee do + end + end + end +end diff --git a/lib/api/helpers/services_helpers.rb b/lib/api/helpers/services_helpers.rb index 953be7f3798..44c577204b8 100644 --- a/lib/api/helpers/services_helpers.rb +++ b/lib/api/helpers/services_helpers.rb @@ -563,6 +563,12 @@ module API name: :notify_only_broken_pipelines, type: Boolean, desc: 'Notify only broken pipelines' + }, + { + required: false, + name: :notify_only_default_branch, + type: Boolean, + desc: 'Send notifications only for the default branch' } ], 'pivotaltracker' => [ diff --git a/lib/api/helpers/settings_helpers.rb b/lib/api/helpers/settings_helpers.rb new file mode 100644 index 00000000000..6441bb579ff --- /dev/null +++ b/lib/api/helpers/settings_helpers.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module API + module Helpers + module SettingsHelpers + extend ActiveSupport::Concern + extend Grape::API::Helpers + + params :optional_params_ee do + end + + def self.optional_attributes + [*::ApplicationSettingsHelper.visible_attributes, + *::ApplicationSettingsHelper.external_authorization_service_attributes, + :performance_bar_allowed_group_id].freeze + end + end + end +end diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 0b4da01f3c8..56960a2eb64 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -9,16 +9,6 @@ module API before { authenticate_non_get! } helpers do - if Gitlab.ee? - params :issues_params_ee do - optional :weight, types: [Integer, String], integer_none_any: true, desc: 'The weight of the issue' - end - - params :issue_params_ee do - optional :weight, type: Integer, desc: 'The weight of the issue' - end - end - params :issues_stats_params do optional :labels, type: Array[String], coerce_with: Validations::Types::LabelsList.coerce, desc: 'Comma-separated list of label names' optional :milestone, type: String, desc: 'Milestone title' @@ -47,7 +37,7 @@ module API optional :my_reaction_emoji, type: String, desc: 'Return issues reacted by the authenticated user by the given emoji' optional :confidential, type: Boolean, desc: 'Filter confidential or public issues' - use :issues_params_ee if Gitlab.ee? + use :optional_issues_params_ee end params :issues_params do @@ -73,7 +63,7 @@ module API optional :confidential, type: Boolean, desc: 'Boolean parameter if the issue should be confidential' optional :discussion_locked, type: Boolean, desc: " Boolean parameter indicating if the issue's discussion is locked" - use :issue_params_ee if Gitlab.ee? + use :optional_issue_params_ee end end diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index ce85772e4ed..5bbf6df78b0 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -386,9 +386,8 @@ module API ) if merge_when_pipeline_succeeds && merge_request.head_pipeline && merge_request.head_pipeline.active? - ::MergeRequests::MergeWhenPipelineSucceedsService - .new(merge_request.target_project, current_user, merge_params) - .execute(merge_request) + AutoMergeService.new(merge_request.target_project, current_user, merge_params) + .execute(merge_request, AutoMergeService::STRATEGY_MERGE_WHEN_PIPELINE_SUCCEEDS) else ::MergeRequests::MergeService .new(merge_request.target_project, current_user, merge_params) @@ -398,28 +397,16 @@ module API present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project end - desc 'Merge a merge request to its default temporary merge ref path' - params do - optional :merge_commit_message, type: String, desc: 'Custom merge commit message' - end - put ':id/merge_requests/:merge_request_iid/merge_to_ref' do + desc 'Returns the up to date merge-ref HEAD commit' + get ':id/merge_requests/:merge_request_iid/merge_ref' do merge_request = find_project_merge_request(params[:merge_request_iid]) - authorize! :admin_merge_request, user_project - - merge_params = { - commit_message: params[:merge_commit_message] - } - - result = ::MergeRequests::MergeToRefService - .new(merge_request.target_project, current_user, merge_params) - .execute(merge_request) + result = ::MergeRequests::MergeabilityCheckService.new(merge_request).execute - if result[:status] == :success - present result.slice(:commit_id), 200 + if result.success? + present :commit_id, result.payload.dig(:merge_ref_head, :commit_id) else - http_status = result[:http_status] || 400 - render_api_error!(result[:message], http_status) + render_api_error!(result.message, 400) end end @@ -429,11 +416,9 @@ module API post ':id/merge_requests/:merge_request_iid/cancel_merge_when_pipeline_succeeds' do merge_request = find_project_merge_request(params[:merge_request_iid]) - unauthorized! unless merge_request.can_cancel_merge_when_pipeline_succeeds?(current_user) + unauthorized! unless merge_request.can_cancel_auto_merge?(current_user) - ::MergeRequests::MergeWhenPipelineSucceedsService - .new(merge_request.target_project, current_user) - .cancel(merge_request) + AutoMergeService.new(merge_request.target_project, current_user).cancel(merge_request) end desc 'Rebase the merge request against its target branch' do diff --git a/lib/api/project_import.rb b/lib/api/project_import.rb index c64ec2fcc95..71891e43dcc 100644 --- a/lib/api/project_import.rb +++ b/lib/api/project_import.rb @@ -3,7 +3,8 @@ module API class ProjectImport < Grape::API include PaginationParams - include Helpers::ProjectsHelpers + + helpers Helpers::ProjectsHelpers helpers do def import_params diff --git a/lib/api/projects.rb b/lib/api/projects.rb index cb0106592f5..1e14c77b5be 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -6,27 +6,12 @@ module API class Projects < Grape::API include PaginationParams include Helpers::CustomAttributes - include Helpers::ProjectsHelpers + + helpers Helpers::ProjectsHelpers before { authenticate_non_get! } helpers do - if Gitlab.ee? - params :optional_filter_params_ee do - optional :wiki_checksum_failed, type: Grape::API::Boolean, default: false, desc: 'Limit by projects where wiki checksum is failed' - optional :repository_checksum_failed, type: Grape::API::Boolean, default: false, desc: 'Limit by projects where repository checksum is failed' - end - - params :optional_update_params_ee do - optional :mirror_user_id, type: Integer, desc: 'User responsible for all the activity surrounding a pull mirror event' - optional :only_mirror_protected_branches, type: Grape::API::Boolean, desc: 'Only mirror protected branches' - optional :mirror_overwrites_diverged_branches, type: Grape::API::Boolean, desc: 'Pull mirror overwrites diverged branches' - optional :import_url, type: String, desc: 'URL from which the project is imported' - optional :packages_enabled, type: Grape::API::Boolean, desc: 'Enable project packages feature' - optional :fallback_approvals_required, type: Integer, desc: 'Overall approvals required when no rule is present' - end - end - # EE::API::Projects would override this method def apply_filters(projects) projects = projects.with_issues_available_for_user(current_user) if params[:with_issues_enabled] @@ -77,7 +62,7 @@ module API optional :with_programming_language, type: String, desc: 'Limit to repositories which use the given programming language' optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'Limit by minimum access level of authenticated user' - use :optional_filter_params_ee if Gitlab.ee? + use :optional_filter_params_ee end params :create_params do @@ -296,7 +281,7 @@ module API optional :path, type: String, desc: 'The path of the repository' use :optional_project_params - use :optional_update_params_ee if Gitlab.ee? + use :optional_update_params_ee at_least_one_of(*Helpers::ProjectsHelpers.update_params_at_least_one_of) end diff --git a/lib/api/protected_branches.rb b/lib/api/protected_branches.rb index f8cce1ed784..33dea25289a 100644 --- a/lib/api/protected_branches.rb +++ b/lib/api/protected_branches.rb @@ -8,6 +8,8 @@ module API before { authorize_admin_project } + helpers Helpers::ProtectedBranchesHelpers + params do requires :id, type: String, desc: 'The ID of a project' end @@ -52,29 +54,7 @@ module API values: ProtectedBranch::MergeAccessLevel.allowed_access_levels, desc: 'Access levels allowed to merge (defaults: `40`, maintainer access level)' - if Gitlab.ee? - optional :unprotect_access_level, type: Integer, - values: ProtectedBranch::UnprotectAccessLevel.allowed_access_levels, - desc: 'Access levels allowed to unprotect (defaults: `40`, maintainer access level)' - - optional :allowed_to_push, type: Array, desc: 'An array of users/groups allowed to push' do - optional :access_level, type: Integer, values: ProtectedBranch::PushAccessLevel.allowed_access_levels - optional :user_id, type: Integer - optional :group_id, type: Integer - end - - optional :allowed_to_merge, type: Array, desc: 'An array of users/groups allowed to merge' do - optional :access_level, type: Integer, values: ProtectedBranch::MergeAccessLevel.allowed_access_levels - optional :user_id, type: Integer - optional :group_id, type: Integer - end - - optional :allowed_to_unprotect, type: Array, desc: 'An array of users/groups allowed to unprotect' do - optional :access_level, type: Integer, values: ProtectedBranch::UnprotectAccessLevel.allowed_access_levels - optional :user_id, type: Integer - optional :group_id, type: Integer - end - end + use :optional_params_ee end # rubocop: disable CodeReuse/ActiveRecord post ':id/protected_branches' do diff --git a/lib/api/settings.rb b/lib/api/settings.rb index 8046acfa397..6767ef882cb 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -4,6 +4,8 @@ module API class Settings < Grape::API before { authenticated_as_admin! } + helpers Helpers::SettingsHelpers + helpers do def current_settings @current_setting ||= @@ -136,54 +138,10 @@ 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 - if Gitlab.ee? - optional :elasticsearch_aws, type: Boolean, desc: 'Enable support for AWS hosted elasticsearch' - - given elasticsearch_aws: ->(val) { val } do - optional :elasticsearch_aws_access_key, type: String, desc: 'AWS IAM access key' - requires :elasticsearch_aws_region, type: String, desc: 'The AWS region the elasticsearch domain is configured' - optional :elasticsearch_aws_secret_access_key, type: String, desc: 'AWS IAM secret access key' - end - - optional :elasticsearch_indexing, type: Boolean, desc: 'Enable Elasticsearch indexing' - - given elasticsearch_indexing: ->(val) { val } do - optional :elasticsearch_search, type: Boolean, desc: 'Enable Elasticsearch search' - requires :elasticsearch_url, type: String, desc: 'The url to use for connecting to Elasticsearch. Use a comma-separated list to support clustering (e.g., "http://localhost:9200, http://localhost:9201")' - optional :elasticsearch_limit_indexing, type: Boolean, desc: 'Limit Elasticsearch to index certain namespaces and projects' - end - - given elasticsearch_limit_indexing: ->(val) { val } do - optional :elasticsearch_namespace_ids, type: Array[Integer], coerce_with: Validations::Types::LabelsList.coerce, desc: 'The namespace ids to index with Elasticsearch.' - optional :elasticsearch_project_ids, type: Array[Integer], coerce_with: Validations::Types::LabelsList.coerce, desc: 'The project ids to index with Elasticsearch.' - end - - optional :email_additional_text, type: String, desc: 'Additional text added to the bottom of every email for legal/auditing/compliance reasons' - optional :help_text, type: String, desc: 'GitLab server administrator information' - optional :repository_size_limit, type: Integer, desc: 'Size limit per repository (MB)' - optional :file_template_project_id, type: Integer, desc: 'ID of project where instance-level file templates are stored.' - optional :repository_storages, type: Array[String], desc: 'A list of names of enabled storage paths, taken from `gitlab.yml`. New projects will be created in one of these stores, chosen at random.' - optional :snowplow_enabled, type: Boolean, desc: 'Enable Snowplow' - - given snowplow_enabled: ->(val) { val } do - requires :snowplow_collector_uri, type: String, desc: 'Snowplow Collector URI' - optional :snowplow_cookie_domain, type: String, desc: 'Snowplow cookie domain' - optional :snowplow_site_id, type: String, desc: 'Snowplow Site/Application ID' - end - - optional :usage_ping_enabled, type: Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.' - end - - optional_attributes = [*::ApplicationSettingsHelper.visible_attributes, - *::ApplicationSettingsHelper.external_authorization_service_attributes, - :performance_bar_allowed_group_id] - - if Gitlab.ee? - optional_attributes += EE::ApplicationSettingsHelper.possible_licensed_attributes - end + use :optional_params_ee - optional(*optional_attributes) - at_least_one_of(*optional_attributes) + optional(*Helpers::SettingsHelpers.optional_attributes) + at_least_one_of(*Helpers::SettingsHelpers.optional_attributes) end put "application/settings" do attrs = declared_params(include_missing: false) |