debian-mirror-gitlab/lib/api/entities.rb

1889 lines
62 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module API
module Entities
2019-10-12 21:52:04 +05:30
class BlameRangeCommit < Grape::Entity
expose :id
expose :parent_ids
expose :message
expose :authored_date, :author_name, :author_email
expose :committed_date, :committer_name, :committer_email
end
class BlameRange < Grape::Entity
expose :commit, using: BlameRangeCommit
expose :lines
end
2018-03-17 18:26:18 +05:30
class WikiPageBasic < Grape::Entity
expose :format
expose :slug
expose :title
end
class WikiPage < WikiPageBasic
expose :content
end
2018-11-20 20:47:30 +05:30
class WikiAttachment < Grape::Entity
include Gitlab::FileMarkdownLinkBuilder
expose :file_name
expose :file_path
expose :branch
expose :link do
expose :file_path, as: :url
expose :markdown do |_entity|
self.markdown_link
end
end
def filename
object.file_name
end
def secure_url
object.file_path
end
end
2014-09-02 18:07:02 +05:30
class UserSafe < Grape::Entity
2018-03-17 18:26:18 +05:30
expose :id, :name, :username
2014-09-02 18:07:02 +05:30
end
class UserBasic < UserSafe
2018-03-17 18:26:18 +05:30
expose :state
2017-09-10 17:25:29 +05:30
expose :avatar_url do |user, options|
user.avatar_url(only_path: false)
end
2015-09-11 14:41:01 +05:30
2018-03-17 18:26:18 +05:30
expose :avatar_path, if: ->(user, options) { options.fetch(:only_path, false) && user.avatar_path }
2018-03-27 19:54:05 +05:30
expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes
2018-03-17 18:26:18 +05:30
2015-09-11 14:41:01 +05:30
expose :web_url do |user, options|
2016-06-02 11:05:42 +05:30
Gitlab::Routing.url_helpers.user_url(user)
2015-09-11 14:41:01 +05:30
end
2014-09-02 18:07:02 +05:30
end
class User < UserBasic
2018-11-18 11:00:15 +05:30
expose :created_at, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) }
2018-12-05 23:21:45 +05:30
expose :bio, :location, :public_email, :skype, :linkedin, :twitter, :website_url, :organization
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
class UserActivity < Grape::Entity
expose :username
expose :last_activity_on
expose :last_activity_on, as: :last_activity_at # Back-compat
end
2019-10-12 21:52:04 +05:30
class UserStarsProject < Grape::Entity
expose :starred_since
expose :user, using: Entities::UserBasic
end
2015-04-26 12:48:37 +05:30
class Identity < Grape::Entity
expose :provider, :extern_uid
end
2017-01-15 13:20:01 +05:30
class UserPublic < User
2016-06-02 11:05:42 +05:30
expose :last_sign_in_at
expose :confirmed_at
2017-08-17 22:00:37 +05:30
expose :last_activity_on
2014-09-02 18:07:02 +05:30
expose :email
2018-03-17 18:26:18 +05:30
expose :theme_id, :color_scheme_id, :projects_limit, :current_sign_in_at
2015-04-26 12:48:37 +05:30
expose :identities, using: Entities::Identity
2014-09-02 18:07:02 +05:30
expose :can_create_group?, as: :can_create_group
expose :can_create_project?, as: :can_create_project
expose :two_factor_enabled?, as: :two_factor_enabled
2016-06-02 11:05:42 +05:30
expose :external
2018-11-18 11:00:15 +05:30
expose :private_profile
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
class UserWithAdmin < UserPublic
expose :admin?, as: :is_admin
end
2019-07-07 11:18:12 +05:30
class UserDetailsWithAdmin < UserWithAdmin
expose :highest_role
end
2018-11-18 11:00:15 +05:30
class UserStatus < Grape::Entity
expose :emoji
expose :message
expose :message_html do |entity|
MarkupHelper.markdown_field(entity, :message)
end
end
2015-09-11 14:41:01 +05:30
class Email < Grape::Entity
expose :id, :email
end
2014-09-02 18:07:02 +05:30
class Hook < Grape::Entity
2018-03-17 18:26:18 +05:30
expose :id, :url, :created_at, :push_events, :tag_push_events, :merge_requests_events, :repository_update_events
2017-08-17 22:00:37 +05:30
expose :enable_ssl_verification
2014-09-02 18:07:02 +05:30
end
class ProjectHook < Hook
2018-03-27 19:54:05 +05:30
expose :project_id, :issues_events, :confidential_issues_events
2018-04-05 14:03:07 +05:30
expose :note_events, :confidential_note_events, :pipeline_events, :wiki_page_events
2017-09-10 17:25:29 +05:30
expose :job_events
2018-11-20 20:47:30 +05:30
expose :push_events_branch_filter
2014-09-02 18:07:02 +05:30
end
2016-08-24 12:49:21 +05:30
class SharedGroup < Grape::Entity
expose :group_id
expose :group_name do |group_link, options|
group_link.group.name
end
2019-03-02 22:35:43 +05:30
expose :group_full_path do |group_link, options|
group_link.group.full_path
end
2016-08-24 12:49:21 +05:30
expose :group_access, as: :group_access_level
2018-11-20 20:47:30 +05:30
expose :expires_at
2016-08-24 12:49:21 +05:30
end
2018-03-17 18:26:18 +05:30
class ProjectIdentity < Grape::Entity
expose :id, :description
2014-09-02 18:07:02 +05:30
expose :name, :name_with_namespace
expose :path, :path_with_namespace
2018-03-17 18:26:18 +05:30
expose :created_at
end
2018-03-27 19:54:05 +05:30
class ProjectExportStatus < ProjectIdentity
include ::API::Helpers::RelatedResourcesHelpers
expose :export_status
expose :_links, if: lambda { |project, _options| project.export_status == :finished } do
expose :api_url do |project|
expose_url(api_v4_projects_export_download_path(id: project.id))
end
expose :web_url do |project|
Gitlab::Routing.url_helpers.download_export_project_url(project)
end
end
end
2020-01-01 13:55:28 +05:30
class RemoteMirror < Grape::Entity
expose :id
expose :enabled
expose :safe_url, as: :url
expose :update_status
expose :last_update_at
expose :last_update_started_at
expose :last_successful_update_at
expose :last_error
expose :only_protected_branches
end
2018-03-27 19:54:05 +05:30
class ProjectImportStatus < ProjectIdentity
expose :import_status
# TODO: Use `expose_nil` once we upgrade the grape-entity gem
2019-02-15 15:39:39 +05:30
expose :import_error, if: lambda { |project, _ops| project.import_state&.last_error } do |project|
project.import_state.last_error
end
2018-03-27 19:54:05 +05:30
end
2018-03-17 18:26:18 +05:30
class BasicProjectDetails < ProjectIdentity
include ::API::ProjectsRelationBuilder
2019-03-13 22:55:13 +05:30
expose :default_branch, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) }
2018-03-17 18:26:18 +05:30
# Avoids an N+1 query: https://github.com/mbleigh/acts-as-taggable-on/issues/91#issuecomment-168273770
expose :tag_list do |project|
# project.tags.order(:name).pluck(:name) is the most suitable option
# to avoid loading all the ActiveRecord objects but, if we use it here
# it override the preloaded associations and makes a query
# (fixed in https://github.com/rails/rails/pull/25976).
project.tags.map(&:name).sort
end
2018-12-13 13:39:08 +05:30
2018-11-08 19:23:39 +05:30
expose :ssh_url_to_repo, :http_url_to_repo, :web_url, :readme_url
2018-12-13 13:39:08 +05:30
expose :license_url, if: :license do |project|
license = project.repository.license_blob
if license
Gitlab::Routing.url_helpers.project_blob_url(project, File.join(project.default_branch, license.path))
end
end
expose :license, with: 'API::Entities::LicenseBasic', if: :license do |project|
project.repository.license
end
2018-03-17 18:26:18 +05:30
expose :avatar_url do |project, options|
project.avatar_url(only_path: false)
end
2018-12-13 13:39:08 +05:30
2017-09-10 17:25:29 +05:30
expose :star_count, :forks_count
2018-03-17 18:26:18 +05:30
expose :last_activity_at
2018-11-18 11:00:15 +05:30
expose :namespace, using: 'API::Entities::NamespaceBasic'
2018-03-27 19:54:05 +05:30
expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2019-03-02 22:35:43 +05:30
def self.preload_relation(projects_relation, options = {})
2018-11-08 19:23:39 +05:30
# Preloading tags, should be done with using only `:tags`,
# as `:tags` are defined as: `has_many :tags, through: :taggings`
# N+1 is solved then by using `subject.tags.map(&:name)`
2019-12-04 20:38:33 +05:30
# MR describing the solution: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20555
2018-03-17 18:26:18 +05:30
projects_relation.preload(:project_feature, :route)
2018-11-08 19:23:39 +05:30
.preload(:import_state, :tags)
2019-09-30 21:07:59 +05:30
.preload(:auto_devops)
2018-11-08 19:23:39 +05:30
.preload(namespace: [:route, :owner])
2018-03-17 18:26:18 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2017-09-10 17:25:29 +05:30
end
2018-03-17 18:26:18 +05:30
class Project < BasicProjectDetails
2017-09-10 17:25:29 +05:30
include ::API::Helpers::RelatedResourcesHelpers
expose :_links do
expose :self do |project|
expose_url(api_v4_projects_path(id: project.id))
end
2018-10-15 14:42:47 +05:30
expose :issues, if: -> (project, options) { issues_available?(project, options) } do |project|
2017-09-10 17:25:29 +05:30
expose_url(api_v4_projects_issues_path(id: project.id))
end
2018-10-15 14:42:47 +05:30
expose :merge_requests, if: -> (project, options) { mrs_available?(project, options) } do |project|
2017-09-10 17:25:29 +05:30
expose_url(api_v4_projects_merge_requests_path(id: project.id))
end
expose :repo_branches do |project|
expose_url(api_v4_projects_repository_branches_path(id: project.id))
end
expose :labels do |project|
expose_url(api_v4_projects_labels_path(id: project.id))
end
expose :events do |project|
expose_url(api_v4_projects_events_path(id: project.id))
end
expose :members do |project|
expose_url(api_v4_projects_members_path(id: project.id))
end
end
2019-09-04 21:01:54 +05:30
expose :empty_repo?, as: :empty_repo
2017-09-10 17:25:29 +05:30
expose :archived?, as: :archived
expose :visibility
expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group }
2018-03-17 18:26:18 +05:30
expose :resolve_outdated_diff_discussions
2016-09-29 09:46:39 +05:30
expose :container_registry_enabled
# Expose old field names with the new permissions methods to keep API compatible
2019-09-30 21:07:59 +05:30
# TODO: remove in API v5, replaced by *_access_level
2017-08-17 22:00:37 +05:30
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]) }
2016-09-29 09:46:39 +05:30
2019-09-30 21:07:59 +05:30
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) }
2015-12-23 02:04:40 +05:30
expose :shared_runners_enabled
2016-09-29 09:46:39 +05:30
expose :lfs_enabled?, as: :lfs_enabled
2015-04-26 12:48:37 +05:30
expose :creator_id
2019-12-04 20:38:33 +05:30
expose :forked_from_project, using: Entities::BasicProjectDetails, if: ->(project, options) do
project.forked? && Ability.allowed?(options[:current_user], :read_project, project.forked_from_project)
end
2017-09-10 17:25:29 +05:30
expose :import_status
2019-02-15 15:39:39 +05:30
expose :import_error, if: lambda { |_project, options| options[:user_can_admin_project] } do |project|
project.import_state&.last_error
end
2018-03-17 18:26:18 +05:30
2017-09-10 17:25:29 +05:30
expose :open_issues_count, if: lambda { |project, options| project.feature_available?(:issues, options[:current_user]) }
expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] }
2019-09-04 21:01:54 +05:30
expose :ci_default_git_depth
2017-08-17 22:00:37 +05:30
expose :public_builds, as: :public_jobs
2019-09-30 21:07:59 +05:30
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 :auto_cancel_pending_pipelines
expose :build_coverage_regex
2019-03-13 22:55:13 +05:30
expose :ci_config_path, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) }
2016-08-24 12:49:21 +05:30
expose :shared_with_groups do |project, options|
2018-03-17 18:26:18 +05:30
SharedGroup.represent(project.project_group_links, options)
2016-08-24 12:49:21 +05:30
end
2017-08-17 22:00:37 +05:30
expose :only_allow_merge_if_pipeline_succeeds
2016-09-29 09:46:39 +05:30
expose :request_access_enabled
2017-08-17 22:00:37 +05:30
expose :only_allow_merge_if_all_discussions_are_resolved
2019-12-26 22:10:19 +05:30
expose :remove_source_branch_after_merge
2017-09-10 17:25:29 +05:30
expose :printing_merge_request_link_enabled
2018-05-09 12:01:36 +05:30
expose :merge_method
2019-03-13 22:55:13 +05:30
expose :statistics, using: 'API::Entities::ProjectStatistics', if: -> (project, options) {
2019-07-07 11:18:12 +05:30
options[:statistics] && Ability.allowed?(options[:current_user], :read_statistics, project)
2019-03-13 22:55:13 +05:30
}
2019-09-30 21:07:59 +05:30
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
2018-03-17 18:26:18 +05:30
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2019-03-02 22:35:43 +05:30
def self.preload_relation(projects_relation, options = {})
2018-11-08 19:23:39 +05:30
# Preloading tags, should be done with using only `:tags`,
# as `:tags` are defined as: `has_many :tags, through: :taggings`
# N+1 is solved then by using `subject.tags.map(&:name)`
2019-12-04 20:38:33 +05:30
# MR describing the solution: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20555
2018-03-17 18:26:18 +05:30
super(projects_relation).preload(:group)
2019-09-04 21:01:54 +05:30
.preload(:ci_cd_settings)
2019-09-30 21:07:59 +05:30
.preload(:auto_devops)
2019-03-02 22:35:43 +05:30
.preload(project_group_links: { group: :route },
2018-03-17 18:26:18 +05:30
fork_network: :root_project,
2018-12-13 13:39:08 +05:30
fork_network_member: :forked_from_project,
2018-11-08 19:23:39 +05:30
forked_from_project: [:route, :forks, :tags, namespace: :route])
2018-03-17 18:26:18 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2018-03-17 18:26:18 +05:30
def self.forks_counting_projects(projects_relation)
projects_relation + projects_relation.map(&:forked_from_project).compact
end
2017-08-17 22:00:37 +05:30
end
class ProjectStatistics < Grape::Entity
expose :commit_count
expose :storage_size
expose :repository_size
2019-09-04 21:01:54 +05:30
expose :wiki_size
2017-08-17 22:00:37 +05:30
expose :lfs_objects_size
expose :build_artifacts_size, as: :job_artifacts_size
2014-09-02 18:07:02 +05:30
end
2019-07-07 11:18:12 +05:30
class ProjectDailyFetches < Grape::Entity
expose :fetch_count, as: :count
expose :date
end
class ProjectDailyStatistics < Grape::Entity
expose :fetches do
expose :total_fetch_count, as: :total
expose :fetches, as: :days, using: ProjectDailyFetches
end
end
2018-03-17 18:26:18 +05:30
class Member < Grape::Entity
expose :user, merge: true, using: UserBasic
expose :access_level
expose :expires_at
2016-09-13 17:45:13 +05:30
end
2018-03-17 18:26:18 +05:30
class AccessRequester < Grape::Entity
expose :user, merge: true, using: UserBasic
expose :requested_at
2014-09-02 18:07:02 +05:30
end
2018-10-15 14:42:47 +05:30
class BasicGroupDetails < Grape::Entity
expose :id
expose :web_url
expose :name
end
class Group < BasicGroupDetails
expose :path, :description, :visibility
2019-12-21 20:55:43 +05:30
expose :share_with_group_lock
expose :require_two_factor_authentication
expose :two_factor_grace_period
expose :project_creation_level_str, as: :project_creation_level
expose :auto_devops_enabled
expose :subgroup_creation_level_str, as: :subgroup_creation_level
expose :emails_disabled
2016-09-29 09:46:39 +05:30
expose :lfs_enabled?, as: :lfs_enabled
2018-03-17 18:26:18 +05:30
expose :avatar_url do |group, options|
group.avatar_url(only_path: false)
2017-09-10 17:25:29 +05:30
end
2016-09-29 09:46:39 +05:30
expose :request_access_enabled
2017-08-17 22:00:37 +05:30
expose :full_name, :full_path
2019-10-12 21:52:04 +05:30
expose :parent_id
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes
2017-08-17 22:00:37 +05:30
expose :statistics, if: :statistics do
with_options format_with: -> (value) { value.to_i } do
expose :storage_size
expose :repository_size
2019-09-04 21:01:54 +05:30
expose :wiki_size
2017-08-17 22:00:37 +05:30
expose :lfs_objects_size
expose :build_artifacts_size, as: :job_artifacts_size
end
end
2014-09-02 18:07:02 +05:30
end
class GroupDetail < Group
2019-12-04 20:38:33 +05:30
expose :runners_token, if: lambda { |group, options| options[:user_can_admin_group] }
2018-03-17 18:26:18 +05:30
expose :projects, using: Entities::Project do |group, options|
2019-03-02 22:35:43 +05:30
projects = GroupProjectsFinder.new(
2018-03-17 18:26:18 +05:30
group: group,
current_user: options[:current_user],
2020-01-01 13:55:28 +05:30
options: { only_owned: true, limit: projects_limit }
2018-03-17 18:26:18 +05:30
).execute
2019-03-02 22:35:43 +05:30
Entities::Project.prepare_relation(projects)
2018-03-17 18:26:18 +05:30
end
expose :shared_projects, using: Entities::Project do |group, options|
2019-03-02 22:35:43 +05:30
projects = GroupProjectsFinder.new(
2018-03-17 18:26:18 +05:30
group: group,
current_user: options[:current_user],
2020-01-01 13:55:28 +05:30
options: { only_shared: true, limit: projects_limit }
2018-03-17 18:26:18 +05:30
).execute
2019-03-02 22:35:43 +05:30
Entities::Project.prepare_relation(projects)
2018-03-17 18:26:18 +05:30
end
2020-01-01 13:55:28 +05:30
def projects_limit
if ::Feature.enabled?(:limit_projects_in_groups_api, default_enabled: true)
GroupProjectsFinder::DEFAULT_PROJECTS_LIMIT
else
nil
end
end
2014-09-02 18:07:02 +05:30
end
2018-10-15 14:42:47 +05:30
class DiffRefs < Grape::Entity
expose :base_sha, :head_sha, :start_sha
end
2018-03-17 18:26:18 +05:30
class Commit < Grape::Entity
2019-07-07 11:18:12 +05:30
expose :id, :short_id, :created_at
2017-08-17 22:00:37 +05:30
expose :parent_ids
2019-07-07 11:18:12 +05:30
expose :full_title, as: :title
2017-08-17 22:00:37 +05:30
expose :safe_message, as: :message
expose :author_name, :author_email, :authored_date
expose :committer_name, :committer_email, :committed_date
end
2018-03-17 18:26:18 +05:30
class CommitStats < Grape::Entity
2017-08-17 22:00:37 +05:30
expose :additions, :deletions, :total
end
2018-11-08 19:23:39 +05:30
class CommitWithStats < Commit
expose :stats, using: Entities::CommitStats
end
2018-03-17 18:26:18 +05:30
class CommitDetail < Commit
expose :stats, using: Entities::CommitStats, if: :stats
2017-08-17 22:00:37 +05:30
expose :status
2018-03-17 18:26:18 +05:30
expose :project_id
2020-02-01 01:16:34 +05:30
expose :last_pipeline do |commit, options|
pipeline = commit.last_pipeline if can_read_pipeline?
::API::Entities::PipelineBasic.represent(pipeline, options)
end
private
def can_read_pipeline?
Ability.allowed?(options[:current_user], :read_pipeline, object.last_pipeline)
end
2017-08-17 22:00:37 +05:30
end
2019-07-07 11:18:12 +05:30
class CommitSignature < Grape::Entity
expose :gpg_key_id
expose :gpg_key_primary_keyid, :gpg_key_user_name, :gpg_key_user_email
expose :verification_status
expose :gpg_key_subkey_id
end
2018-03-27 19:54:05 +05:30
class BasicRef < Grape::Entity
expose :type, :name
end
2018-03-17 18:26:18 +05:30
class Branch < Grape::Entity
2014-09-02 18:07:02 +05:30
expose :name
2018-03-17 18:26:18 +05:30
expose :commit, using: Entities::Commit do |repo_branch, options|
2016-11-24 13:41:30 +05:30
options[:project].repository.commit(repo_branch.dereferenced_target)
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
expose :merged do |repo_branch, options|
2018-03-17 18:26:18 +05:30
if options[:merged_branch_names]
options[:merged_branch_names].include?(repo_branch.name)
else
options[:project].repository.merged_to_root_ref?(repo_branch)
end
2017-08-17 22:00:37 +05:30
end
2016-08-24 12:49:21 +05:30
expose :protected do |repo_branch, options|
2017-09-10 17:25:29 +05:30
::ProtectedBranch.protected?(options[:project], repo_branch.name)
2016-08-24 12:49:21 +05:30
end
expose :developers_can_push do |repo_branch, options|
2019-12-26 22:10:19 +05:30
::ProtectedBranch.developers_can?(:push, repo_branch.name, protected_refs: options[:project].protected_branches)
2016-08-24 12:49:21 +05:30
end
expose :developers_can_merge do |repo_branch, options|
2019-12-26 22:10:19 +05:30
::ProtectedBranch.developers_can?(:merge, repo_branch.name, protected_refs: options[:project].protected_branches)
2014-09-02 18:07:02 +05:30
end
2018-11-08 19:23:39 +05:30
expose :can_push do |repo_branch, options|
Gitlab::UserAccess.new(options[:current_user], project: options[:project]).can_push_to_branch?(repo_branch.name)
end
2018-11-20 20:47:30 +05:30
expose :default do |repo_branch, options|
options[:project].default_branch == repo_branch.name
end
2014-09-02 18:07:02 +05:30
end
2018-03-17 18:26:18 +05:30
class TreeObject < Grape::Entity
2017-08-17 22:00:37 +05:30
expose :id, :name, :type, :path
2014-09-02 18:07:02 +05:30
expose :mode do |obj, options|
2017-08-17 22:00:37 +05:30
filemode = obj.mode
2014-09-02 18:07:02 +05:30
filemode = "0" + filemode if filemode.length < 6
filemode
end
end
2018-03-17 18:26:18 +05:30
class Snippet < Grape::Entity
2018-11-08 19:23:39 +05:30
expose :id, :title, :file_name, :description, :visibility
2017-08-17 22:00:37 +05:30
expose :author, using: Entities::UserBasic
expose :updated_at, :created_at
2018-03-17 18:26:18 +05:30
expose :project_id
expose :web_url do |snippet|
2017-08-17 22:00:37 +05:30
Gitlab::UrlBuilder.build(snippet)
end
2014-09-02 18:07:02 +05:30
end
2018-03-17 18:26:18 +05:30
class ProjectSnippet < Snippet
end
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
class PersonalSnippet < Snippet
2017-08-17 22:00:37 +05:30
expose :raw_url do |snippet|
2020-01-01 13:55:28 +05:30
Gitlab::UrlBuilder.build(snippet, raw: true)
2017-08-17 22:00:37 +05:30
end
2014-09-02 18:07:02 +05:30
end
2019-09-30 21:07:59 +05:30
class IssuableEntity < Grape::Entity
2014-09-02 18:07:02 +05:30
expose :id, :iid
2017-09-10 17:25:29 +05:30
expose(:project_id) { |entity| entity&.project.try(:id) }
2014-09-02 18:07:02 +05:30
expose :title, :description
expose :state, :created_at, :updated_at
2019-07-07 11:18:12 +05:30
# Avoids an N+1 query when metadata is included
def issuable_metadata(subject, options, method, args = nil)
cached_subject = options.dig(:issuable_metadata, subject.id)
(cached_subject || subject).public_send(method, *args) # rubocop: disable GitlabSecurity/PublicSend
end
2014-09-02 18:07:02 +05:30
end
2018-03-17 18:26:18 +05:30
class Diff < Grape::Entity
expose :old_path, :new_path, :a_mode, :b_mode
2017-09-10 17:25:29 +05:30
expose :new_file?, as: :new_file
expose :renamed_file?, as: :renamed_file
expose :deleted_file?, as: :deleted_file
2018-03-17 18:26:18 +05:30
expose :json_safe_diff, as: :diff
2015-04-26 12:48:37 +05:30
end
2017-09-10 17:25:29 +05:30
class ProtectedRefAccess < Grape::Entity
expose :access_level
expose :access_level_description do |protected_ref_access|
protected_ref_access.humanize
end
end
class ProtectedBranch < Grape::Entity
expose :name
expose :push_access_levels, using: Entities::ProtectedRefAccess
expose :merge_access_levels, using: Entities::ProtectedRefAccess
end
2018-11-20 20:47:30 +05:30
class ProtectedTag < Grape::Entity
expose :name
expose :create_access_levels, using: Entities::ProtectedRefAccess
end
2017-09-10 17:25:29 +05:30
class Milestone < Grape::Entity
expose :id, :iid
expose :project_id, if: -> (entity, options) { entity&.project_id }
expose :group_id, if: -> (entity, options) { entity&.group_id }
expose :title, :description
expose :state, :created_at, :updated_at
2014-09-02 18:07:02 +05:30
expose :due_date
2017-08-17 22:00:37 +05:30
expose :start_date
2018-11-08 19:23:39 +05:30
expose :web_url do |milestone, _options|
Gitlab::UrlBuilder.build(milestone)
end
2014-09-02 18:07:02 +05:30
end
2019-09-30 21:07:59 +05:30
class IssueBasic < IssuableEntity
2018-03-17 18:26:18 +05:30
expose :closed_at
2018-05-09 12:01:36 +05:30
expose :closed_by, using: Entities::UserBasic
2019-09-04 21:01:54 +05:30
expose :labels do |issue, options|
if options[:with_labels_details]
::API::Entities::LabelBasic.represent(issue.labels.sort_by(&:title))
else
issue.labels.map(&:title).sort
end
2018-03-17 18:26:18 +05:30
end
2019-09-04 21:01:54 +05:30
2014-09-02 18:07:02 +05:30
expose :milestone, using: Entities::Milestone
2017-08-17 22:00:37 +05:30
expose :assignees, :author, using: Entities::UserBasic
2019-07-07 11:18:12 +05:30
expose :assignee, using: ::API::Entities::UserBasic do |issue|
2017-08-17 22:00:37 +05:30
issue.assignees.first
2016-06-02 11:05:42 +05:30
end
2017-08-17 22:00:37 +05:30
2019-07-07 11:18:12 +05:30
expose(:user_notes_count) { |issue, options| issuable_metadata(issue, options, :user_notes_count) }
expose(:merge_requests_count) { |issue, options| issuable_metadata(issue, options, :merge_requests_count, options[:current_user]) }
expose(:upvotes) { |issue, options| issuable_metadata(issue, options, :upvotes) }
expose(:downvotes) { |issue, options| issuable_metadata(issue, options, :downvotes) }
2016-08-24 12:49:21 +05:30
expose :due_date
2016-09-29 09:46:39 +05:30
expose :confidential
2018-03-17 18:26:18 +05:30
expose :discussion_locked
2016-09-29 09:46:39 +05:30
2019-07-07 11:18:12 +05:30
expose :web_url do |issue|
2016-09-29 09:46:39 +05:30
Gitlab::UrlBuilder.build(issue)
end
2018-03-17 18:26:18 +05:30
expose :time_stats, using: 'API::Entities::IssuableTimeStats' do |issue|
issue
end
2019-09-04 21:01:54 +05:30
expose :task_completion_status
end
2017-08-17 22:00:37 +05:30
class Issue < IssueBasic
2017-09-10 17:25:29 +05:30
include ::API::Helpers::RelatedResourcesHelpers
2019-09-04 21:01:54 +05:30
expose(:has_tasks) do |issue, _|
!issue.task_list_items.empty?
end
expose :task_status, if: -> (issue, _) do
!issue.task_list_items.empty?
end
2017-09-10 17:25:29 +05:30
expose :_links do
expose :self do |issue|
expose_url(api_v4_project_issue_path(id: issue.project_id, issue_iid: issue.iid))
end
expose :notes do |issue|
expose_url(api_v4_projects_issues_notes_path(id: issue.project_id, noteable_id: issue.iid))
end
expose :award_emoji do |issue|
expose_url(api_v4_projects_issues_award_emoji_path(id: issue.project_id, issue_iid: issue.iid))
end
expose :project do |issue|
expose_url(api_v4_projects_path(id: issue.project_id))
end
end
2019-10-12 21:52:04 +05:30
# Calculating the value of subscribed field triggers Markdown
# processing. We can't do that for multiple issues / merge
# requests in a single API request.
expose :subscribed, if: -> (_, options) { options.fetch(:include_subscribed, true) } do |issue, options|
2017-08-17 22:00:37 +05:30
issue.subscribed?(options[:current_user], options[:project] || issue.project)
end
2020-01-01 13:55:28 +05:30
expose :moved_to_id
2017-08-17 22:00:37 +05:30
end
class IssuableTimeStats < Grape::Entity
2018-03-17 18:26:18 +05:30
format_with(:time_tracking_formatter) do |time_spent|
Gitlab::TimeTrackingFormatter.output(time_spent)
end
2017-08-17 22:00:37 +05:30
expose :time_estimate
expose :total_time_spent
expose :human_time_estimate
2018-03-17 18:26:18 +05:30
with_options(format_with: :time_tracking_formatter) do
expose :total_time_spent, as: :human_total_time_spent
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2018-03-17 18:26:18 +05:30
def total_time_spent
# Avoids an N+1 query since timelogs are preloaded
object.timelogs.map(&:time_spent).sum
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
end
class ExternalIssue < Grape::Entity
expose :title
expose :id
2014-09-02 18:07:02 +05:30
end
2018-03-27 19:54:05 +05:30
class PipelineBasic < Grape::Entity
expose :id, :sha, :ref, :status
2019-12-21 20:55:43 +05:30
expose :created_at, :updated_at
2018-11-18 11:00:15 +05:30
expose :web_url do |pipeline, _options|
Gitlab::Routing.url_helpers.project_pipeline_url(pipeline.project, pipeline)
end
2018-03-27 19:54:05 +05:30
end
2019-09-30 21:07:59 +05:30
class MergeRequestSimple < IssuableEntity
2017-09-10 17:25:29 +05:30
expose :title
expose :web_url do |merge_request, options|
Gitlab::UrlBuilder.build(merge_request)
end
end
2019-09-30 21:07:59 +05:30
class MergeRequestBasic < IssuableEntity
2018-12-13 13:39:08 +05:30
expose :merged_by, using: Entities::UserBasic do |merge_request, _options|
merge_request.metrics&.merged_by
end
expose :merged_at do |merge_request, _options|
merge_request.metrics&.merged_at
end
expose :closed_by, using: Entities::UserBasic do |merge_request, _options|
merge_request.metrics&.latest_closed_by
end
expose :closed_at do |merge_request, _options|
merge_request.metrics&.latest_closed_at
end
2018-11-08 19:23:39 +05:30
expose :title_html, if: -> (_, options) { options[:render_html] } do |entity|
MarkupHelper.markdown_field(entity, :title)
end
expose :description_html, if: -> (_, options) { options[:render_html] } do |entity|
MarkupHelper.markdown_field(entity, :description)
end
2015-11-26 14:37:03 +05:30
expose :target_branch, :source_branch
2019-07-07 11:18:12 +05:30
expose(:user_notes_count) { |merge_request, options| issuable_metadata(merge_request, options, :user_notes_count) }
expose(:upvotes) { |merge_request, options| issuable_metadata(merge_request, options, :upvotes) }
expose(:downvotes) { |merge_request, options| issuable_metadata(merge_request, options, :downvotes) }
2019-07-31 22:56:46 +05:30
expose :assignee, using: ::API::Entities::UserBasic do |merge_request|
merge_request.assignee
end
expose :author, :assignees, using: Entities::UserBasic
2014-09-02 18:07:02 +05:30
expose :source_project_id, :target_project_id
2019-07-07 11:18:12 +05:30
expose :labels do |merge_request|
2017-09-10 17:25:29 +05:30
# Avoids an N+1 query since labels are preloaded
merge_request.labels.map(&:title).sort
end
2015-09-11 14:41:01 +05:30
expose :work_in_progress?, as: :work_in_progress
2014-09-02 18:07:02 +05:30
expose :milestone, using: Entities::Milestone
2017-08-17 22:00:37 +05:30
expose :merge_when_pipeline_succeeds
2018-03-17 18:26:18 +05:30
# Ideally we should deprecate `MergeRequest#merge_status` exposure and
# use `MergeRequest#mergeable?` instead (boolean).
2019-12-04 20:38:33 +05:30
# See https://gitlab.com/gitlab-org/gitlab-foss/issues/42344 for more
2018-03-17 18:26:18 +05:30
# information.
expose :merge_status do |merge_request|
2019-09-30 21:07:59 +05:30
merge_request.check_mergeability
2018-03-17 18:26:18 +05:30
merge_request.merge_status
end
2016-09-29 09:46:39 +05:30
expose :diff_head_sha, as: :sha
expose :merge_commit_sha
2019-12-26 22:10:19 +05:30
expose :squash_commit_sha
2018-03-17 18:26:18 +05:30
expose :discussion_locked
2016-08-24 12:49:21 +05:30
expose :should_remove_source_branch?, as: :should_remove_source_branch
expose :force_remove_source_branch?, as: :force_remove_source_branch
2018-11-08 19:23:39 +05:30
expose :allow_collaboration, if: -> (merge_request, _) { merge_request.for_fork? }
# Deprecated
expose :allow_collaboration, as: :allow_maintainer_to_push, if: -> (merge_request, _) { merge_request.for_fork? }
2016-09-29 09:46:39 +05:30
2019-07-07 11:18:12 +05:30
expose :reference do |merge_request, options|
merge_request.to_reference(options[:project])
end
expose :web_url do |merge_request|
2016-09-29 09:46:39 +05:30
Gitlab::UrlBuilder.build(merge_request)
end
2018-03-17 18:26:18 +05:30
expose :time_stats, using: 'API::Entities::IssuableTimeStats' do |merge_request|
merge_request
end
2018-11-08 19:23:39 +05:30
expose :squash
2019-09-04 21:01:54 +05:30
expose :task_completion_status
2019-12-26 22:10:19 +05:30
expose :cannot_be_merged?, as: :has_conflicts
expose :mergeable_discussions_state?, as: :blocking_discussions_resolved
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
class MergeRequest < MergeRequestBasic
2019-12-21 20:55:43 +05:30
expose :subscribed, if: -> (_, options) { options.fetch(:include_subscribed, true) } do |merge_request, options|
2017-08-17 22:00:37 +05:30
merge_request.subscribed?(options[:current_user], options[:project])
end
2018-03-17 18:26:18 +05:30
expose :changes_count do |merge_request, _options|
merge_request.merge_request_diff.real_size
end
2018-03-27 19:54:05 +05:30
expose :latest_build_started_at, if: -> (_, options) { build_available?(options) } do |merge_request, _options|
merge_request.metrics&.latest_build_started_at
end
expose :latest_build_finished_at, if: -> (_, options) { build_available?(options) } do |merge_request, _options|
merge_request.metrics&.latest_build_finished_at
end
expose :first_deployed_to_production_at, if: -> (_, options) { build_available?(options) } do |merge_request, _options|
merge_request.metrics&.first_deployed_to_production_at
end
expose :pipeline, using: Entities::PipelineBasic, if: -> (_, options) { build_available?(options) } do |merge_request, _options|
merge_request.metrics&.pipeline
end
2019-07-07 11:18:12 +05:30
expose :head_pipeline, using: 'API::Entities::Pipeline', if: -> (_, options) do
Ability.allowed?(options[:current_user], :read_pipeline, options[:project])
end
2018-10-15 14:42:47 +05:30
expose :diff_refs, using: Entities::DiffRefs
2019-02-15 15:39:39 +05:30
# Allow the status of a rebase to be determined
expose :merge_error
expose :rebase_in_progress?, as: :rebase_in_progress, if: -> (_, options) { options[:include_rebase_in_progress] }
2018-11-20 20:47:30 +05:30
expose :diverged_commits_count, as: :diverged_commits_count, if: -> (_, options) { options[:include_diverged_commits_count] }
2018-03-27 19:54:05 +05:30
def build_available?(options)
options[:project]&.feature_available?(:builds, options[:current_user])
end
2019-07-07 11:18:12 +05:30
expose :user do
expose :can_merge do |merge_request, options|
merge_request.can_be_merged_by?(options[:current_user])
end
end
2017-08-17 22:00:37 +05:30
end
2015-04-26 12:48:37 +05:30
class MergeRequestChanges < MergeRequest
2018-03-17 18:26:18 +05:30
expose :diffs, as: :changes, using: Entities::Diff do |compare, _|
2017-09-10 17:25:29 +05:30
compare.raw_diffs(limits: false).to_a
2015-04-26 12:48:37 +05:30
end
end
2016-09-29 09:46:39 +05:30
class MergeRequestDiff < Grape::Entity
expose :id, :head_commit_sha, :base_commit_sha, :start_commit_sha,
:created_at, :merge_request_id, :state, :real_size
end
class MergeRequestDiffFull < MergeRequestDiff
2018-03-17 18:26:18 +05:30
expose :commits, using: Entities::Commit
2016-09-29 09:46:39 +05:30
2018-03-17 18:26:18 +05:30
expose :diffs, using: Entities::Diff do |compare, _|
2017-09-10 17:25:29 +05:30
compare.raw_diffs(limits: false).to_a
2016-09-29 09:46:39 +05:30
end
end
2014-09-02 18:07:02 +05:30
class SSHKey < Grape::Entity
2018-03-17 18:26:18 +05:30
expose :id, :title, :key, :created_at
2014-09-02 18:07:02 +05:30
end
2015-09-25 12:07:36 +05:30
class SSHKeyWithUser < SSHKey
2017-01-15 13:20:01 +05:30
expose :user, using: Entities::UserPublic
2015-09-25 12:07:36 +05:30
end
2018-03-17 18:26:18 +05:30
class DeployKeysProject < Grape::Entity
expose :deploy_key, merge: true, using: Entities::SSHKey
expose :can_push
end
class GPGKey < Grape::Entity
expose :id, :key, :created_at
end
2018-10-15 14:42:47 +05:30
class DiffPosition < Grape::Entity
expose :base_sha, :start_sha, :head_sha, :old_path, :new_path,
:position_type
end
2014-09-02 18:07:02 +05:30
class Note < Grape::Entity
2017-09-10 17:25:29 +05:30
# Only Issue and MergeRequest have iid
NOTEABLE_TYPES_WITH_IID = %w(Issue MergeRequest).freeze
2014-09-02 18:07:02 +05:30
expose :id
2018-03-27 19:54:05 +05:30
expose :type
2014-09-02 18:07:02 +05:30
expose :note, as: :body
expose :attachment_identifier, as: :attachment
expose :author, using: Entities::UserBasic
2016-06-02 11:05:42 +05:30
expose :created_at, :updated_at
2015-09-11 14:41:01 +05:30
expose :system?, as: :system
2015-12-23 02:04:40 +05:30
expose :noteable_id, :noteable_type
2017-09-10 17:25:29 +05:30
2018-11-18 11:00:15 +05:30
expose :position, if: ->(note, options) { note.is_a?(DiffNote) } do |note|
2018-10-15 14:42:47 +05:30
note.position.to_h
end
expose :resolvable?, as: :resolvable
expose :resolved?, as: :resolved, if: ->(note, options) { note.resolvable? }
expose :resolved_by, using: Entities::UserBasic, if: ->(note, options) { note.resolvable? }
2017-09-10 17:25:29 +05:30
# Avoid N+1 queries as much as possible
expose(:noteable_iid) { |note| note.noteable.iid if NOTEABLE_TYPES_WITH_IID.include?(note.noteable_type) }
2014-09-02 18:07:02 +05:30
end
2018-03-27 19:54:05 +05:30
class Discussion < Grape::Entity
expose :id
expose :individual_note?, as: :individual_note
expose :notes, using: Entities::Note
end
2018-11-08 19:23:39 +05:30
class Avatar < Grape::Entity
expose :avatar_url do |avatarable, options|
avatarable.avatar_url(only_path: false, size: options[:size])
end
end
2016-06-22 15:30:34 +05:30
class AwardEmoji < Grape::Entity
expose :id
expose :name
expose :user, using: Entities::UserBasic
expose :created_at, :updated_at
expose :awardable_id, :awardable_type
end
2014-09-02 18:07:02 +05:30
class MRNote < Grape::Entity
expose :note
expose :author, using: Entities::UserBasic
end
2015-04-26 12:48:37 +05:30
class CommitNote < Grape::Entity
expose :note
2016-08-24 12:49:21 +05:30
expose(:path) { |note| note.diff_file.try(:file_path) if note.diff_note? }
expose(:line) { |note| note.diff_line.try(:new_line) if note.diff_note? }
expose(:line_type) { |note| note.diff_line.try(:type) if note.diff_note? }
2015-04-26 12:48:37 +05:30
expose :author, using: Entities::UserBasic
2015-09-25 12:07:36 +05:30
expose :created_at
2015-04-26 12:48:37 +05:30
end
2015-10-24 18:46:33 +05:30
class CommitStatus < Grape::Entity
expose :id, :sha, :ref, :status, :name, :target_url, :description,
2017-08-17 22:00:37 +05:30
:created_at, :started_at, :finished_at, :allow_failure, :coverage
2015-10-24 18:46:33 +05:30
expose :author, using: Entities::UserBasic
end
2017-09-10 17:25:29 +05:30
class PushEventPayload < Grape::Entity
2019-12-21 20:55:43 +05:30
expose :commit_count, :action, :ref_type, :commit_from, :commit_to, :ref,
:commit_title, :ref_count
2017-09-10 17:25:29 +05:30
end
2014-09-02 18:07:02 +05:30
class Event < Grape::Entity
2018-03-17 18:26:18 +05:30
expose :project_id, :action_name
2017-09-10 17:25:29 +05:30
expose :target_id, :target_iid, :target_type, :author_id
expose :target_title
2014-09-02 18:07:02 +05:30
expose :created_at
2015-12-23 02:04:40 +05:30
expose :note, using: Entities::Note, if: ->(event, options) { event.note? }
expose :author, using: Entities::UserBasic, if: ->(event, options) { event.author }
2015-04-26 12:48:37 +05:30
2017-09-10 17:25:29 +05:30
expose :push_event_payload,
as: :push_data,
using: PushEventPayload,
2019-09-04 21:01:54 +05:30
if: -> (event, _) { event.push_action? }
2017-09-10 17:25:29 +05:30
2015-04-26 12:48:37 +05:30
expose :author_username do |event, options|
2017-08-17 22:00:37 +05:30
event.author&.username
2015-04-26 12:48:37 +05:30
end
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
class ProjectGroupLink < Grape::Entity
2016-11-03 12:29:30 +05:30
expose :id, :project_id, :group_id, :group_access, :expires_at
2016-06-02 11:05:42 +05:30
end
2016-08-24 12:49:21 +05:30
class Todo < Grape::Entity
expose :id
2018-11-18 11:00:15 +05:30
expose :project, using: Entities::ProjectIdentity, if: -> (todo, _) { todo.project_id }
expose :group, using: 'API::Entities::NamespaceBasic', if: -> (todo, _) { todo.group_id }
2016-08-24 12:49:21 +05:30
expose :author, using: Entities::UserBasic
expose :action_name
expose :target_type
expose :target do |todo, options|
2019-07-07 11:18:12 +05:30
todo_options = options.fetch(todo.target_type, {})
todo_target_class(todo.target_type).represent(todo.target, todo_options)
2016-08-24 12:49:21 +05:30
end
expose :target_url do |todo, options|
2019-12-21 20:55:43 +05:30
todo_target_url(todo)
2016-08-24 12:49:21 +05:30
end
expose :body
expose :state
expose :created_at
2018-11-18 11:00:15 +05:30
def todo_target_class(target_type)
2019-12-04 20:38:33 +05:30
# false as second argument prevents looking up in module hierarchy
# see also https://gitlab.com/gitlab-org/gitlab-foss/issues/59719
::API::Entities.const_get(target_type, false)
2018-11-18 11:00:15 +05:30
end
2019-12-21 20:55:43 +05:30
def todo_target_url(todo)
target_type = todo.target_type.underscore
target_url = "#{todo.resource_parent.class.to_s.underscore}_#{target_type}_url"
Gitlab::Routing
.url_helpers
.public_send(target_url, todo.resource_parent, todo.target, anchor: todo_target_anchor(todo)) # rubocop:disable GitlabSecurity/PublicSend
end
def todo_target_anchor(todo)
"note_#{todo.note_id}" if todo.note_id?
end
2016-08-24 12:49:21 +05:30
end
2018-03-17 18:26:18 +05:30
class NamespaceBasic < Grape::Entity
2019-07-31 22:56:46 +05:30
expose :id, :name, :path, :kind, :full_path, :parent_id, :avatar_url
expose :web_url do |namespace|
if namespace.user?
Gitlab::Routing.url_helpers.user_url(namespace.owner)
else
namespace.web_url
end
end
2018-03-17 18:26:18 +05:30
end
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
class Namespace < NamespaceBasic
2017-09-10 17:25:29 +05:30
expose :members_count_with_descendants, if: -> (namespace, opts) { expose_members_count_with_descendants?(namespace, opts) } do |namespace, _|
namespace.users_with_descendants.count
end
def expose_members_count_with_descendants?(namespace, opts)
namespace.kind == 'group' && Ability.allowed?(opts[:current_user], :admin_group, namespace)
end
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
class MemberAccess < Grape::Entity
2015-04-26 12:48:37 +05:30
expose :access_level
2016-06-02 11:05:42 +05:30
expose :notification_level do |member, options|
if member.notification_setting
2016-09-29 09:46:39 +05:30
::NotificationSetting.levels[member.notification_setting.level]
2016-06-02 11:05:42 +05:30
end
end
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
class ProjectAccess < MemberAccess
2016-06-02 11:05:42 +05:30
end
2016-09-13 17:45:13 +05:30
class GroupAccess < MemberAccess
2014-09-02 18:07:02 +05:30
end
2016-09-29 09:46:39 +05:30
class NotificationSetting < Grape::Entity
expose :level
expose :events, if: ->(notification_setting, _) { notification_setting.custom? } do
2018-11-20 20:47:30 +05:30
::NotificationSetting.email_events.each do |event|
2016-09-29 09:46:39 +05:30
expose event
end
end
end
class GlobalNotificationSetting < NotificationSetting
expose :notification_email do |notification_setting, options|
notification_setting.user.notification_email
end
end
2015-10-24 18:46:33 +05:30
class ProjectService < Grape::Entity
expose :id, :title, :created_at, :updated_at, :active
2019-09-04 21:01:54 +05:30
expose :commit_events, :push_events, :issues_events, :confidential_issues_events
2018-03-17 18:26:18 +05:30
expose :merge_requests_events, :tag_push_events, :note_events
2018-04-05 14:03:07 +05:30
expose :confidential_note_events, :pipeline_events, :wiki_page_events
2017-09-10 17:25:29 +05:30
expose :job_events
2015-10-24 18:46:33 +05:30
# Expose serialized properties
expose :properties do |service, options|
2019-12-21 20:55:43 +05:30
# TODO: Simplify as part of https://gitlab.com/gitlab-org/gitlab/issues/29404
2019-12-04 20:38:33 +05:30
if service.data_fields_present?
service.data_fields.as_json.slice(*service.api_field_names)
else
service.properties.slice(*service.api_field_names)
end
2015-10-24 18:46:33 +05:30
end
end
2014-09-02 18:07:02 +05:30
class ProjectWithAccess < Project
expose :permissions do
expose :project_access, using: Entities::ProjectAccess do |project, options|
2018-11-08 19:23:39 +05:30
if options[:project_members]
options[:project_members].find { |member| member.source_id == project.id }
2017-09-10 17:25:29 +05:30
else
2018-03-17 18:26:18 +05:30
project.project_member(options[:current_user])
2017-09-10 17:25:29 +05:30
end
2014-09-02 18:07:02 +05:30
end
expose :group_access, using: Entities::GroupAccess do |project, options|
if project.group
2018-11-08 19:23:39 +05:30
if options[:group_members]
options[:group_members].find { |member| member.source_id == project.namespace_id }
2017-09-10 17:25:29 +05:30
else
2019-03-02 22:35:43 +05:30
project.group.highest_group_member(options[:current_user])
2017-09-10 17:25:29 +05:30
end
2014-09-02 18:07:02 +05:30
end
end
end
2018-03-17 18:26:18 +05:30
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2018-03-17 18:26:18 +05:30
def self.preload_relation(projects_relation, options = {})
relation = super(projects_relation, options)
2019-10-12 21:52:04 +05:30
project_ids = relation.select('projects.id')
namespace_ids = relation.select(:namespace_id)
2018-03-17 18:26:18 +05:30
2018-11-08 19:23:39 +05:30
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])
2018-03-17 18:26:18 +05:30
relation
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2014-09-02 18:07:02 +05:30
end
2016-11-03 12:29:30 +05:30
class LabelBasic < Grape::Entity
2019-07-07 11:18:12 +05:30
expose :id, :name, :color, :description, :text_color
2016-11-03 12:29:30 +05:30
end
class Label < LabelBasic
2019-10-12 21:52:04 +05:30
with_options if: lambda { |_, options| options[:with_counts] } do
expose :open_issues_count do |label, options|
label.open_issues_count(options[:current_user])
end
2017-08-17 22:00:37 +05:30
2019-10-12 21:52:04 +05:30
expose :closed_issues_count do |label, options|
label.closed_issues_count(options[:current_user])
end
2017-08-17 22:00:37 +05:30
2019-10-12 21:52:04 +05:30
expose :open_merge_requests_count do |label, options|
label.open_merge_requests_count(options[:current_user])
end
2017-08-17 22:00:37 +05:30
end
2019-03-02 22:35:43 +05:30
expose :subscribed do |label, options|
label.subscribed?(options[:current_user], options[:parent])
2017-08-17 22:00:37 +05:30
end
2019-03-02 22:35:43 +05:30
end
2016-06-02 11:05:42 +05:30
2019-03-02 22:35:43 +05:30
class GroupLabel < Label
end
class ProjectLabel < Label
expose :priority do |label, options|
label.priority(options[:parent])
2016-06-02 11:05:42 +05:30
end
2019-07-07 11:18:12 +05:30
expose :is_project_label do |label, options|
label.is_a?(::ProjectLabel)
end
2014-09-02 18:07:02 +05:30
end
2016-11-03 12:29:30 +05:30
class List < Grape::Entity
expose :id
expose :label, using: Entities::LabelBasic
expose :position
end
class Board < Grape::Entity
expose :id
2018-03-17 18:26:18 +05:30
expose :project, using: Entities::BasicProjectDetails
2016-11-03 12:29:30 +05:30
expose :lists, using: Entities::List do |board|
2019-09-30 21:07:59 +05:30
board.destroyable_lists
2016-11-03 12:29:30 +05:30
end
end
2014-09-02 18:07:02 +05:30
class Compare < Grape::Entity
2018-03-17 18:26:18 +05:30
expose :commit, using: Entities::Commit do |compare, options|
::Commit.decorate(compare.commits, nil).last
2014-09-02 18:07:02 +05:30
end
2018-03-17 18:26:18 +05:30
expose :commits, using: Entities::Commit do |compare, options|
::Commit.decorate(compare.commits, nil)
2014-09-02 18:07:02 +05:30
end
2018-03-17 18:26:18 +05:30
expose :diffs, using: Entities::Diff do |compare, options|
2017-09-10 17:25:29 +05:30
compare.diffs(limits: false).to_a
2014-09-02 18:07:02 +05:30
end
expose :compare_timeout do |compare, options|
2016-06-02 11:05:42 +05:30
compare.diffs.overflow?
2014-09-02 18:07:02 +05:30
end
expose :same, as: :compare_same_ref
end
class Contributor < Grape::Entity
expose :name, :email, :commits, :additions, :deletions
end
2015-04-26 12:48:37 +05:30
class BroadcastMessage < Grape::Entity
2020-01-01 13:55:28 +05:30
expose :message, :starts_at, :ends_at, :color, :font, :target_path
2015-04-26 12:48:37 +05:30
end
2015-09-11 14:41:01 +05:30
2019-12-04 20:38:33 +05:30
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
2015-09-11 14:41:01 +05:30
class ApplicationSetting < Grape::Entity
2018-11-08 19:23:39 +05:30
def self.exposed_attributes
attributes = ::ApplicationSettingsHelper.visible_attributes
attributes.delete(:performance_bar_allowed_group_path)
attributes.delete(:performance_bar_enabled)
2019-10-12 21:52:04 +05:30
attributes.delete(:allow_local_requests_from_hooks_and_services)
2018-11-08 19:23:39 +05:30
2019-09-04 21:01:54 +05:30
# let's not expose the secret key in a response
attributes.delete(:asset_proxy_secret_key)
2019-12-26 22:10:19 +05:30
attributes.delete(:eks_secret_access_key)
2019-09-04 21:01:54 +05:30
2018-11-08 19:23:39 +05:30
attributes
end
expose :id, :performance_bar_allowed_group_id
expose(*exposed_attributes)
2017-08-17 22:00:37 +05:30
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) }
2018-03-17 18:26:18 +05:30
2019-07-07 11:18:12 +05:30
expose(*::ApplicationSettingsHelper.external_authorization_service_attributes)
2018-03-17 18:26:18 +05:30
# 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
2019-10-12 21:52:04 +05:30
expose :allow_local_requests_from_web_hooks_and_services, as: :allow_local_requests_from_hooks_and_services
2015-09-11 14:41:01 +05:30
end
2015-11-26 14:37:03 +05:30
2019-02-15 15:39:39 +05:30
# deprecated old Release representation
class TagRelease < Grape::Entity
2015-11-26 14:37:03 +05:30
expose :tag, as: :tag_name
expose :description
end
2019-02-15 15:39:39 +05:30
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
2019-07-31 22:56:46 +05:30
class Release < Grape::Entity
2019-12-26 22:10:19 +05:30
include ::API::Helpers::Presentable
expose :name do |release, _|
can_download_code? ? release.name : "Release-#{release.id}"
end
2019-12-21 20:55:43 +05:30
expose :tag, as: :tag_name, if: ->(_, _) { can_download_code? }
2019-07-31 22:56:46 +05:30
expose :description
2019-02-15 15:39:39 +05:30
expose :description_html do |entity|
MarkupHelper.markdown_field(entity, :description)
end
expose :created_at
2019-09-30 21:07:59 +05:30
expose :released_at
2019-02-15 15:39:39 +05:30
expose :author, using: Entities::UserBasic, if: -> (release, _) { release.author.present? }
2019-12-21 20:55:43 +05:30
expose :commit, using: Entities::Commit, if: ->(_, _) { can_download_code? }
2019-09-30 21:07:59 +05:30
expose :upcoming_release?, as: :upcoming_release
2020-01-03 18:37:03 +05:30
expose :milestones, using: Entities::Milestone, if: -> (release, _) { release.milestones.present? && can_read_milestone? }
2019-12-26 22:10:19 +05:30
expose :commit_path, expose_nil: false
expose :tag_path, expose_nil: false
2020-01-01 13:55:28 +05:30
expose :evidence_sha, expose_nil: false, if: ->(_, _) { can_download_code? }
2019-02-15 15:39:39 +05:30
expose :assets do
2019-07-31 22:56:46 +05:30
expose :assets_count, as: :count do |release, _|
assets_to_exclude = can_download_code? ? [] : [:sources]
release.assets_count(except: assets_to_exclude)
end
2019-12-21 20:55:43 +05:30
expose :sources, using: Entities::Releases::Source, if: ->(_, _) { can_download_code? }
2019-02-15 15:39:39 +05:30
expose :links, using: Entities::Releases::Link do |release, options|
release.links.sorted
end
2020-01-01 13:55:28 +05:30
expose :evidence_file_path, expose_nil: false, if: ->(_, _) { can_download_code? }
2019-02-15 15:39:39 +05:30
end
2019-12-21 20:55:43 +05:30
expose :_links do
2019-12-26 22:10:19 +05:30
expose :merge_requests_url, expose_nil: false
expose :issues_url, expose_nil: false
expose :edit_url, expose_nil: false
2019-12-21 20:55:43 +05:30
end
2019-07-31 22:56:46 +05:30
private
def can_download_code?
Ability.allowed?(options[:current_user], :download_code, object.project)
end
2020-01-03 18:37:03 +05:30
def can_read_milestone?
Ability.allowed?(options[:current_user], :read_milestone, object.project)
end
2019-02-15 15:39:39 +05:30
end
2018-03-17 18:26:18 +05:30
class Tag < Grape::Entity
2018-10-15 14:42:47 +05:30
expose :name, :message, :target
2015-11-26 14:37:03 +05:30
2018-03-17 18:26:18 +05:30
expose :commit, using: Entities::Commit do |repo_tag, options|
2016-11-24 13:41:30 +05:30
options[:project].repository.commit(repo_tag.dereferenced_target)
2015-11-26 14:37:03 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2019-02-15 15:39:39 +05:30
expose :release, using: Entities::TagRelease do |repo_tag, options|
2016-08-24 12:49:21 +05:30
options[:project].releases.find_by(tag: repo_tag.name)
2015-11-26 14:37:03 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2019-12-04 20:38:33 +05:30
expose :protected do |repo_tag, options|
::ProtectedTag.protected?(options[:project], repo_tag.name)
end
2015-11-26 14:37:03 +05:30
end
2015-12-23 02:04:40 +05:30
class Runner < Grape::Entity
expose :id
expose :description
2018-11-08 19:23:39 +05:30
expose :ip_address
expose :active
2018-11-08 19:23:39 +05:30
expose :instance_type?, as: :is_shared
expose :name
2018-03-17 18:26:18 +05:30
expose :online?, as: :online
expose :status
end
2016-04-02 18:10:28 +05:30
class RunnerDetails < Runner
expose :tag_list
2016-06-02 11:05:42 +05:30
expose :run_untagged
2016-06-22 15:30:34 +05:30
expose :locked
2018-05-09 12:01:36 +05:30
expose :maximum_timeout
2018-03-17 18:26:18 +05:30
expose :access_level
2016-04-02 18:10:28 +05:30
expose :version, :revision, :platform, :architecture
expose :contacted_at
2018-11-08 19:23:39 +05:30
expose :token, if: lambda { |runner, options| options[:current_user].admin? || !runner.instance_type? }
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2016-04-02 18:10:28 +05:30
expose :projects, with: Entities::BasicProjectDetails do |runner, options|
2017-08-17 22:00:37 +05:30
if options[:current_user].admin?
2016-04-02 18:10:28 +05:30
runner.projects
else
options[:current_user].authorized_projects.where(id: runner.projects)
end
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
2018-10-15 14:42:47 +05:30
expose :groups, with: Entities::BasicGroupDetails do |runner, options|
if options[:current_user].admin?
runner.groups
else
options[:current_user].authorized_groups.where(id: runner.groups)
end
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2016-04-02 18:10:28 +05:30
end
2017-08-17 22:00:37 +05:30
class RunnerRegistrationDetails < Grape::Entity
expose :id, :token
end
class JobArtifactFile < Grape::Entity
2019-02-15 15:39:39 +05:30
expose :filename
expose :cached_size, as: :size
2016-04-02 18:10:28 +05:30
end
2018-11-20 20:47:30 +05:30
class JobArtifact < Grape::Entity
expose :file_type, :size, :filename, :file_format
end
2018-03-17 18:26:18 +05:30
class JobBasic < Grape::Entity
2019-09-04 21:01:54 +05:30
expose :id, :status, :stage, :name, :ref, :tag, :coverage, :allow_failure
expose :created_at, :started_at, :finished_at
2018-03-17 18:26:18 +05:30
expose :duration
expose :user, with: User
2018-03-17 18:26:18 +05:30
expose :commit, with: Commit
expose :pipeline, with: PipelineBasic
2018-11-18 11:00:15 +05:30
expose :web_url do |job, _options|
Gitlab::Routing.url_helpers.project_job_url(job.project, job)
end
2018-03-17 18:26:18 +05:30
end
class Job < JobBasic
2018-11-20 20:47:30 +05:30
# artifacts_file is included in job_artifacts, but kept for backward compatibility (remove in api/v5)
2017-08-17 22:00:37 +05:30
expose :artifacts_file, using: JobArtifactFile, if: -> (job, opts) { job.artifacts? }
2018-11-20 20:47:30 +05:30
expose :job_artifacts, as: :artifacts, using: JobArtifact
expose :runner, with: Runner
2018-11-08 19:23:39 +05:30
expose :artifacts_expire_at
2018-03-17 18:26:18 +05:30
end
class JobBasicWithProject < JobBasic
expose :project, with: ProjectIdentity
end
class Trigger < Grape::Entity
2019-02-02 18:00:53 +05:30
include ::API::Helpers::Presentable
2017-08-17 22:00:37 +05:30
expose :id
2019-02-02 18:00:53 +05:30
expose :token
expose :description
2018-03-17 18:26:18 +05:30
expose :created_at, :updated_at, :last_used
2017-08-17 22:00:37 +05:30
expose :owner, using: Entities::UserBasic
end
class Variable < Grape::Entity
2019-07-31 22:56:46 +05:30
expose :variable_type, :key, :value
2018-03-17 18:26:18 +05:30
expose :protected?, as: :protected, if: -> (entity, _) { entity.respond_to?(:protected?) }
2019-09-04 21:01:54 +05:30
expose :masked?, as: :masked, if: -> (entity, _) { entity.respond_to?(:masked?) }
2019-10-12 21:52:04 +05:30
expose :environment_scope, if: -> (entity, _) { entity.respond_to?(:environment_scope) }
end
2016-06-02 11:05:42 +05:30
2016-11-03 12:29:30 +05:30
class Pipeline < PipelineBasic
expose :before_sha, :tag, :yaml_errors
2016-09-13 17:45:13 +05:30
expose :user, with: Entities::UserBasic
expose :created_at, :updated_at, :started_at, :finished_at, :committed_at
expose :duration
2017-08-17 22:00:37 +05:30
expose :coverage
2019-07-07 11:18:12 +05:30
expose :detailed_status, using: DetailedStatusEntity do |pipeline, options|
pipeline.detailed_status(options[:current_user])
end
2016-09-13 17:45:13 +05:30
end
2017-09-10 17:25:29 +05:30
class PipelineSchedule < Grape::Entity
expose :id
expose :description, :ref, :cron, :cron_timezone, :next_run_at, :active
expose :created_at, :updated_at
expose :owner, using: Entities::UserBasic
end
class PipelineScheduleDetails < PipelineSchedule
expose :last_pipeline, using: Entities::PipelineBasic
2018-03-17 18:26:18 +05:30
expose :variables, using: Entities::Variable
2017-09-10 17:25:29 +05:30
end
2016-09-29 09:46:39 +05:30
class EnvironmentBasic < Grape::Entity
2017-08-17 22:00:37 +05:30
expose :id, :name, :slug, :external_url
2016-09-13 17:45:13 +05:30
end
class Deployment < Grape::Entity
2019-12-21 20:55:43 +05:30
expose :id, :iid, :ref, :sha, :created_at, :updated_at
2016-09-13 17:45:13 +05:30
expose :user, using: Entities::UserBasic
expose :environment, using: Entities::EnvironmentBasic
2017-08-17 22:00:37 +05:30
expose :deployable, using: Entities::Job
2019-12-21 20:55:43 +05:30
expose :status
2016-09-13 17:45:13 +05:30
end
2019-07-31 22:56:46 +05:30
class Environment < EnvironmentBasic
expose :project, using: Entities::BasicProjectDetails
expose :last_deployment, using: Entities::Deployment, if: { last_deployment: true }
2019-12-21 20:55:43 +05:30
expose :state
2019-07-31 22:56:46 +05:30
end
2018-12-13 13:39:08 +05:30
class LicenseBasic < Grape::Entity
2016-06-02 11:05:42 +05:30
expose :key, :name, :nickname
expose :url, as: :html_url
expose(:source_url) { |license| license.meta['source'] }
2018-12-13 13:39:08 +05:30
end
class License < LicenseBasic
expose :popular?, as: :popular
2016-06-02 11:05:42 +05:30
expose(:description) { |license| license.meta['description'] }
expose(:conditions) { |license| license.meta['conditions'] }
expose(:permissions) { |license| license.meta['permissions'] }
expose(:limitations) { |license| license.meta['limitations'] }
expose :content
end
2016-06-22 15:30:34 +05:30
class TemplatesList < Grape::Entity
2018-12-05 23:21:45 +05:30
expose :key
2016-06-02 11:05:42 +05:30
expose :name
end
2016-06-22 15:30:34 +05:30
class Template < Grape::Entity
2016-06-02 11:05:42 +05:30
expose :name, :content
end
2016-09-29 09:46:39 +05:30
class BroadcastMessage < Grape::Entity
expose :id, :message, :starts_at, :ends_at, :color, :font
expose :active?, as: :active
end
2017-08-17 22:00:37 +05:30
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
2018-12-05 23:21:45 +05:30
class ImpersonationToken < PersonalAccessToken
expose :impersonation
end
class ImpersonationTokenWithToken < PersonalAccessTokenWithToken
2017-08-17 22:00:37 +05:30
expose :impersonation
end
2017-09-10 17:25:29 +05:30
class FeatureGate < Grape::Entity
expose :key
expose :value
end
class Feature < Grape::Entity
expose :name
expose :state
expose :gates, using: FeatureGate do |model|
model.gates.map do |gate|
value = model.gate_values[gate.key]
# By default all gate values are populated. Only show relevant ones.
if (value.is_a?(Integer) && value.zero?) || (value.is_a?(Set) && value.empty?)
next
end
{ key: gate.key, value: value }
end.compact
end
end
2017-08-17 22:00:37 +05:30
module JobRequest
class JobInfo < Grape::Entity
expose :name, :stage
expose :project_id, :project_name
end
class GitInfo < Grape::Entity
expose :repo_url, :ref, :sha, :before_sha
2019-07-07 11:18:12 +05:30
expose :ref_type
expose :refspecs
expose :git_depth, as: :depth
2017-08-17 22:00:37 +05:30
end
class RunnerInfo < Grape::Entity
2018-05-09 12:01:36 +05:30
expose :metadata_timeout, as: :timeout
2018-11-08 19:23:39 +05:30
expose :runner_session_url
2017-08-17 22:00:37 +05:30
end
class Step < Grape::Entity
expose :name, :script, :timeout, :when, :allow_failure
end
2019-07-07 11:18:12 +05:30
class Port < Grape::Entity
expose :number, :protocol, :name
end
2017-08-17 22:00:37 +05:30
class Image < Grape::Entity
2017-09-10 17:25:29 +05:30
expose :name, :entrypoint
2019-07-07 11:18:12 +05:30
expose :ports, using: JobRequest::Port
2017-09-10 17:25:29 +05:30
end
class Service < Image
expose :alias, :command
2017-08-17 22:00:37 +05:30
end
class Artifacts < Grape::Entity
2018-11-18 11:00:15 +05:30
expose :name
expose :untracked
expose :paths
expose :when
expose :expire_in
expose :artifact_type
expose :artifact_format
2017-08-17 22:00:37 +05:30
end
class Cache < Grape::Entity
2017-09-10 17:25:29 +05:30
expose :key, :untracked, :paths, :policy
2017-08-17 22:00:37 +05:30
end
class Credentials < Grape::Entity
expose :type, :url, :username, :password
end
class Dependency < Grape::Entity
2019-02-15 15:39:39 +05:30
expose :id, :name, :token
2018-03-17 18:26:18 +05:30
expose :artifacts_file, using: JobArtifactFile, if: ->(job, _) { job.artifacts? }
2017-08-17 22:00:37 +05:30
end
class Response < Grape::Entity
expose :id
expose :token
expose :allow_git_fetch
expose :job_info, using: JobInfo do |model|
model
end
expose :git_info, using: GitInfo do |model|
model
end
expose :runner_info, using: RunnerInfo do |model|
model
end
expose :variables
expose :steps, using: Step
expose :image, using: Image
2017-09-10 17:25:29 +05:30
expose :services, using: Service
2017-08-17 22:00:37 +05:30
expose :artifacts, using: Artifacts
expose :cache, using: Cache
expose :credentials, using: Credentials
2020-01-01 13:55:28 +05:30
expose :all_dependencies, as: :dependencies, using: Dependency
2018-03-17 18:26:18 +05:30
expose :features
2017-08-17 22:00:37 +05:30
end
end
2017-09-10 17:25:29 +05:30
class UserAgentDetail < Grape::Entity
expose :user_agent
expose :ip_address
expose :submitted, as: :akismet_submitted
end
2018-03-17 18:26:18 +05:30
class CustomAttribute < Grape::Entity
expose :key
expose :value
end
class PagesDomainCertificateExpiration < Grape::Entity
expose :expired?, as: :expired
expose :expiration
end
class PagesDomainCertificate < Grape::Entity
expose :subject
expose :expired?, as: :expired
expose :certificate
expose :certificate_text
end
class PagesDomainBasic < Grape::Entity
expose :domain
expose :url
expose :project_id
expose :verified?, as: :verified
expose :verification_code, as: :verification_code
expose :enabled_until
2019-12-26 22:10:19 +05:30
expose :auto_ssl_enabled
2018-03-17 18:26:18 +05:30
expose :certificate,
as: :certificate_expiration,
if: ->(pages_domain, _) { pages_domain.certificate? },
using: PagesDomainCertificateExpiration do |pages_domain|
pages_domain
end
end
class PagesDomain < Grape::Entity
expose :domain
expose :url
expose :verified?, as: :verified
expose :verification_code, as: :verification_code
expose :enabled_until
2019-12-26 22:10:19 +05:30
expose :auto_ssl_enabled
2018-03-17 18:26:18 +05:30
expose :certificate,
if: ->(pages_domain, _) { pages_domain.certificate? },
using: PagesDomainCertificate do |pages_domain|
pages_domain
end
end
class Application < Grape::Entity
2018-12-13 13:39:08 +05:30
expose :id
2018-03-17 18:26:18 +05:30
expose :uid, as: :application_id
2018-12-13 13:39:08 +05:30
expose :name, as: :application_name
2018-03-17 18:26:18 +05:30
expose :redirect_uri, as: :callback_url
end
# Use with care, this exposes the secret
class ApplicationWithSecret < Application
expose :secret
end
class Blob < Grape::Entity
expose :basename
expose :data
2019-12-26 22:10:19 +05:30
expose :path
# TODO: :filename was renamed to :path but both still return the full path,
# in the future we can only return the filename here without the leading
# directory path.
# https://gitlab.com/gitlab-org/gitlab/issues/34521
expose :filename, &:path
2018-03-17 18:26:18 +05:30
expose :id
expose :ref
expose :startline
expose :project_id
end
2018-03-27 19:54:05 +05:30
class BasicBadgeDetails < Grape::Entity
2020-01-01 13:55:28 +05:30
expose :name
2018-03-27 19:54:05 +05:30
expose :link_url
expose :image_url
expose :rendered_link_url do |badge, options|
badge.rendered_link_url(options.fetch(:project, nil))
end
expose :rendered_image_url do |badge, options|
badge.rendered_image_url(options.fetch(:project, nil))
end
end
class Badge < BasicBadgeDetails
expose :id
expose :kind do |badge|
badge.type == 'ProjectBadge' ? 'project' : 'group'
end
end
2018-11-20 20:47:30 +05:30
class ResourceLabelEvent < Grape::Entity
expose :id
expose :user, using: Entities::UserBasic
expose :created_at
expose :resource_type do |event, options|
event.issuable.class.name
end
expose :resource_id do |event, options|
event.issuable.id
end
expose :label, using: Entities::LabelBasic
expose :action
end
2019-02-15 15:39:39 +05:30
class Suggestion < Grape::Entity
expose :id
expose :from_line
expose :to_line
expose :appliable?, as: :appliable
expose :applied
expose :from_content
expose :to_content
end
module Platform
class Kubernetes < Grape::Entity
expose :api_url
expose :namespace
expose :authorization_type
expose :ca_cert
end
end
module Provider
class Gcp < Grape::Entity
expose :cluster_id
expose :status_name
expose :gcp_project_id
expose :zone
expose :machine_type
expose :num_nodes
expose :endpoint
end
end
class Cluster < Grape::Entity
2019-07-07 11:18:12 +05:30
expose :id, :name, :created_at, :domain
2019-02-15 15:39:39 +05:30
expose :provider_type, :platform_type, :environment_scope, :cluster_type
expose :user, using: Entities::UserBasic
expose :platform_kubernetes, using: Entities::Platform::Kubernetes
expose :provider_gcp, using: Entities::Provider::Gcp
2019-12-26 22:10:19 +05:30
expose :management_project, using: Entities::ProjectIdentity
2019-02-15 15:39:39 +05:30
end
class ClusterProject < Cluster
expose :project, using: Entities::BasicProjectDetails
end
2019-09-30 21:07:59 +05:30
class ClusterGroup < Cluster
expose :group, using: Entities::BasicGroupDetails
end
2019-12-04 20:38:33 +05:30
module InternalPostReceive
class Message < Grape::Entity
expose :message
expose :type
end
class Response < Grape::Entity
expose :messages, using: Message
expose :reference_counter_decreased
end
end
2014-09-02 18:07:02 +05:30
end
end
2019-12-04 20:38:33 +05:30
# rubocop: disable Cop/InjectEnterpriseEditionModule
::API::Entities::ApplicationSetting.prepend_if_ee('EE::API::Entities::ApplicationSetting')
::API::Entities::Board.prepend_if_ee('EE::API::Entities::Board')
::API::Entities::Group.prepend_if_ee('EE::API::Entities::Group', with_descendants: true)
::API::Entities::GroupDetail.prepend_if_ee('EE::API::Entities::GroupDetail')
::API::Entities::IssueBasic.prepend_if_ee('EE::API::Entities::IssueBasic', with_descendants: true)
::API::Entities::Issue.prepend_if_ee('EE::API::Entities::Issue')
::API::Entities::List.prepend_if_ee('EE::API::Entities::List')
::API::Entities::MergeRequestBasic.prepend_if_ee('EE::API::Entities::MergeRequestBasic', with_descendants: true)
2020-01-01 13:55:28 +05:30
::API::Entities::Member.prepend_if_ee('EE::API::Entities::Member', with_descendants: true)
2019-12-04 20:38:33 +05:30
::API::Entities::Namespace.prepend_if_ee('EE::API::Entities::Namespace')
::API::Entities::Project.prepend_if_ee('EE::API::Entities::Project', with_descendants: true)
::API::Entities::ProtectedRefAccess.prepend_if_ee('EE::API::Entities::ProtectedRefAccess')
::API::Entities::UserPublic.prepend_if_ee('EE::API::Entities::UserPublic', with_descendants: true)
::API::Entities::Todo.prepend_if_ee('EE::API::Entities::Todo')
::API::Entities::ProtectedBranch.prepend_if_ee('EE::API::Entities::ProtectedBranch')
::API::Entities::Identity.prepend_if_ee('EE::API::Entities::Identity')
::API::Entities::UserWithAdmin.prepend_if_ee('EE::API::Entities::UserWithAdmin', with_descendants: true)