From 26b7b475586b67c9e9aee7ec7311cca712901dbc Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Wed, 15 May 2019 13:19:16 +0200 Subject: Add *_access_level to project API - issues_access_level - repository_access_level - merge_requests_access_level - builds_access_level - wiki_access_level - snippets_access_level --- lib/api/entities.rb | 8 ++++++++ lib/api/helpers/projects_helpers.rb | 33 ++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index b9aa387ba61..4bd4442a76e 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -247,12 +247,20 @@ module API expose :container_registry_enabled # Expose old field names with the new permissions methods to keep API compatible + # TODO: remove in API v5, replaced by *_access_level 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(:jobs_enabled) { |project, options| project.feature_available?(:builds, options[:current_user]) } expose(:snippets_enabled) { |project, options| project.feature_available?(:snippets, options[:current_user]) } + expose(:issues_access_level) { |project, options| project.project_feature.string_access_level(:issues) } + expose(:repository_access_level) { |project, options| project.project_feature.string_access_level(:repository) } + expose(:merge_requests_access_level) { |project, options| project.project_feature.string_access_level(:merge_requests) } + expose(:wiki_access_level) { |project, options| project.project_feature.string_access_level(:wiki) } + expose(:builds_access_level) { |project, options| project.project_feature.string_access_level(:builds) } + expose(:snippets_access_level) { |project, options| project.project_feature.string_access_level(:snippets) } + expose :shared_runners_enabled expose :lfs_enabled?, as: :lfs_enabled expose :creator_id diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index f242f1fea0e..36d93d9457f 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -9,11 +9,21 @@ module API 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`' + + # TODO: remove in API v5, replaced by *_access_level 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 :issues_access_level, type: String, values: %w(disabled private enabled), desc: 'Issues access level. One of `disabled`, `private` or `enabled`' + optional :repository_access_level, type: String, values: %w(disabled private enabled), desc: 'Repository access level. One of `disabled`, `private` or `enabled`' + optional :merge_requests_access_level, type: String, values: %w(disabled private enabled), desc: 'Merge requests access level. One of `disabled`, `private` or `enabled`' + optional :wiki_access_level, type: String, values: %w(disabled private enabled), desc: 'Wiki access level. One of `disabled`, `private` or `enabled`' + optional :builds_access_level, type: String, values: %w(disabled private enabled), desc: 'Builds access level. One of `disabled`, `private` or `enabled`' + optional :snippets_access_level, type: String, values: %w(disabled private enabled), desc: 'Snippets access level. One of `disabled`, `private` or `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' @@ -48,15 +58,14 @@ module API def self.update_params_at_least_one_of [ - :jobs_enabled, - :resolve_outdated_diff_discussions, + :builds_access_level, :ci_config_path, :container_registry_enabled, :default_branch, :description, - :issues_enabled, + :issues_access_level, :lfs_enabled, - :merge_requests_enabled, + :merge_requests_access_level, :merge_method, :name, :only_allow_merge_if_all_discussions_are_resolved, @@ -64,14 +73,24 @@ module API :path, :printing_merge_request_link_enabled, :public_builds, + :repository_access_level, :request_access_enabled, + :resolve_outdated_diff_discussions, :shared_runners_enabled, - :snippets_enabled, + :snippets_access_level, :tag_list, :visibility, - :wiki_enabled, + :wiki_access_level, :avatar, - :external_authorization_classification_label + :external_authorization_classification_label, + + # TODO: remove in API v5, replaced by *_access_level + :issues_enabled, + :jobs_enabled, + :merge_requests_enabled, + :wiki_enabled, + :jobs_enabled, + :snippets_enabled ] end end -- cgit v1.2.1 From 353e68772c8b57ef4a98be094f2674d28a2dedcd Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Wed, 15 May 2019 14:35:55 +0200 Subject: Add build_git_strategy attribute to project API We map the boolean to the string 'fetch' or 'clone', to be more explicit. --- lib/api/entities.rb | 3 +++ lib/api/helpers/projects_helpers.rb | 2 ++ 2 files changed, 5 insertions(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 4bd4442a76e..0389ff0e045 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -275,6 +275,9 @@ module API expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] } expose :ci_default_git_depth expose :public_builds, as: :public_jobs + expose :build_git_strategy, if: lambda { |project, options| options[:user_can_admin_project] } do |project, options| + project.build_allow_git_fetch ? 'fetch' : 'clone' + end expose :ci_config_path, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) } expose :shared_with_groups do |project, options| SharedGroup.represent(project.project_group_links, options) diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index 36d93d9457f..bc847968c25 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -8,6 +8,7 @@ module API params :optional_project_params_ce do optional :description, type: String, desc: 'The description of the project' + optional :build_git_strategy, type: String, values: %w(fetch clone), desc: 'The Git strategy. Defaults to `fetch`' optional :ci_config_path, type: String, desc: 'The path to CI config file. Defaults to `.gitlab-ci.yml`' # TODO: remove in API v5, replaced by *_access_level @@ -58,6 +59,7 @@ module API def self.update_params_at_least_one_of [ + :build_git_strategy, :builds_access_level, :ci_config_path, :container_registry_enabled, -- cgit v1.2.1 From a7892e71714ad0f425547db12f205771dc270da5 Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Wed, 15 May 2019 15:32:18 +0200 Subject: Add build_timeout to project API --- lib/api/entities.rb | 1 + lib/api/helpers/projects_helpers.rb | 2 ++ 2 files changed, 3 insertions(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 0389ff0e045..3bfaf63d912 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -278,6 +278,7 @@ module API expose :build_git_strategy, if: lambda { |project, options| options[:user_can_admin_project] } do |project, options| project.build_allow_git_fetch ? 'fetch' : 'clone' end + expose :build_timeout expose :ci_config_path, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) } expose :shared_with_groups do |project, options| SharedGroup.represent(project.project_group_links, options) diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index bc847968c25..7a806839856 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -9,6 +9,7 @@ module API params :optional_project_params_ce do optional :description, type: String, desc: 'The description of the project' optional :build_git_strategy, type: String, values: %w(fetch clone), desc: 'The Git strategy. Defaults to `fetch`' + optional :build_timeout, type: Integer, desc: 'Build timeout' optional :ci_config_path, type: String, desc: 'The path to CI config file. Defaults to `.gitlab-ci.yml`' # TODO: remove in API v5, replaced by *_access_level @@ -60,6 +61,7 @@ module API def self.update_params_at_least_one_of [ :build_git_strategy, + :build_timeout, :builds_access_level, :ci_config_path, :container_registry_enabled, -- cgit v1.2.1 From 5f04d24934770e9aa366aac1400a302232eefd89 Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Wed, 15 May 2019 15:36:17 +0200 Subject: Add build_coverage_regex to project API --- lib/api/entities.rb | 1 + lib/api/helpers/projects_helpers.rb | 2 ++ 2 files changed, 3 insertions(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 3bfaf63d912..3eb2d19c624 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -279,6 +279,7 @@ module API project.build_allow_git_fetch ? 'fetch' : 'clone' end expose :build_timeout + expose :build_coverage_regex expose :ci_config_path, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) } expose :shared_with_groups do |project, options| SharedGroup.represent(project.project_group_links, options) diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index 7a806839856..956158b39a6 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -10,6 +10,7 @@ module API optional :description, type: String, desc: 'The description of the project' optional :build_git_strategy, type: String, values: %w(fetch clone), desc: 'The Git strategy. Defaults to `fetch`' optional :build_timeout, type: Integer, desc: 'Build timeout' + optional :build_coverage_regex, type: String, desc: 'Test coverage parsing' optional :ci_config_path, type: String, desc: 'The path to CI config file. Defaults to `.gitlab-ci.yml`' # TODO: remove in API v5, replaced by *_access_level @@ -60,6 +61,7 @@ module API def self.update_params_at_least_one_of [ + :build_coverage_regex, :build_git_strategy, :build_timeout, :builds_access_level, -- cgit v1.2.1 From 5028f5d73d8fa69f72ac8d2b1cc493d82cf6f3e4 Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Wed, 15 May 2019 16:17:25 +0200 Subject: Add auto_cancel_pending_pipelines to project API --- lib/api/entities.rb | 1 + lib/api/helpers/projects_helpers.rb | 2 ++ 2 files changed, 3 insertions(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 3eb2d19c624..c6c7023042f 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -279,6 +279,7 @@ module API project.build_allow_git_fetch ? 'fetch' : 'clone' end expose :build_timeout + expose :auto_cancel_pending_pipelines expose :build_coverage_regex expose :ci_config_path, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) } expose :shared_with_groups do |project, options| diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index 956158b39a6..390c694e21b 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -10,6 +10,7 @@ module API optional :description, type: String, desc: 'The description of the project' optional :build_git_strategy, type: String, values: %w(fetch clone), desc: 'The Git strategy. Defaults to `fetch`' optional :build_timeout, type: Integer, desc: 'Build timeout' + optional :auto_cancel_pending_pipelines, type: String, values: %w(disabled enabled), desc: 'Auto-cancel pending pipelines' optional :build_coverage_regex, type: String, desc: 'Test coverage parsing' optional :ci_config_path, type: String, desc: 'The path to CI config file. Defaults to `.gitlab-ci.yml`' @@ -61,6 +62,7 @@ module API def self.update_params_at_least_one_of [ + :auto_cancel_pending_pipelines, :build_coverage_regex, :build_git_strategy, :build_timeout, -- cgit v1.2.1 From e44167004dd44cf727829d0fc9df59fe3404bb49 Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Wed, 15 May 2019 16:27:54 +0200 Subject: Add auto_devops_* to project API The auto_devops object sometimes doesn't exists. We may need to create it. --- lib/api/entities.rb | 4 ++++ lib/api/helpers/projects_helpers.rb | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index c6c7023042f..7bf66589616 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -294,6 +294,10 @@ module API options[:statistics] && Ability.allowed?(options[:current_user], :read_statistics, project) } expose :external_authorization_classification_label + expose :auto_devops_enabled?, as: :auto_devops_enabled + expose :auto_devops_deploy_strategy do |project, options| + project.auto_devops.nil? ? 'continuous' : project.auto_devops.deploy_strategy + end # rubocop: disable CodeReuse/ActiveRecord def self.preload_relation(projects_relation, options = {}) diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index 390c694e21b..0e21a7a66fd 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -44,6 +44,8 @@ module API 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' optional :ci_default_git_depth, type: Integer, desc: 'Default number of revisions for shallow cloning' + optional :auto_devops_enabled, type: Boolean, desc: 'Flag indication if Auto DevOps is enabled' + optional :auto_devops_deploy_strategy, type: String, values: %w(continuous manual timed_incremental), desc: 'Auto Deploy strategy' end params :optional_project_params_ee do @@ -62,6 +64,8 @@ module API def self.update_params_at_least_one_of [ + :auto_devops_enabled, + :auto_devops_deploy_strategy, :auto_cancel_pending_pipelines, :build_coverage_regex, :build_git_strategy, -- cgit v1.2.1 From 32bbb52c19cf804c94a15e34d69a036d08acd35a Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Tue, 28 May 2019 18:09:02 +0200 Subject: Fix API performance problem of auto_devops query --- lib/api/entities.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 7bf66589616..5eae87fea02 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -201,6 +201,7 @@ module API # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20555 projects_relation.preload(:project_feature, :route) .preload(:import_state, :tags) + .preload(:auto_devops) .preload(namespace: [:route, :owner]) end # rubocop: enable CodeReuse/ActiveRecord @@ -307,6 +308,7 @@ module API # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20555 super(projects_relation).preload(:group) .preload(:ci_cd_settings) + .preload(:auto_devops) .preload(project_group_links: { group: :route }, fork_network: :root_project, fork_network_member: :forked_from_project, -- cgit v1.2.1 From b9e52612feb4956f0b3cc26af0f98810e67a5287 Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Tue, 9 Jul 2019 08:44:19 +0000 Subject: Updates on success of an MR the count on top and in other tabs New API endpoint for merge request count Updates all open tabs at the same time with one call Restructured API response API response changed to 401 if no current_user Added API + JS specs Fix for Static Check Updated Count on Open/Close, Assign/Unassign of MR's Checking if MR Count is refreshed Added # frozen_string_literal: true to spec Added Changelog --- lib/api/api.rb | 1 + lib/api/user_counts.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 lib/api/user_counts.rb (limited to 'lib/api') diff --git a/lib/api/api.rb b/lib/api/api.rb index 42499c5b41e..7016a66593d 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -166,6 +166,7 @@ module API mount ::API::Templates mount ::API::Todos mount ::API::Triggers + mount ::API::UserCounts mount ::API::Users mount ::API::Variables mount ::API::Version diff --git a/lib/api/user_counts.rb b/lib/api/user_counts.rb new file mode 100644 index 00000000000..8df4b381bbf --- /dev/null +++ b/lib/api/user_counts.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module API + class UserCounts < Grape::API + resource :user_counts do + desc 'Return the user specific counts' do + detail 'Open MR Count' + end + get do + unauthorized! unless current_user + + { + merge_requests: current_user.assigned_open_merge_requests_count + } + end + end + end +end -- cgit v1.2.1 From dba5f3aeeac6e6891ed58bdb0e66df68b152bb4a Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 1 Jul 2019 11:19:48 +0300 Subject: Rename ProjectEntity to IssuableEntity --- lib/api/entities.rb | 8 ++++---- lib/api/import_github.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index b9aa387ba61..55d38530c01 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -491,7 +491,7 @@ module API end end - class ProjectEntity < Grape::Entity + class IssuableEntity < Grape::Entity expose :id, :iid expose(:project_id) { |entity| entity&.project.try(:id) } expose :title, :description @@ -544,7 +544,7 @@ module API end end - class IssueBasic < ProjectEntity + class IssueBasic < IssuableEntity expose :closed_at expose :closed_by, using: Entities::UserBasic @@ -650,14 +650,14 @@ module API end end - class MergeRequestSimple < ProjectEntity + class MergeRequestSimple < IssuableEntity expose :title expose :web_url do |merge_request, options| Gitlab::UrlBuilder.build(merge_request) end end - class MergeRequestBasic < ProjectEntity + class MergeRequestBasic < IssuableEntity expose :merged_by, using: Entities::UserBasic do |merge_request, _options| merge_request.metrics&.merged_by end diff --git a/lib/api/import_github.rb b/lib/api/import_github.rb index e7504051808..21d4928193e 100644 --- a/lib/api/import_github.rb +++ b/lib/api/import_github.rb @@ -28,7 +28,7 @@ module API desc 'Import a GitHub project' do detail 'This feature was introduced in GitLab 11.3.4.' - success Entities::ProjectEntity + success ::ProjectEntity end params do requires :personal_access_token, type: String, desc: 'GitHub personal access token' -- cgit v1.2.1 From 639ab5214cb569dce70080020e3181946e5d3bf1 Mon Sep 17 00:00:00 2001 From: charlie ablett Date: Tue, 9 Jul 2019 12:45:23 +0000 Subject: Remove `:graphql` feature flag - Remove `FeatureConstrainer` call wrapping api endpoint - Remove `Feature.enabled?(:graphql)` conditionals in back and frontend - Modify graphql test to be graphql flag agnostic - Remove api routing spec - Remove frontend feature flag via `gon` --- lib/api/helpers/graphql_helpers.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/api') diff --git a/lib/api/helpers/graphql_helpers.rb b/lib/api/helpers/graphql_helpers.rb index 94010ab1bc2..bd60470fbd6 100644 --- a/lib/api/helpers/graphql_helpers.rb +++ b/lib/api/helpers/graphql_helpers.rb @@ -7,8 +7,6 @@ module API # should be in app/graphql/ or lib/gitlab/graphql/ module GraphqlHelpers def conditionally_graphql!(fallback:, query:, context: {}, transform: nil) - return fallback.call unless Feature.enabled?(:graphql) - result = GitlabSchema.execute(query, context: context) if transform -- cgit v1.2.1