diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-11 15:07:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-11 15:07:33 +0000 |
commit | 34ce62a494ab1e8f1e76dc4f0bda925593a4c0cb (patch) | |
tree | bdf6d89f15cfac499ff6a750c69d78060b1f3bdd /lib/api | |
parent | 2761b4465bb13e170f0b8b2941d83f356a47eee6 (diff) | |
download | gitlab-ce-34ce62a494ab1e8f1e76dc4f0bda925593a4c0cb.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/api.rb | 4 | ||||
-rw-r--r-- | lib/api/ci/jobs.rb | 2 | ||||
-rw-r--r-- | lib/api/entities/project_daily_fetches.rb | 4 | ||||
-rw-r--r-- | lib/api/entities/project_daily_statistics.rb | 4 | ||||
-rw-r--r-- | lib/api/files.rb | 73 | ||||
-rw-r--r-- | lib/api/project_statistics.rb | 10 | ||||
-rw-r--r-- | lib/api/unleash.rb | 14 |
7 files changed, 67 insertions, 44 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index 4d25108cfe5..b1d359f0479 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -195,6 +195,7 @@ module API mount ::API::FeatureFlags mount ::API::FeatureFlagsUserLists mount ::API::Features + mount ::API::Files mount ::API::FreezePeriods mount ::API::GroupClusters mount ::API::GroupExport @@ -216,6 +217,7 @@ module API mount ::API::ProjectRepositoryStorageMoves mount ::API::ProjectSnippets mount ::API::ProjectSnapshots + mount ::API::ProjectStatistics mount ::API::ProjectTemplates mount ::API::ProtectedBranches mount ::API::ProtectedTags @@ -268,7 +270,6 @@ module API mount ::API::ErrorTracking::Collector mount ::API::ErrorTracking::ProjectSettings mount ::API::Events - mount ::API::Files mount ::API::GenericPackages mount ::API::Geo mount ::API::GoProxy @@ -309,7 +310,6 @@ module API mount ::API::ProjectEvents mount ::API::ProjectMilestones mount ::API::ProjectPackages - mount ::API::ProjectStatistics mount ::API::Projects mount ::API::ProtectedTags mount ::API::PypiPackages diff --git a/lib/api/ci/jobs.rb b/lib/api/ci/jobs.rb index 1836cfd8217..9e41e1c0d8f 100644 --- a/lib/api/ci/jobs.rb +++ b/lib/api/ci/jobs.rb @@ -262,7 +262,7 @@ module API .select { |_role, role_access_level| role_access_level <= user_access_level } .map(&:first) - environment = if persisted_environment = current_authenticated_job.persisted_environment + environment = if persisted_environment = current_authenticated_job.actual_persisted_environment { tier: persisted_environment.tier, slug: persisted_environment.slug } end diff --git a/lib/api/entities/project_daily_fetches.rb b/lib/api/entities/project_daily_fetches.rb index 036b5dc99b8..8797aeb9521 100644 --- a/lib/api/entities/project_daily_fetches.rb +++ b/lib/api/entities/project_daily_fetches.rb @@ -3,8 +3,8 @@ module API module Entities class ProjectDailyFetches < Grape::Entity - expose :fetch_count, as: :count - expose :date + expose :fetch_count, as: :count, documentation: { type: 'integer', example: 3 } + expose :date, documentation: { type: 'date', example: '2022-01-01' } end end end diff --git a/lib/api/entities/project_daily_statistics.rb b/lib/api/entities/project_daily_statistics.rb index 803ee445851..555ecc6be39 100644 --- a/lib/api/entities/project_daily_statistics.rb +++ b/lib/api/entities/project_daily_statistics.rb @@ -4,8 +4,8 @@ module API module Entities class ProjectDailyStatistics < Grape::Entity expose :fetches do - expose :total_fetch_count, as: :total - expose :fetches, as: :days, using: ProjectDailyFetches + expose :total_fetch_count, as: :total, documentation: { type: 'integer', example: 3 } + expose :fetches, as: :days, using: ProjectDailyFetches, documentation: { is_array: true } end end end diff --git a/lib/api/files.rb b/lib/api/files.rb index 1b3961e4aac..68dd2647703 100644 --- a/lib/api/files.rb +++ b/lib/api/files.rb @@ -82,33 +82,44 @@ module API end params :simple_file_params do - requires :file_path, type: String, file_path: true, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' - requires :branch, type: String, desc: 'Name of the branch to commit into. To create a new branch, also provide `start_branch`.', allow_blank: false - requires :commit_message, type: String, allow_blank: false, desc: 'Commit message' - optional :start_branch, type: String, desc: 'Name of the branch to start the new commit from' - optional :author_email, type: String, desc: 'The email of the author' - optional :author_name, type: String, desc: 'The name of the author' + requires :file_path, type: String, file_path: true, + desc: 'The url encoded path to the file.', documentation: { example: 'lib%2Fclass%2Erb' } + requires :branch, type: String, + desc: 'Name of the branch to commit into. To create a new branch, also provide `start_branch`.', allow_blank: false, + documentation: { example: 'main' } + requires :commit_message, type: String, + allow_blank: false, desc: 'Commit message', documentation: { example: 'Initial commit' } + optional :start_branch, type: String, + desc: 'Name of the branch to start the new commit from', documentation: { example: 'main' } + optional :author_email, type: String, + desc: 'The email of the author', documentation: { example: 'johndoe@example.com' } + optional :author_name, type: String, + desc: 'The name of the author', documentation: { example: 'John Doe' } end params :extended_file_params do use :simple_file_params - requires :content, type: String, desc: 'File content' + requires :content, type: String, desc: 'File content', documentation: { example: 'file content' } optional :encoding, type: String, values: %w[base64 text], default: 'text', desc: 'File encoding' - optional :last_commit_id, type: String, desc: 'Last known commit id for this file' + optional :last_commit_id, type: String, + desc: 'Last known commit id for this file', + documentation: { example: '2695effb5807a22ff3d138d593fd856244e155e7' } optional :execute_filemode, type: Boolean, desc: 'Enable / Disable the executable flag on the file path' end end params do - requires :id, type: String, desc: 'The project ID' + requires :id, type: String, desc: 'The project ID', documentation: { example: 'gitlab-org/gitlab' } end resource :projects, requirements: FILE_ENDPOINT_REQUIREMENTS do allow_access_with_scope :read_repository, if: -> (request) { request.get? || request.head? } desc 'Get blame file metadata from repository' params do - requires :file_path, type: String, file_path: true, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' - requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false + requires :file_path, type: String, file_path: true, + desc: 'The url encoded path to the file.', documentation: { example: 'lib%2Fclass%2Erb' } + requires :ref, type: String, + desc: 'The name of branch, tag or commit', allow_blank: false, documentation: { example: 'main' } end head ":id/repository/files/:file_path/blame", requirements: FILE_ENDPOINT_REQUIREMENTS do assign_file_vars! @@ -118,11 +129,15 @@ module API desc 'Get blame file from the repository' params do - requires :file_path, type: String, file_path: true, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' - requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false + requires :file_path, type: String, file_path: true, + desc: 'The url encoded path to the file.', documentation: { example: 'lib%2Fclass%2Erb' } + requires :ref, type: String, + desc: 'The name of branch, tag or commit', allow_blank: false, documentation: { example: 'main' } optional :range, type: Hash do - requires :start, type: Integer, desc: 'The first line of the range to blame', allow_blank: false, values: ->(v) { v > 0 } - requires :end, type: Integer, desc: 'The last line of the range to blame', allow_blank: false, values: ->(v) { v > 0 } + requires :start, type: Integer, + desc: 'The first line of the range to blame', allow_blank: false, values: ->(v) { v > 0 } + requires :end, type: Integer, + desc: 'The last line of the range to blame', allow_blank: false, values: ->(v) { v > 0 } end end get ":id/repository/files/:file_path/blame", requirements: FILE_ENDPOINT_REQUIREMENTS do @@ -138,8 +153,10 @@ module API desc 'Get raw file metadata from repository' params do - requires :file_path, type: String, file_path: true, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' - optional :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false + requires :file_path, type: String, file_path: true, + desc: 'The url encoded path to the file.', documentation: { example: 'lib%2Fclass%2Erb' } + optional :ref, type: String, + desc: 'The name of branch, tag or commit', allow_blank: false, documentation: { example: 'main' } end head ":id/repository/files/:file_path/raw", requirements: FILE_ENDPOINT_REQUIREMENTS, urgency: :low do assign_file_vars! @@ -147,10 +164,14 @@ module API set_http_headers(blob_data) end - desc 'Get raw file contents from the repository' + desc 'Get raw file contents from the repository' do + success File + end params do - requires :file_path, type: String, file_path: true, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' - optional :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false + requires :file_path, type: String, file_path: true, + desc: 'The url encoded path to the file.', documentation: { example: 'lib%2Fclass%2Erb' } + optional :ref, type: String, + desc: 'The name of branch, tag or commit', allow_blank: false, documentation: { example: 'main' } end get ":id/repository/files/:file_path/raw", requirements: FILE_ENDPOINT_REQUIREMENTS, urgency: :low do assign_file_vars! @@ -163,8 +184,10 @@ module API desc 'Get file metadata from repository' params do - requires :file_path, type: String, file_path: true, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' - requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false + requires :file_path, type: String, file_path: true, + desc: 'The url encoded path to the file.', documentation: { example: 'lib%2Fclass%2Erb' } + requires :ref, type: String, + desc: 'The name of branch, tag or commit', allow_blank: false, documentation: { example: 'main' } end head ":id/repository/files/:file_path", requirements: FILE_ENDPOINT_REQUIREMENTS, urgency: :low do assign_file_vars! @@ -174,8 +197,10 @@ module API desc 'Get a file from the repository' params do - requires :file_path, type: String, file_path: true, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' - requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false + requires :file_path, type: String, file_path: true, + desc: 'The url encoded path to the file.', documentation: { example: 'lib%2Fclass%2Erb' } + requires :ref, type: String, + desc: 'The name of branch, tag or commit', allow_blank: false, documentation: { example: 'main' } end get ":id/repository/files/:file_path", requirements: FILE_ENDPOINT_REQUIREMENTS do assign_file_vars! diff --git a/lib/api/project_statistics.rb b/lib/api/project_statistics.rb index 445feebc2b9..859e53b6981 100644 --- a/lib/api/project_statistics.rb +++ b/lib/api/project_statistics.rb @@ -13,7 +13,15 @@ module API requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project' end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get the list of project fetch statistics for the last 30 days' + desc 'Get the list of project fetch statistics for the last 30 days' do + success Entities::ProjectDailyStatistics + failure [ + { code: 404, message: '404 Project Not Found' }, + { code: 401, message: '401 Unauthorized' } + ] + tags %w[projects] + end + get ":id/statistics" do statistic_finder = ::Projects::DailyStatisticsFinder.new(user_project) diff --git a/lib/api/unleash.rb b/lib/api/unleash.rb index 949f4a46a1b..38ce4bd7f32 100644 --- a/lib/api/unleash.rb +++ b/lib/api/unleash.rb @@ -30,12 +30,7 @@ module API tags unleash_tags end get 'features', urgency: :low do - if ::Feature.enabled?(:cache_unleash_client_api, project) - present_feature_flags - else - present :version, 1 - present :features, feature_flags, with: ::API::Entities::UnleashFeature - end + present_feature_flags end # We decrease the urgency of this endpoint until the maxmemory issue of redis-cache has been resolved. @@ -45,12 +40,7 @@ module API tags unleash_tags end get 'client/features', urgency: :low do - if ::Feature.enabled?(:cache_unleash_client_api, project) - present_feature_flags - else - present :version, 1 - present :features, feature_flags, with: ::API::Entities::UnleashFeature - end + present_feature_flags end post 'client/register' do |