diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 00:08:46 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 00:08:46 +0000 |
commit | 47d1f417f03aca055b2ba49c32bb6fb01c459831 (patch) | |
tree | 200f05f28369cbf3a34abcb4a3c388558268b86f /lib | |
parent | 006e89697dd5165f355afc20fc6bb0cdfa7b381a (diff) | |
download | gitlab-ce-47d1f417f03aca055b2ba49c32bb6fb01c459831.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
22 files changed, 323 insertions, 220 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index aa2cbd3fed3..5d5a61b76f1 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -163,42 +163,6 @@ module API end end - class LabelBasic < Grape::Entity - expose :id, :name, :color, :description, :description_html, :text_color - end - - class Label < LabelBasic - with_options if: lambda { |_, options| options[:with_counts] } do - expose :open_issues_count do |label, options| - label.open_issues_count(options[:current_user]) - end - - expose :closed_issues_count do |label, options| - label.closed_issues_count(options[:current_user]) - end - - expose :open_merge_requests_count do |label, options| - label.open_merge_requests_count(options[:current_user]) - end - end - - expose :subscribed do |label, options| - label.subscribed?(options[:current_user], options[:parent]) - end - end - - class GroupLabel < Label - end - - class ProjectLabel < Label - expose :priority do |label, options| - label.priority(options[:parent]) - end - expose :is_project_label do |label, options| - label.is_a?(::ProjectLabel) - end - end - class List < Grape::Entity expose :id expose :label, using: Entities::LabelBasic @@ -242,130 +206,6 @@ module API expose :message, :starts_at, :ends_at, :color, :font, :target_path, :broadcast_type end - class ApplicationStatistics < Grape::Entity - include ActionView::Helpers::NumberHelper - include CountHelper - - expose :forks do |counts| - approximate_fork_count_with_delimiters(counts) - end - - expose :issues do |counts| - approximate_count_with_delimiters(counts, ::Issue) - end - - expose :merge_requests do |counts| - approximate_count_with_delimiters(counts, ::MergeRequest) - end - - expose :notes do |counts| - approximate_count_with_delimiters(counts, ::Note) - end - - expose :snippets do |counts| - approximate_count_with_delimiters(counts, ::Snippet) - end - - expose :ssh_keys do |counts| - approximate_count_with_delimiters(counts, ::Key) - end - - expose :milestones do |counts| - approximate_count_with_delimiters(counts, ::Milestone) - end - - expose :users do |counts| - approximate_count_with_delimiters(counts, ::User) - end - - expose :projects do |counts| - approximate_count_with_delimiters(counts, ::Project) - end - - expose :groups do |counts| - approximate_count_with_delimiters(counts, ::Group) - end - - expose :active_users do |_| - number_with_delimiter(::User.active.count) - end - end - - class ApplicationSetting < Grape::Entity - def self.exposed_attributes - attributes = ::ApplicationSettingsHelper.visible_attributes - attributes.delete(:performance_bar_allowed_group_path) - attributes.delete(:performance_bar_enabled) - attributes.delete(:allow_local_requests_from_hooks_and_services) - - # let's not expose the secret key in a response - attributes.delete(:asset_proxy_secret_key) - attributes.delete(:eks_secret_access_key) - - 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 - expose(:default_project_visibility) { |setting, _options| Gitlab::VisibilityLevel.string_level(setting.default_project_visibility) } - expose(:default_snippet_visibility) { |setting, _options| Gitlab::VisibilityLevel.string_level(setting.default_snippet_visibility) } - expose(:default_group_visibility) { |setting, _options| Gitlab::VisibilityLevel.string_level(setting.default_group_visibility) } - - expose(*::ApplicationSettingsHelper.external_authorization_service_attributes) - - # support legacy names, can be removed in v5 - expose :password_authentication_enabled_for_web, as: :password_authentication_enabled - expose :password_authentication_enabled_for_web, as: :signin_enabled - expose :allow_local_requests_from_web_hooks_and_services, as: :allow_local_requests_from_hooks_and_services - end - - class Appearance < Grape::Entity - expose :title - expose :description - - expose :logo do |appearance, options| - appearance.logo.url - end - - expose :header_logo do |appearance, options| - appearance.header_logo.url - end - - expose :favicon do |appearance, options| - appearance.favicon.url - end - - expose :new_project_guidelines - expose :header_message - expose :footer_message - expose :message_background_color - expose :message_font_color - expose :email_header_and_footer_enabled - end - - # deprecated old Release representation - class TagRelease < Grape::Entity - expose :tag, as: :tag_name - expose :description - end - - module Releases - class Link < Grape::Entity - expose :id - expose :name - expose :url - expose :external?, as: :external - end - - class Source < Grape::Entity - expose :format - expose :url - end - end - class Release < Grape::Entity include ::API::Helpers::Presentable @@ -477,40 +317,6 @@ module API expose :id, :token end - class JobArtifactFile < Grape::Entity - expose :filename - expose :cached_size, as: :size - end - - class JobArtifact < Grape::Entity - expose :file_type, :size, :filename, :file_format - end - - class JobBasic < Grape::Entity - expose :id, :status, :stage, :name, :ref, :tag, :coverage, :allow_failure - expose :created_at, :started_at, :finished_at - expose :duration - expose :user, with: Entities::User - expose :commit, with: Entities::Commit - expose :pipeline, with: Entities::PipelineBasic - - expose :web_url do |job, _options| - Gitlab::Routing.url_helpers.project_job_url(job.project, job) - end - end - - class Job < JobBasic - # artifacts_file is included in job_artifacts, but kept for backward compatibility (remove in api/v5) - expose :artifacts_file, using: JobArtifactFile, if: -> (job, opts) { job.artifacts? } - expose :job_artifacts, as: :artifacts, using: JobArtifact - expose :runner, with: Runner - expose :artifacts_expire_at - end - - class JobBasicWithProject < JobBasic - expose :project, with: Entities::ProjectIdentity - end - class Trigger < Grape::Entity include ::API::Helpers::Presentable @@ -585,32 +391,6 @@ module API expose :content end - class TemplatesList < Grape::Entity - expose :key - expose :name - end - - class Template < Grape::Entity - expose :name, :content - end - - class BroadcastMessage < Grape::Entity - expose :id, :message, :starts_at, :ends_at, :color, :font - expose :active?, as: :active - end - - class PersonalAccessToken < Grape::Entity - expose :id, :name, :revoked, :created_at, :scopes - expose :active?, as: :active - expose :expires_at do |personal_access_token| - personal_access_token.expires_at ? personal_access_token.expires_at.strftime("%Y-%m-%d") : nil - end - end - - class PersonalAccessTokenWithToken < PersonalAccessToken - expose :token - end - class ImpersonationToken < PersonalAccessToken expose :impersonation end diff --git a/lib/api/entities/appearance.rb b/lib/api/entities/appearance.rb new file mode 100644 index 00000000000..c3cffc8d05c --- /dev/null +++ b/lib/api/entities/appearance.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module API + module Entities + class Appearance < Grape::Entity + expose :title + expose :description + + expose :logo do |appearance, options| + appearance.logo.url + end + + expose :header_logo do |appearance, options| + appearance.header_logo.url + end + + expose :favicon do |appearance, options| + appearance.favicon.url + end + + expose :new_project_guidelines + expose :header_message + expose :footer_message + expose :message_background_color + expose :message_font_color + expose :email_header_and_footer_enabled + end + end +end diff --git a/lib/api/entities/application_setting.rb b/lib/api/entities/application_setting.rb new file mode 100644 index 00000000000..6ca2d1e6da4 --- /dev/null +++ b/lib/api/entities/application_setting.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module API + module Entities + class ApplicationSetting < Grape::Entity + def self.exposed_attributes + attributes = ::ApplicationSettingsHelper.visible_attributes + attributes.delete(:performance_bar_allowed_group_path) + attributes.delete(:performance_bar_enabled) + attributes.delete(:allow_local_requests_from_hooks_and_services) + + # let's not expose the secret key in a response + attributes.delete(:asset_proxy_secret_key) + attributes.delete(:eks_secret_access_key) + + 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 + expose(:default_project_visibility) { |setting, _options| Gitlab::VisibilityLevel.string_level(setting.default_project_visibility) } + expose(:default_snippet_visibility) { |setting, _options| Gitlab::VisibilityLevel.string_level(setting.default_snippet_visibility) } + expose(:default_group_visibility) { |setting, _options| Gitlab::VisibilityLevel.string_level(setting.default_group_visibility) } + + expose(*::ApplicationSettingsHelper.external_authorization_service_attributes) + + # support legacy names, can be removed in v5 + expose :password_authentication_enabled_for_web, as: :password_authentication_enabled + expose :password_authentication_enabled_for_web, as: :signin_enabled + expose :allow_local_requests_from_web_hooks_and_services, as: :allow_local_requests_from_hooks_and_services + end + end +end diff --git a/lib/api/entities/application_statistics.rb b/lib/api/entities/application_statistics.rb new file mode 100644 index 00000000000..4bcba1da464 --- /dev/null +++ b/lib/api/entities/application_statistics.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +module API + module Entities + class ApplicationStatistics < Grape::Entity + include ActionView::Helpers::NumberHelper + include CountHelper + + expose :forks do |counts| + approximate_fork_count_with_delimiters(counts) + end + + expose :issues do |counts| + approximate_count_with_delimiters(counts, ::Issue) + end + + expose :merge_requests do |counts| + approximate_count_with_delimiters(counts, ::MergeRequest) + end + + expose :notes do |counts| + approximate_count_with_delimiters(counts, ::Note) + end + + expose :snippets do |counts| + approximate_count_with_delimiters(counts, ::Snippet) + end + + expose :ssh_keys do |counts| + approximate_count_with_delimiters(counts, ::Key) + end + + expose :milestones do |counts| + approximate_count_with_delimiters(counts, ::Milestone) + end + + expose :users do |counts| + approximate_count_with_delimiters(counts, ::User) + end + + expose :projects do |counts| + approximate_count_with_delimiters(counts, ::Project) + end + + expose :groups do |counts| + approximate_count_with_delimiters(counts, ::Group) + end + + expose :active_users do |_| + number_with_delimiter(::User.active.count) + end + end + end +end diff --git a/lib/api/entities/broadcast_message.rb b/lib/api/entities/broadcast_message.rb new file mode 100644 index 00000000000..31d4cc50526 --- /dev/null +++ b/lib/api/entities/broadcast_message.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module API + module Entities + class BroadcastMessage < Grape::Entity + expose :id, :message, :starts_at, :ends_at, :color, :font + expose :active?, as: :active + end + end +end diff --git a/lib/api/entities/group_label.rb b/lib/api/entities/group_label.rb new file mode 100644 index 00000000000..4e1b9226e6d --- /dev/null +++ b/lib/api/entities/group_label.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module API + module Entities + class GroupLabel < Entities::Label + end + end +end diff --git a/lib/api/entities/job.rb b/lib/api/entities/job.rb new file mode 100644 index 00000000000..cbee8794007 --- /dev/null +++ b/lib/api/entities/job.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module API + module Entities + class Job < Entities::JobBasic + # artifacts_file is included in job_artifacts, but kept for backward compatibility (remove in api/v5) + expose :artifacts_file, using: Entities::JobArtifactFile, if: -> (job, opts) { job.artifacts? } + expose :job_artifacts, as: :artifacts, using: Entities::JobArtifact + expose :runner, with: Entities::Runner + expose :artifacts_expire_at + end + end +end diff --git a/lib/api/entities/job_artifact.rb b/lib/api/entities/job_artifact.rb new file mode 100644 index 00000000000..94dbdb38fee --- /dev/null +++ b/lib/api/entities/job_artifact.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module API + module Entities + class JobArtifact < Grape::Entity + expose :file_type, :size, :filename, :file_format + end + end +end diff --git a/lib/api/entities/job_artifact_file.rb b/lib/api/entities/job_artifact_file.rb new file mode 100644 index 00000000000..fa2851a7f0e --- /dev/null +++ b/lib/api/entities/job_artifact_file.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module API + module Entities + class JobArtifactFile < Grape::Entity + expose :filename + expose :cached_size, as: :size + end + end +end diff --git a/lib/api/entities/job_basic.rb b/lib/api/entities/job_basic.rb new file mode 100644 index 00000000000..a8541039934 --- /dev/null +++ b/lib/api/entities/job_basic.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module API + module Entities + class JobBasic < Grape::Entity + expose :id, :status, :stage, :name, :ref, :tag, :coverage, :allow_failure + expose :created_at, :started_at, :finished_at + expose :duration + expose :user, with: Entities::User + expose :commit, with: Entities::Commit + expose :pipeline, with: Entities::PipelineBasic + + expose :web_url do |job, _options| + Gitlab::Routing.url_helpers.project_job_url(job.project, job) + end + end + end +end diff --git a/lib/api/entities/job_basic_with_project.rb b/lib/api/entities/job_basic_with_project.rb new file mode 100644 index 00000000000..09387e045ec --- /dev/null +++ b/lib/api/entities/job_basic_with_project.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module API + module Entities + class JobBasicWithProject < Entities::JobBasic + expose :project, with: Entities::ProjectIdentity + end + end +end diff --git a/lib/api/entities/label.rb b/lib/api/entities/label.rb new file mode 100644 index 00000000000..ca9a0912331 --- /dev/null +++ b/lib/api/entities/label.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module API + module Entities + class Label < Entities::LabelBasic + with_options if: lambda { |_, options| options[:with_counts] } do + expose :open_issues_count do |label, options| + label.open_issues_count(options[:current_user]) + end + + expose :closed_issues_count do |label, options| + label.closed_issues_count(options[:current_user]) + end + + expose :open_merge_requests_count do |label, options| + label.open_merge_requests_count(options[:current_user]) + end + end + + expose :subscribed do |label, options| + label.subscribed?(options[:current_user], options[:parent]) + end + end + end +end diff --git a/lib/api/entities/label_basic.rb b/lib/api/entities/label_basic.rb new file mode 100644 index 00000000000..ed52688638e --- /dev/null +++ b/lib/api/entities/label_basic.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module API + module Entities + class LabelBasic < Grape::Entity + expose :id, :name, :color, :description, :description_html, :text_color + end + end +end diff --git a/lib/api/entities/personal_access_token.rb b/lib/api/entities/personal_access_token.rb new file mode 100644 index 00000000000..d6fb9af6ab3 --- /dev/null +++ b/lib/api/entities/personal_access_token.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module API + module Entities + class PersonalAccessToken < Grape::Entity + expose :id, :name, :revoked, :created_at, :scopes + expose :active?, as: :active + expose :expires_at do |personal_access_token| + personal_access_token.expires_at ? personal_access_token.expires_at.strftime("%Y-%m-%d") : nil + end + end + end +end diff --git a/lib/api/entities/personal_access_token_with_token.rb b/lib/api/entities/personal_access_token_with_token.rb new file mode 100644 index 00000000000..84dcd3bc8d8 --- /dev/null +++ b/lib/api/entities/personal_access_token_with_token.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module API + module Entities + class PersonalAccessTokenWithToken < Entities::PersonalAccessToken + expose :token + end + end +end diff --git a/lib/api/entities/project_label.rb b/lib/api/entities/project_label.rb new file mode 100644 index 00000000000..b47a9414ddb --- /dev/null +++ b/lib/api/entities/project_label.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module API + module Entities + class ProjectLabel < Entities::Label + expose :priority do |label, options| + label.priority(options[:parent]) + end + expose :is_project_label do |label, options| + label.is_a?(::ProjectLabel) + end + end + end +end diff --git a/lib/api/entities/releases/link.rb b/lib/api/entities/releases/link.rb new file mode 100644 index 00000000000..6cc01e0e981 --- /dev/null +++ b/lib/api/entities/releases/link.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module API + module Entities + module Releases + class Link < Grape::Entity + expose :id + expose :name + expose :url + expose :external?, as: :external + end + end + end +end diff --git a/lib/api/entities/releases/source.rb b/lib/api/entities/releases/source.rb new file mode 100644 index 00000000000..2b0c8038ddf --- /dev/null +++ b/lib/api/entities/releases/source.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module API + module Entities + module Releases + class Source < Grape::Entity + expose :format + expose :url + end + end + end +end diff --git a/lib/api/entities/tag_release.rb b/lib/api/entities/tag_release.rb new file mode 100644 index 00000000000..d5f73d60332 --- /dev/null +++ b/lib/api/entities/tag_release.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module API + module Entities + # deprecated old Release representation + class TagRelease < Grape::Entity + expose :tag, as: :tag_name + expose :description + end + end +end diff --git a/lib/api/entities/template.rb b/lib/api/entities/template.rb new file mode 100644 index 00000000000..ef364d971bf --- /dev/null +++ b/lib/api/entities/template.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module API + module Entities + class Template < Grape::Entity + expose :name, :content + end + end +end diff --git a/lib/api/entities/templates_list.rb b/lib/api/entities/templates_list.rb new file mode 100644 index 00000000000..8e8aa1bd285 --- /dev/null +++ b/lib/api/entities/templates_list.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module API + module Entities + class TemplatesList < Grape::Entity + expose :key + expose :name + end + end +end diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb index 974e32ce17c..123a695be13 100644 --- a/lib/backup/repository.rb +++ b/lib/backup/repository.rb @@ -96,6 +96,7 @@ module Backup end wiki = ProjectWiki.new(project) + wiki.repository.remove rescue nil path_to_wiki_bundle = path_to_bundle(wiki) if File.exist?(path_to_wiki_bundle) |