2013-05-14 08:33:31 -04:00
|
|
|
module API
|
2012-06-27 07:32:56 -04:00
|
|
|
module Entities
|
2014-06-13 10:46:48 -04:00
|
|
|
class UserSafe < Grape::Entity
|
|
|
|
expose :name, :username
|
|
|
|
end
|
2014-02-13 08:45:24 -05:00
|
|
|
|
2014-06-13 10:46:48 -04:00
|
|
|
class UserBasic < UserSafe
|
2017-05-10 00:26:17 -04:00
|
|
|
expose :id, :state
|
|
|
|
expose :avatar_url do |user, options|
|
|
|
|
user.avatar_url(only_path: false)
|
|
|
|
end
|
2015-07-30 05:56:15 -04:00
|
|
|
|
|
|
|
expose :web_url do |user, options|
|
2016-03-24 12:00:26 -04:00
|
|
|
Gitlab::Routing.url_helpers.user_url(user)
|
2015-07-30 05:56:15 -04:00
|
|
|
end
|
2012-06-27 07:32:56 -04:00
|
|
|
end
|
2012-06-27 08:51:39 -04:00
|
|
|
|
2014-06-13 10:46:48 -04:00
|
|
|
class User < UserBasic
|
|
|
|
expose :created_at
|
2016-09-26 13:33:00 -04:00
|
|
|
expose :bio, :location, :skype, :linkedin, :twitter, :website_url, :organization
|
2013-03-11 08:35:00 -04:00
|
|
|
end
|
|
|
|
|
2017-04-12 07:19:45 -04:00
|
|
|
class UserActivity < Grape::Entity
|
|
|
|
expose :username
|
2017-03-27 09:43:10 -04:00
|
|
|
expose :last_activity_on
|
|
|
|
expose :last_activity_on, as: :last_activity_at # Back-compat
|
2017-04-12 07:19:45 -04:00
|
|
|
end
|
|
|
|
|
2014-11-27 06:34:39 -05:00
|
|
|
class Identity < Grape::Entity
|
|
|
|
expose :provider, :extern_uid
|
|
|
|
end
|
|
|
|
|
2016-11-21 07:59:37 -05:00
|
|
|
class UserPublic < User
|
2016-02-24 07:14:37 -05:00
|
|
|
expose :last_sign_in_at
|
|
|
|
expose :confirmed_at
|
2017-03-27 09:43:10 -04:00
|
|
|
expose :last_activity_on
|
2014-06-13 10:46:48 -04:00
|
|
|
expose :email
|
2017-02-13 12:50:13 -05:00
|
|
|
expose :color_scheme_id, :projects_limit, :current_sign_in_at
|
2014-11-27 06:34:39 -05:00
|
|
|
expose :identities, using: Entities::Identity
|
2014-06-13 10:46:48 -04:00
|
|
|
expose :can_create_group?, as: :can_create_group
|
|
|
|
expose :can_create_project?, as: :can_create_project
|
2016-06-06 00:38:42 -04:00
|
|
|
expose :two_factor_enabled?, as: :two_factor_enabled
|
2016-03-14 19:11:20 -04:00
|
|
|
expose :external
|
2012-07-05 09:47:00 -04:00
|
|
|
end
|
|
|
|
|
2017-06-20 10:54:29 -04:00
|
|
|
class UserWithAdmin < UserPublic
|
2017-04-21 05:47:58 -04:00
|
|
|
expose :admin?, as: :is_admin
|
2012-09-20 10:44:44 -04:00
|
|
|
end
|
|
|
|
|
2017-06-20 10:54:29 -04:00
|
|
|
class UserWithPrivateDetails < UserWithAdmin
|
|
|
|
expose :private_token
|
|
|
|
end
|
|
|
|
|
2015-07-29 09:40:08 -04:00
|
|
|
class Email < Grape::Entity
|
|
|
|
expose :id, :email
|
|
|
|
end
|
|
|
|
|
2012-09-08 13:51:12 -04:00
|
|
|
class Hook < Grape::Entity
|
2017-05-05 12:00:32 -04:00
|
|
|
expose :id, :url, :created_at, :push_events, :tag_push_events, :repository_update_events
|
2016-10-19 10:08:30 -04:00
|
|
|
expose :enable_ssl_verification
|
2012-09-08 13:51:12 -04:00
|
|
|
end
|
|
|
|
|
2013-12-04 06:19:53 -05:00
|
|
|
class ProjectHook < Hook
|
2016-10-18 14:07:56 -04:00
|
|
|
expose :project_id, :issues_events, :merge_requests_events
|
2017-02-22 05:13:59 -05:00
|
|
|
expose :note_events, :pipeline_events, :wiki_page_events
|
2017-05-15 11:11:45 -04:00
|
|
|
expose :job_events
|
2013-12-04 06:19:53 -05:00
|
|
|
end
|
|
|
|
|
2016-07-08 03:34:36 -04:00
|
|
|
class SharedGroup < Grape::Entity
|
|
|
|
expose :group_id
|
|
|
|
expose :group_name do |group_link, options|
|
|
|
|
group_link.group.name
|
|
|
|
end
|
|
|
|
expose :group_access, as: :group_access_level
|
|
|
|
end
|
|
|
|
|
2017-08-03 03:43:24 -04:00
|
|
|
class BasicProjectDetails < Grape::Entity
|
|
|
|
expose :id, :description, :default_branch, :tag_list
|
|
|
|
expose :ssh_url_to_repo, :http_url_to_repo, :web_url
|
|
|
|
expose :name, :name_with_namespace
|
|
|
|
expose :path, :path_with_namespace
|
|
|
|
expose :star_count, :forks_count
|
|
|
|
expose :created_at, :last_activity_at
|
|
|
|
end
|
|
|
|
|
2017-08-15 13:44:37 -04:00
|
|
|
class Project < BasicProjectDetails
|
2017-07-25 05:35:45 -04:00
|
|
|
include ::API::Helpers::RelatedResourcesHelpers
|
|
|
|
|
|
|
|
expose :_links do
|
|
|
|
expose :self do |project|
|
|
|
|
expose_url(api_v4_projects_path(id: project.id))
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :issues, if: -> (*args) { issues_available?(*args) } do |project|
|
|
|
|
expose_url(api_v4_projects_issues_path(id: project.id))
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :merge_requests, if: -> (*args) { mrs_available?(*args) } do |project|
|
|
|
|
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
|
|
|
|
|
2014-04-18 11:55:06 -04:00
|
|
|
expose :archived?, as: :archived
|
2017-08-03 03:43:24 -04:00
|
|
|
expose :visibility
|
2014-03-17 08:33:41 -04:00
|
|
|
expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group }
|
2016-08-01 18:31:21 -04:00
|
|
|
expose :container_registry_enabled
|
|
|
|
|
|
|
|
# Expose old field names with the new permissions methods to keep API compatible
|
2016-11-29 14:21:39 -05:00
|
|
|
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]) }
|
2017-02-22 05:13:59 -05:00
|
|
|
expose(:jobs_enabled) { |project, options| project.feature_available?(:builds, options[:current_user]) }
|
2016-11-29 14:21:39 -05:00
|
|
|
expose(:snippets_enabled) { |project, options| project.feature_available?(:snippets, options[:current_user]) }
|
2016-08-01 18:31:21 -04:00
|
|
|
|
2016-09-06 12:48:00 -04:00
|
|
|
expose :shared_runners_enabled
|
|
|
|
expose :lfs_enabled?, as: :lfs_enabled
|
2015-04-10 12:35:05 -04:00
|
|
|
expose :creator_id
|
2016-11-29 14:25:41 -05:00
|
|
|
expose :namespace, using: 'API::Entities::Namespace'
|
2017-08-09 05:52:22 -04:00
|
|
|
expose :forked_from_project, using: Entities::BasicProjectDetails, if: lambda { |project, options| project.forked? }
|
2017-06-01 10:57:41 -04:00
|
|
|
expose :import_status
|
|
|
|
expose :import_error, if: lambda { |_project, options| options[:user_can_admin_project] }
|
2017-05-10 00:26:17 -04:00
|
|
|
expose :avatar_url do |user, options|
|
|
|
|
user.avatar_url(only_path: false)
|
|
|
|
end
|
2017-07-10 03:38:42 -04:00
|
|
|
expose :open_issues_count, if: lambda { |project, options| project.feature_available?(:issues, options[:current_user]) }
|
2016-01-11 09:27:20 -05:00
|
|
|
expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] }
|
2017-02-23 03:16:20 -05:00
|
|
|
expose :public_builds, as: :public_jobs
|
2017-07-05 08:11:01 -04:00
|
|
|
expose :ci_config_path
|
2016-07-08 03:34:36 -04:00
|
|
|
expose :shared_with_groups do |project, options|
|
|
|
|
SharedGroup.represent(project.project_group_links.all, options)
|
|
|
|
end
|
2017-02-17 08:56:13 -05:00
|
|
|
expose :only_allow_merge_if_pipeline_succeeds
|
2016-09-14 18:04:27 -04:00
|
|
|
expose :request_access_enabled
|
2016-09-16 07:02:42 -04:00
|
|
|
expose :only_allow_merge_if_all_discussions_are_resolved
|
2017-06-16 14:39:21 -04:00
|
|
|
expose :printing_merge_request_link_enabled
|
2016-11-22 11:58:10 -05:00
|
|
|
|
|
|
|
expose :statistics, using: 'API::Entities::ProjectStatistics', if: :statistics
|
|
|
|
end
|
|
|
|
|
|
|
|
class ProjectStatistics < Grape::Entity
|
|
|
|
expose :commit_count
|
|
|
|
expose :storage_size
|
|
|
|
expose :repository_size
|
|
|
|
expose :lfs_objects_size
|
2017-02-23 03:16:20 -05:00
|
|
|
expose :build_artifacts_size, as: :job_artifacts_size
|
2012-06-27 08:51:39 -04:00
|
|
|
end
|
|
|
|
|
2016-06-23 11:14:31 -04:00
|
|
|
class Member < UserBasic
|
2014-09-15 04:55:36 -04:00
|
|
|
expose :access_level do |user, options|
|
2016-09-15 12:34:57 -04:00
|
|
|
member = options[:member] || options[:source].members.find_by(user_id: user.id)
|
2016-06-23 11:14:31 -04:00
|
|
|
member.access_level
|
|
|
|
end
|
2016-08-18 12:01:50 -04:00
|
|
|
expose :expires_at do |user, options|
|
2016-09-15 12:34:57 -04:00
|
|
|
member = options[:member] || options[:source].members.find_by(user_id: user.id)
|
2016-08-18 12:01:50 -04:00
|
|
|
member.expires_at
|
|
|
|
end
|
2016-06-23 11:14:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class AccessRequester < UserBasic
|
|
|
|
expose :requested_at do |user, options|
|
2016-09-15 12:34:57 -04:00
|
|
|
access_requester = options[:access_requester] || options[:source].requesters.find_by(user_id: user.id)
|
2016-06-23 11:14:31 -04:00
|
|
|
access_requester.requested_at
|
2012-09-21 06:23:17 -04:00
|
|
|
end
|
2012-09-06 16:49:29 -04:00
|
|
|
end
|
|
|
|
|
2013-01-08 16:05:00 -05:00
|
|
|
class Group < Grape::Entity
|
2017-03-01 15:23:00 -05:00
|
|
|
expose :id, :name, :path, :description, :visibility
|
2016-09-06 12:48:00 -04:00
|
|
|
expose :lfs_enabled?, as: :lfs_enabled
|
2017-05-10 00:26:17 -04:00
|
|
|
expose :avatar_url do |user, options|
|
|
|
|
user.avatar_url(only_path: false)
|
|
|
|
end
|
2016-06-02 12:05:06 -04:00
|
|
|
expose :web_url
|
2016-09-14 18:04:27 -04:00
|
|
|
expose :request_access_enabled
|
2017-01-26 14:31:32 -05:00
|
|
|
expose :full_name, :full_path
|
2017-05-03 08:49:37 -04:00
|
|
|
|
|
|
|
if ::Group.supports_nested_groups?
|
|
|
|
expose :parent_id
|
|
|
|
end
|
2016-11-22 11:58:10 -05:00
|
|
|
|
|
|
|
expose :statistics, if: :statistics do
|
|
|
|
with_options format_with: -> (value) { value.to_i } do
|
|
|
|
expose :storage_size
|
|
|
|
expose :repository_size
|
|
|
|
expose :lfs_objects_size
|
2017-02-23 03:16:20 -05:00
|
|
|
expose :build_artifacts_size, as: :job_artifacts_size
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
|
|
|
end
|
2013-01-08 16:05:00 -05:00
|
|
|
end
|
2013-02-18 04:10:58 -05:00
|
|
|
|
2013-02-03 13:38:33 -05:00
|
|
|
class GroupDetail < Group
|
2013-01-08 16:05:00 -05:00
|
|
|
expose :projects, using: Entities::Project
|
2016-07-08 04:59:52 -04:00
|
|
|
expose :shared_projects, using: Entities::Project
|
2013-01-08 16:05:00 -05:00
|
|
|
end
|
|
|
|
|
2016-10-27 09:26:58 -04:00
|
|
|
class RepoCommit < Grape::Entity
|
|
|
|
expose :id, :short_id, :title, :created_at
|
|
|
|
expose :parent_ids
|
|
|
|
expose :safe_message, as: :message
|
|
|
|
expose :author_name, :author_email, :authored_date
|
|
|
|
expose :committer_name, :committer_email, :committed_date
|
|
|
|
end
|
|
|
|
|
|
|
|
class RepoCommitStats < Grape::Entity
|
|
|
|
expose :additions, :deletions, :total
|
|
|
|
end
|
|
|
|
|
|
|
|
class RepoCommitDetail < RepoCommit
|
|
|
|
expose :stats, using: Entities::RepoCommitStats
|
|
|
|
expose :status
|
|
|
|
end
|
|
|
|
|
2016-07-19 07:30:23 -04:00
|
|
|
class RepoBranch < Grape::Entity
|
2014-02-04 07:46:15 -05:00
|
|
|
expose :name
|
|
|
|
|
2016-10-27 09:26:58 -04:00
|
|
|
expose :commit, using: Entities::RepoCommit do |repo_branch, options|
|
2016-09-26 23:07:31 -04:00
|
|
|
options[:project].repository.commit(repo_branch.dereferenced_target)
|
2014-02-04 07:46:15 -05:00
|
|
|
end
|
|
|
|
|
2016-11-28 13:16:15 -05:00
|
|
|
expose :merged do |repo_branch, options|
|
|
|
|
options[:project].repository.merged_to_root_ref?(repo_branch.name)
|
|
|
|
end
|
|
|
|
|
2016-07-19 07:30:23 -04:00
|
|
|
expose :protected do |repo_branch, options|
|
2017-08-02 06:16:17 -04:00
|
|
|
::ProtectedBranch.protected?(options[:project], repo_branch.name)
|
2016-07-12 10:31:55 -04:00
|
|
|
end
|
|
|
|
|
2016-07-19 07:30:23 -04:00
|
|
|
expose :developers_can_push do |repo_branch, options|
|
2017-04-03 20:39:34 -04:00
|
|
|
options[:project].protected_branches.developers_can?(:push, repo_branch.name)
|
2013-01-28 12:22:44 -05:00
|
|
|
end
|
2016-07-19 04:36:18 -04:00
|
|
|
|
2016-07-19 07:30:23 -04:00
|
|
|
expose :developers_can_merge do |repo_branch, options|
|
2017-04-03 20:39:34 -04:00
|
|
|
options[:project].protected_branches.developers_can?(:merge, repo_branch.name)
|
2016-07-19 04:36:18 -04:00
|
|
|
end
|
2012-06-27 08:51:39 -04:00
|
|
|
end
|
2012-06-29 09:34:08 -04:00
|
|
|
|
2014-02-04 07:46:15 -05:00
|
|
|
class RepoTreeObject < Grape::Entity
|
2016-08-29 11:23:40 -04:00
|
|
|
expose :id, :name, :type, :path
|
2014-02-04 07:46:15 -05:00
|
|
|
|
|
|
|
expose :mode do |obj, options|
|
2017-04-01 11:55:14 -04:00
|
|
|
filemode = obj.mode
|
2014-02-04 07:46:15 -05:00
|
|
|
filemode = "0" + filemode if filemode.length < 6
|
|
|
|
filemode
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-29 09:34:08 -04:00
|
|
|
class ProjectSnippet < Grape::Entity
|
2017-05-03 11:26:49 -04:00
|
|
|
expose :id, :title, :file_name, :description
|
2012-08-10 18:07:50 -04:00
|
|
|
expose :author, using: Entities::UserBasic
|
2016-03-05 17:17:49 -05:00
|
|
|
expose :updated_at, :created_at
|
2016-03-09 13:25:39 -05:00
|
|
|
|
2016-08-02 13:37:04 -04:00
|
|
|
expose :web_url do |snippet, options|
|
|
|
|
Gitlab::UrlBuilder.build(snippet)
|
|
|
|
end
|
2012-06-29 09:34:08 -04:00
|
|
|
end
|
2012-07-24 08:19:51 -04:00
|
|
|
|
2016-11-26 10:37:26 -05:00
|
|
|
class PersonalSnippet < Grape::Entity
|
2017-05-03 11:26:49 -04:00
|
|
|
expose :id, :title, :file_name, :description
|
2016-11-26 10:37:26 -05:00
|
|
|
expose :author, using: Entities::UserBasic
|
|
|
|
expose :updated_at, :created_at
|
|
|
|
|
|
|
|
expose :web_url do |snippet|
|
|
|
|
Gitlab::UrlBuilder.build(snippet)
|
|
|
|
end
|
|
|
|
expose :raw_url do |snippet|
|
|
|
|
Gitlab::UrlBuilder.build(snippet) + "/raw"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-14 09:39:54 -04:00
|
|
|
class ProjectEntity < Grape::Entity
|
|
|
|
expose :id, :iid
|
2017-07-07 11:08:49 -04:00
|
|
|
expose(:project_id) { |entity| entity&.project.try(:id) }
|
2014-04-09 11:24:12 -04:00
|
|
|
expose :title, :description
|
|
|
|
expose :state, :created_at, :updated_at
|
2013-10-14 09:39:54 -04:00
|
|
|
end
|
|
|
|
|
2015-02-02 16:08:10 -05:00
|
|
|
class RepoDiff < Grape::Entity
|
|
|
|
expose :old_path, :new_path, :a_mode, :b_mode, :diff
|
2017-05-15 13:10:29 -04:00
|
|
|
expose :new_file?, as: :new_file
|
|
|
|
expose :renamed_file?, as: :renamed_file
|
|
|
|
expose :deleted_file?, as: :deleted_file
|
2015-02-02 16:08:10 -05:00
|
|
|
end
|
|
|
|
|
2017-08-02 06:16:17 -04:00
|
|
|
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
|
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
class Milestone < Grape::Entity
|
|
|
|
expose :id, :iid
|
2017-07-12 15:58:48 -04:00
|
|
|
expose :project_id, if: -> (entity, options) { entity&.project_id }
|
|
|
|
expose :group_id, if: -> (entity, options) { entity&.group_id }
|
2017-07-07 11:08:49 -04:00
|
|
|
expose :title, :description
|
|
|
|
expose :state, :created_at, :updated_at
|
2014-04-09 11:24:12 -04:00
|
|
|
expose :due_date
|
2016-11-15 12:48:30 -05:00
|
|
|
expose :start_date
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
|
2017-03-06 06:48:10 -05:00
|
|
|
class IssueBasic < ProjectEntity
|
2014-07-30 10:17:29 -04:00
|
|
|
expose :label_names, as: :labels
|
2012-08-10 18:07:50 -04:00
|
|
|
expose :milestone, using: Entities::Milestone
|
2017-05-04 08:11:15 -04:00
|
|
|
expose :assignees, :author, using: Entities::UserBasic
|
|
|
|
|
|
|
|
expose :assignee, using: ::API::Entities::UserBasic do |issue, options|
|
|
|
|
issue.assignees.first
|
|
|
|
end
|
2016-04-08 02:41:10 -04:00
|
|
|
|
2016-06-01 05:23:09 -04:00
|
|
|
expose :user_notes_count
|
2016-05-11 16:43:58 -04:00
|
|
|
expose :upvotes, :downvotes
|
2016-07-12 11:59:21 -04:00
|
|
|
expose :due_date
|
2016-07-15 10:21:53 -04:00
|
|
|
expose :confidential
|
2016-08-02 13:37:04 -04:00
|
|
|
|
|
|
|
expose :web_url do |issue, options|
|
|
|
|
Gitlab::UrlBuilder.build(issue)
|
|
|
|
end
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
2012-09-16 10:52:06 -04:00
|
|
|
|
2017-03-06 06:48:10 -05:00
|
|
|
class Issue < IssueBasic
|
2017-07-25 05:35:45 -04:00
|
|
|
include ::API::Helpers::RelatedResourcesHelpers
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-03-06 06:48:10 -05:00
|
|
|
expose :subscribed do |issue, options|
|
|
|
|
issue.subscribed?(options[:current_user], options[:project] || issue.project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-18 11:48:16 -05:00
|
|
|
class IssuableTimeStats < Grape::Entity
|
|
|
|
expose :time_estimate
|
|
|
|
expose :total_time_spent
|
|
|
|
expose :human_time_estimate
|
|
|
|
expose :human_total_time_spent
|
|
|
|
end
|
|
|
|
|
2016-06-11 10:16:32 -04:00
|
|
|
class ExternalIssue < Grape::Entity
|
|
|
|
expose :title
|
|
|
|
expose :id
|
|
|
|
end
|
|
|
|
|
2017-07-10 17:58:23 -04:00
|
|
|
class MergeRequestSimple < ProjectEntity
|
|
|
|
expose :title
|
|
|
|
expose :web_url do |merge_request, options|
|
|
|
|
Gitlab::UrlBuilder.build(merge_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-06 06:48:10 -05:00
|
|
|
class MergeRequestBasic < ProjectEntity
|
2015-11-11 08:12:51 -05:00
|
|
|
expose :target_branch, :source_branch
|
2017-07-08 02:21:09 -04:00
|
|
|
expose :upvotes do |merge_request, options|
|
|
|
|
if options[:issuable_metadata]
|
|
|
|
options[:issuable_metadata][merge_request.id].upvotes
|
|
|
|
else
|
|
|
|
merge_request.upvotes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
expose :downvotes do |merge_request, options|
|
|
|
|
if options[:issuable_metadata]
|
|
|
|
options[:issuable_metadata][merge_request.id].downvotes
|
|
|
|
else
|
|
|
|
merge_request.downvotes
|
|
|
|
end
|
|
|
|
end
|
2013-10-14 09:39:54 -04:00
|
|
|
expose :author, :assignee, using: Entities::UserBasic
|
|
|
|
expose :source_project_id, :target_project_id
|
2017-07-08 02:21:09 -04:00
|
|
|
expose :labels do |merge_request, options|
|
|
|
|
# Avoids an N+1 query since labels are preloaded
|
|
|
|
merge_request.labels.map(&:title).sort
|
|
|
|
end
|
2015-07-09 13:21:37 -04:00
|
|
|
expose :work_in_progress?, as: :work_in_progress
|
2014-04-15 22:14:05 -04:00
|
|
|
expose :milestone, using: Entities::Milestone
|
2017-02-17 08:56:13 -05:00
|
|
|
expose :merge_when_pipeline_succeeds
|
2016-01-17 13:59:43 -05:00
|
|
|
expose :merge_status
|
2016-08-23 13:29:59 -04:00
|
|
|
expose :diff_head_sha, as: :sha
|
|
|
|
expose :merge_commit_sha
|
2016-06-01 05:23:09 -04:00
|
|
|
expose :user_notes_count
|
2016-07-11 11:25:01 -04:00
|
|
|
expose :should_remove_source_branch?, as: :should_remove_source_branch
|
|
|
|
expose :force_remove_source_branch?, as: :force_remove_source_branch
|
2016-08-02 13:37:04 -04:00
|
|
|
|
|
|
|
expose :web_url do |merge_request, options|
|
|
|
|
Gitlab::UrlBuilder.build(merge_request)
|
|
|
|
end
|
2012-09-16 10:52:06 -04:00
|
|
|
end
|
2012-10-21 07:00:27 -04:00
|
|
|
|
2017-03-06 06:48:10 -05:00
|
|
|
class MergeRequest < MergeRequestBasic
|
|
|
|
expose :subscribed do |merge_request, options|
|
|
|
|
merge_request.subscribed?(options[:current_user], options[:project])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-02 16:08:10 -05:00
|
|
|
class MergeRequestChanges < MergeRequest
|
|
|
|
expose :diffs, as: :changes, using: Entities::RepoDiff do |compare, _|
|
2017-05-31 15:41:25 -04:00
|
|
|
compare.raw_diffs(limits: false).to_a
|
2015-02-02 16:08:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-03 04:32:29 -04:00
|
|
|
class MergeRequestDiff < Grape::Entity
|
|
|
|
expose :id, :head_commit_sha, :base_commit_sha, :start_commit_sha,
|
|
|
|
:created_at, :merge_request_id, :state, :real_size
|
2016-08-12 07:44:49 -04:00
|
|
|
end
|
2016-08-03 04:32:29 -04:00
|
|
|
|
2016-08-12 07:44:49 -04:00
|
|
|
class MergeRequestDiffFull < MergeRequestDiff
|
2016-08-03 04:32:29 -04:00
|
|
|
expose :commits, using: Entities::RepoCommit
|
|
|
|
|
|
|
|
expose :diffs, using: Entities::RepoDiff do |compare, _|
|
2017-05-31 15:41:25 -04:00
|
|
|
compare.raw_diffs(limits: false).to_a
|
2016-08-03 04:32:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-14 09:39:54 -04:00
|
|
|
class SSHKey < Grape::Entity
|
2016-08-18 03:27:45 -04:00
|
|
|
expose :id, :title, :key, :created_at, :can_push
|
2012-10-21 07:00:27 -04:00
|
|
|
end
|
2012-10-21 12:48:56 -04:00
|
|
|
|
2015-08-29 05:52:21 -04:00
|
|
|
class SSHKeyWithUser < SSHKey
|
2016-11-21 07:59:37 -05:00
|
|
|
expose :user, using: Entities::UserPublic
|
2015-08-29 05:52:21 -04:00
|
|
|
end
|
|
|
|
|
2012-10-21 12:48:56 -04:00
|
|
|
class Note < Grape::Entity
|
2017-08-08 07:31:55 -04:00
|
|
|
# Only Issue and MergeRequest have iid
|
|
|
|
NOTEABLE_TYPES_WITH_IID = %w(Issue MergeRequest).freeze
|
|
|
|
|
2012-11-27 14:43:39 -05:00
|
|
|
expose :id
|
|
|
|
expose :note, as: :body
|
2013-03-19 07:28:29 -04:00
|
|
|
expose :attachment_identifier, as: :attachment
|
2012-10-21 12:48:56 -04:00
|
|
|
expose :author, using: Entities::UserBasic
|
2016-04-12 06:32:34 -04:00
|
|
|
expose :created_at, :updated_at
|
2015-08-12 15:39:58 -04:00
|
|
|
expose :system?, as: :system
|
2015-12-04 06:21:06 -05:00
|
|
|
expose :noteable_id, :noteable_type
|
2017-08-08 07:31:55 -04:00
|
|
|
|
|
|
|
# Avoid N+1 queries as much as possible
|
|
|
|
expose(:noteable_iid) { |note| note.noteable.iid if NOTEABLE_TYPES_WITH_IID.include?(note.noteable_type) }
|
2012-10-21 12:48:56 -04:00
|
|
|
end
|
2012-11-29 15:10:07 -05:00
|
|
|
|
2016-06-08 03:33:41 -04:00
|
|
|
class AwardEmoji < Grape::Entity
|
|
|
|
expose :id
|
|
|
|
expose :name
|
|
|
|
expose :user, using: Entities::UserBasic
|
|
|
|
expose :created_at, :updated_at
|
|
|
|
expose :awardable_id, :awardable_type
|
|
|
|
end
|
|
|
|
|
2012-11-29 15:10:07 -05:00
|
|
|
class MRNote < Grape::Entity
|
|
|
|
expose :note
|
|
|
|
expose :author, using: Entities::UserBasic
|
|
|
|
end
|
2013-06-06 12:19:17 -04:00
|
|
|
|
2014-06-27 10:48:30 -04:00
|
|
|
class CommitNote < Grape::Entity
|
|
|
|
expose :note
|
2016-06-20 13:15:44 -04:00
|
|
|
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? }
|
2014-06-27 10:48:30 -04:00
|
|
|
expose :author, using: Entities::UserBasic
|
2015-08-19 02:29:18 -04:00
|
|
|
expose :created_at
|
2014-06-27 10:48:30 -04:00
|
|
|
end
|
|
|
|
|
2015-10-06 06:01:16 -04:00
|
|
|
class CommitStatus < Grape::Entity
|
|
|
|
expose :id, :sha, :ref, :status, :name, :target_url, :description,
|
2017-02-13 21:28:45 -05:00
|
|
|
:created_at, :started_at, :finished_at, :allow_failure, :coverage
|
2015-10-12 06:15:48 -04:00
|
|
|
expose :author, using: Entities::UserBasic
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
|
Migrate events into a new format
This commit migrates events data in such a way that push events are
stored much more efficiently. This is done by creating a shadow table
called "events_for_migration", and a table called "push_event_payloads"
which is used for storing push data of push events. The background
migration in this commit will copy events from the "events" table into
the "events_for_migration" table, push events in will also have a row
created in "push_event_payloads".
This approach allows us to reclaim space in the next release by simply
swapping the "events" and "events_for_migration" tables, then dropping
the old events (now "events_for_migration") table.
The new table structure is also optimised for storage space, and does
not include the unused "title" column nor the "data" column (since this
data is moved to "push_event_payloads").
== Newly Created Events
Newly created events are inserted into both "events" and
"events_for_migration", both using the exact same primary key value. The
table "push_event_payloads" in turn has a foreign key to the _shadow_
table. This removes the need for recreating and validating the foreign
key after swapping the tables. Since the shadow table also has a foreign
key to "projects.id" we also don't have to worry about orphaned rows.
This approach however does require some additional storage as we're
duplicating a portion of the events data for at least 1 release. The
exact amount is hard to estimate, but for GitLab.com this is expected to
be between 10 and 20 GB at most. The background migration in this commit
deliberately does _not_ update the "events" table as doing so would put
a lot of pressure on PostgreSQL's auto vacuuming system.
== Supporting Both Old And New Events
Application code has also been adjusted to support push events using
both the old and new data formats. This is done by creating a PushEvent
class which extends the regular Event class. Using Rails' Single Table
Inheritance system we can ensure the right class is used for the right
data, which in this case is based on the value of `events.action`. To
support displaying old and new data at the same time the PushEvent class
re-defines a few methods of the Event class, falling back to their
original implementations for push events in the old format.
Once all existing events have been migrated the various push event
related methods can be removed from the Event model, and the calls to
`super` can be removed from the methods in the PushEvent model.
The UI and event atom feed have also been slightly changed to better
handle this new setup, fortunately only a few changes were necessary to
make this work.
== API Changes
The API only displays push data of events in the new format. Supporting
both formats in the API is a bit more difficult compared to the UI.
Since the old push data was not really well documented (apart from one
example that used an incorrect "action" nmae) I decided that supporting
both was not worth the effort, especially since events will be migrated
in a few days _and_ new events are created in the correct format.
2017-07-10 11:43:57 -04:00
|
|
|
class PushEventPayload < Grape::Entity
|
|
|
|
expose :commit_count, :action, :ref_type, :commit_from, :commit_to
|
|
|
|
expose :ref, :commit_title
|
|
|
|
end
|
|
|
|
|
2013-06-06 12:19:17 -04:00
|
|
|
class Event < Grape::Entity
|
|
|
|
expose :title, :project_id, :action_name
|
2017-08-02 02:18:17 -04:00
|
|
|
expose :target_id, :target_iid, :target_type, :author_id
|
Migrate events into a new format
This commit migrates events data in such a way that push events are
stored much more efficiently. This is done by creating a shadow table
called "events_for_migration", and a table called "push_event_payloads"
which is used for storing push data of push events. The background
migration in this commit will copy events from the "events" table into
the "events_for_migration" table, push events in will also have a row
created in "push_event_payloads".
This approach allows us to reclaim space in the next release by simply
swapping the "events" and "events_for_migration" tables, then dropping
the old events (now "events_for_migration") table.
The new table structure is also optimised for storage space, and does
not include the unused "title" column nor the "data" column (since this
data is moved to "push_event_payloads").
== Newly Created Events
Newly created events are inserted into both "events" and
"events_for_migration", both using the exact same primary key value. The
table "push_event_payloads" in turn has a foreign key to the _shadow_
table. This removes the need for recreating and validating the foreign
key after swapping the tables. Since the shadow table also has a foreign
key to "projects.id" we also don't have to worry about orphaned rows.
This approach however does require some additional storage as we're
duplicating a portion of the events data for at least 1 release. The
exact amount is hard to estimate, but for GitLab.com this is expected to
be between 10 and 20 GB at most. The background migration in this commit
deliberately does _not_ update the "events" table as doing so would put
a lot of pressure on PostgreSQL's auto vacuuming system.
== Supporting Both Old And New Events
Application code has also been adjusted to support push events using
both the old and new data formats. This is done by creating a PushEvent
class which extends the regular Event class. Using Rails' Single Table
Inheritance system we can ensure the right class is used for the right
data, which in this case is based on the value of `events.action`. To
support displaying old and new data at the same time the PushEvent class
re-defines a few methods of the Event class, falling back to their
original implementations for push events in the old format.
Once all existing events have been migrated the various push event
related methods can be removed from the Event model, and the calls to
`super` can be removed from the methods in the PushEvent model.
The UI and event atom feed have also been slightly changed to better
handle this new setup, fortunately only a few changes were necessary to
make this work.
== API Changes
The API only displays push data of events in the new format. Supporting
both formats in the API is a bit more difficult compared to the UI.
Since the old push data was not really well documented (apart from one
example that used an incorrect "action" nmae) I decided that supporting
both was not worth the effort, especially since events will be migrated
in a few days _and_ new events are created in the correct format.
2017-07-10 11:43:57 -04:00
|
|
|
expose :target_title
|
2014-04-09 11:24:12 -04:00
|
|
|
expose :created_at
|
2015-12-04 06:21:06 -05:00
|
|
|
expose :note, using: Entities::Note, if: ->(event, options) { event.note? }
|
|
|
|
expose :author, using: Entities::UserBasic, if: ->(event, options) { event.author }
|
2014-10-31 06:08:45 -04:00
|
|
|
|
Migrate events into a new format
This commit migrates events data in such a way that push events are
stored much more efficiently. This is done by creating a shadow table
called "events_for_migration", and a table called "push_event_payloads"
which is used for storing push data of push events. The background
migration in this commit will copy events from the "events" table into
the "events_for_migration" table, push events in will also have a row
created in "push_event_payloads".
This approach allows us to reclaim space in the next release by simply
swapping the "events" and "events_for_migration" tables, then dropping
the old events (now "events_for_migration") table.
The new table structure is also optimised for storage space, and does
not include the unused "title" column nor the "data" column (since this
data is moved to "push_event_payloads").
== Newly Created Events
Newly created events are inserted into both "events" and
"events_for_migration", both using the exact same primary key value. The
table "push_event_payloads" in turn has a foreign key to the _shadow_
table. This removes the need for recreating and validating the foreign
key after swapping the tables. Since the shadow table also has a foreign
key to "projects.id" we also don't have to worry about orphaned rows.
This approach however does require some additional storage as we're
duplicating a portion of the events data for at least 1 release. The
exact amount is hard to estimate, but for GitLab.com this is expected to
be between 10 and 20 GB at most. The background migration in this commit
deliberately does _not_ update the "events" table as doing so would put
a lot of pressure on PostgreSQL's auto vacuuming system.
== Supporting Both Old And New Events
Application code has also been adjusted to support push events using
both the old and new data formats. This is done by creating a PushEvent
class which extends the regular Event class. Using Rails' Single Table
Inheritance system we can ensure the right class is used for the right
data, which in this case is based on the value of `events.action`. To
support displaying old and new data at the same time the PushEvent class
re-defines a few methods of the Event class, falling back to their
original implementations for push events in the old format.
Once all existing events have been migrated the various push event
related methods can be removed from the Event model, and the calls to
`super` can be removed from the methods in the PushEvent model.
The UI and event atom feed have also been slightly changed to better
handle this new setup, fortunately only a few changes were necessary to
make this work.
== API Changes
The API only displays push data of events in the new format. Supporting
both formats in the API is a bit more difficult compared to the UI.
Since the old push data was not really well documented (apart from one
example that used an incorrect "action" nmae) I decided that supporting
both was not worth the effort, especially since events will be migrated
in a few days _and_ new events are created in the correct format.
2017-07-10 11:43:57 -04:00
|
|
|
expose :push_event_payload,
|
|
|
|
as: :push_data,
|
|
|
|
using: PushEventPayload,
|
|
|
|
if: -> (event, _) { event.push? }
|
|
|
|
|
2014-10-31 06:08:45 -04:00
|
|
|
expose :author_username do |event, options|
|
2017-02-07 09:16:46 -05:00
|
|
|
event.author&.username
|
2014-10-31 06:08:45 -04:00
|
|
|
end
|
2013-06-06 12:19:17 -04:00
|
|
|
end
|
2013-11-15 08:24:10 -05:00
|
|
|
|
2016-03-13 06:46:16 -04:00
|
|
|
class ProjectGroupLink < Grape::Entity
|
2016-09-22 16:31:18 -04:00
|
|
|
expose :id, :project_id, :group_id, :group_access, :expires_at
|
2016-03-13 06:46:16 -04:00
|
|
|
end
|
|
|
|
|
2016-03-11 14:04:42 -05:00
|
|
|
class Todo < Grape::Entity
|
|
|
|
expose :id
|
|
|
|
expose :project, using: Entities::BasicProjectDetails
|
|
|
|
expose :author, using: Entities::UserBasic
|
2016-06-15 07:20:30 -04:00
|
|
|
expose :action_name
|
2016-03-11 14:04:42 -05:00
|
|
|
expose :target_type
|
2016-06-22 13:15:09 -04:00
|
|
|
|
|
|
|
expose :target do |todo, options|
|
2017-02-21 08:44:21 -05:00
|
|
|
target = todo.target_type == 'Commit' ? 'RepoCommit' : todo.target_type
|
|
|
|
Entities.const_get(target).represent(todo.target, options)
|
2016-03-11 14:04:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :target_url do |todo, options|
|
|
|
|
target_type = todo.target_type.underscore
|
|
|
|
target_url = "namespace_project_#{target_type}_url"
|
2016-06-22 13:15:09 -04:00
|
|
|
target_anchor = "note_#{todo.note_id}" if todo.note_id?
|
2016-03-11 14:04:42 -05:00
|
|
|
|
2017-08-10 12:39:26 -04:00
|
|
|
Gitlab::Routing
|
|
|
|
.url_helpers
|
|
|
|
.public_send(target_url, todo.project.namespace, todo.project, todo.target, anchor: target_anchor) # rubocop:disable GitlabSecurity/PublicSend
|
2016-03-11 14:04:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :body
|
|
|
|
expose :state
|
|
|
|
expose :created_at
|
|
|
|
end
|
|
|
|
|
2013-11-15 08:24:10 -05:00
|
|
|
class Namespace < Grape::Entity
|
2017-06-27 16:35:35 -04:00
|
|
|
expose :id, :name, :path, :kind, :full_path, :parent_id
|
|
|
|
|
2017-06-28 16:27:01 -04:00
|
|
|
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)
|
2017-06-27 16:35:35 -04:00
|
|
|
end
|
2013-11-15 08:24:10 -05:00
|
|
|
end
|
2014-03-17 08:33:41 -04:00
|
|
|
|
2016-06-23 11:14:31 -04:00
|
|
|
class MemberAccess < Grape::Entity
|
2014-09-15 04:55:36 -04:00
|
|
|
expose :access_level
|
2016-03-29 16:19:00 -04:00
|
|
|
expose :notification_level do |member, options|
|
|
|
|
if member.notification_setting
|
2016-08-02 16:52:55 -04:00
|
|
|
::NotificationSetting.levels[member.notification_setting.level]
|
2016-03-29 16:19:00 -04:00
|
|
|
end
|
|
|
|
end
|
2014-03-17 08:33:41 -04:00
|
|
|
end
|
|
|
|
|
2016-06-23 11:14:31 -04:00
|
|
|
class ProjectAccess < MemberAccess
|
2016-03-29 16:19:00 -04:00
|
|
|
end
|
|
|
|
|
2016-06-23 11:14:31 -04:00
|
|
|
class GroupAccess < MemberAccess
|
2014-03-17 08:33:41 -04:00
|
|
|
end
|
|
|
|
|
2016-08-02 16:52:55 -04:00
|
|
|
class NotificationSetting < Grape::Entity
|
|
|
|
expose :level
|
|
|
|
expose :events, if: ->(notification_setting, _) { notification_setting.custom? } do
|
|
|
|
::NotificationSetting::EMAIL_EVENTS.each do |event|
|
|
|
|
expose event
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class GlobalNotificationSetting < NotificationSetting
|
|
|
|
expose :notification_email do |notification_setting, options|
|
|
|
|
notification_setting.user.notification_email
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-12 09:24:00 -04:00
|
|
|
class ProjectService < Grape::Entity
|
|
|
|
expose :id, :title, :created_at, :updated_at, :active
|
2016-08-02 06:06:31 -04:00
|
|
|
expose :push_events, :issues_events, :merge_requests_events
|
2017-02-22 05:13:59 -05:00
|
|
|
expose :tag_push_events, :note_events, :pipeline_events
|
2017-05-15 11:11:45 -04:00
|
|
|
expose :job_events
|
2015-10-12 09:24:00 -04:00
|
|
|
# Expose serialized properties
|
|
|
|
expose :properties do |service, options|
|
2017-06-21 09:48:12 -04:00
|
|
|
field_names = service.fields
|
|
|
|
.select { |field| options[:include_passwords] || field[:type] != 'password' }
|
|
|
|
.map { |field| field[:name] }
|
2015-10-12 09:24:00 -04:00
|
|
|
service.properties.slice(*field_names)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-17 08:33:41 -04:00
|
|
|
class ProjectWithAccess < Project
|
|
|
|
expose :permissions do
|
|
|
|
expose :project_access, using: Entities::ProjectAccess do |project, options|
|
2017-07-06 09:09:35 -04:00
|
|
|
if options.key?(:project_members)
|
|
|
|
(options[:project_members] || []).find { |member| member.source_id == project.id }
|
|
|
|
else
|
|
|
|
project.project_members.find_by(user_id: options[:current_user].id)
|
|
|
|
end
|
2014-03-17 08:33:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :group_access, using: Entities::GroupAccess do |project, options|
|
2014-03-17 09:14:27 -04:00
|
|
|
if project.group
|
2017-07-06 09:09:35 -04:00
|
|
|
if options.key?(:group_members)
|
|
|
|
(options[:group_members] || []).find { |member| member.source_id == project.namespace_id }
|
|
|
|
else
|
|
|
|
project.group.group_members.find_by(user_id: options[:current_user].id)
|
|
|
|
end
|
2014-03-17 09:14:27 -04:00
|
|
|
end
|
2014-03-17 08:33:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-03-21 05:18:19 -04:00
|
|
|
|
2016-10-02 23:12:59 -04:00
|
|
|
class LabelBasic < Grape::Entity
|
2016-11-04 07:52:38 -04:00
|
|
|
expose :id, :name, :color, :description
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Label < LabelBasic
|
2016-11-14 09:52:43 -05:00
|
|
|
expose :open_issues_count do |label, options|
|
2016-11-14 10:04:07 -05:00
|
|
|
label.open_issues_count(options[:current_user])
|
|
|
|
end
|
2016-11-14 09:52:43 -05:00
|
|
|
|
2016-11-14 10:04:07 -05:00
|
|
|
expose :closed_issues_count do |label, options|
|
|
|
|
label.closed_issues_count(options[:current_user])
|
|
|
|
end
|
2016-11-14 09:52:43 -05:00
|
|
|
|
2016-11-14 10:04:07 -05:00
|
|
|
expose :open_merge_requests_count do |label, options|
|
|
|
|
label.open_merge_requests_count(options[:current_user])
|
2016-11-14 09:52:43 -05:00
|
|
|
end
|
|
|
|
|
2016-09-29 10:33:38 -04:00
|
|
|
expose :priority do |label, options|
|
|
|
|
label.priority(options[:project])
|
|
|
|
end
|
2016-05-12 16:48:09 -04:00
|
|
|
|
|
|
|
expose :subscribed do |label, options|
|
2016-11-01 12:06:05 -04:00
|
|
|
label.subscribed?(options[:current_user], options[:project])
|
2016-05-12 16:48:09 -04:00
|
|
|
end
|
2014-03-21 05:18:19 -04:00
|
|
|
end
|
2014-05-26 09:08:22 -04:00
|
|
|
|
2016-10-02 23:12:59 -04:00
|
|
|
class List < Grape::Entity
|
|
|
|
expose :id
|
|
|
|
expose :label, using: Entities::LabelBasic
|
|
|
|
expose :position
|
|
|
|
end
|
|
|
|
|
|
|
|
class Board < Grape::Entity
|
|
|
|
expose :id
|
|
|
|
expose :lists, using: Entities::List do |board|
|
|
|
|
board.lists.destroyable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-26 09:08:22 -04:00
|
|
|
class Compare < Grape::Entity
|
|
|
|
expose :commit, using: Entities::RepoCommit do |compare, options|
|
2015-04-21 09:09:15 -04:00
|
|
|
Commit.decorate(compare.commits, nil).last
|
2014-05-26 09:08:22 -04:00
|
|
|
end
|
2014-07-29 07:29:59 -04:00
|
|
|
|
2014-05-26 09:08:22 -04:00
|
|
|
expose :commits, using: Entities::RepoCommit do |compare, options|
|
2015-04-21 09:09:15 -04:00
|
|
|
Commit.decorate(compare.commits, nil)
|
2014-05-26 09:08:22 -04:00
|
|
|
end
|
2014-07-29 07:29:59 -04:00
|
|
|
|
2014-05-26 09:08:22 -04:00
|
|
|
expose :diffs, using: Entities::RepoDiff do |compare, options|
|
2017-05-31 15:41:25 -04:00
|
|
|
compare.diffs(limits: false).to_a
|
2014-05-26 09:08:22 -04:00
|
|
|
end
|
2014-05-27 04:16:50 -04:00
|
|
|
|
|
|
|
expose :compare_timeout do |compare, options|
|
2016-03-03 12:38:44 -05:00
|
|
|
compare.diffs.overflow?
|
2014-05-27 04:16:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :same, as: :compare_same_ref
|
2014-05-26 09:08:22 -04:00
|
|
|
end
|
2014-07-02 08:09:06 -04:00
|
|
|
|
|
|
|
class Contributor < Grape::Entity
|
|
|
|
expose :name, :email, :commits, :additions, :deletions
|
|
|
|
end
|
2015-02-07 10:41:30 -05:00
|
|
|
|
|
|
|
class BroadcastMessage < Grape::Entity
|
|
|
|
expose :message, :starts_at, :ends_at, :color, :font
|
|
|
|
end
|
2015-07-03 10:50:21 -04:00
|
|
|
|
|
|
|
class ApplicationSetting < Grape::Entity
|
|
|
|
expose :id
|
2017-07-13 12:03:52 -04:00
|
|
|
expose(*::ApplicationSettingsHelper.visible_attributes)
|
2017-02-17 08:50:02 -05:00
|
|
|
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) }
|
2017-07-13 12:03:52 -04:00
|
|
|
expose :password_authentication_enabled, as: :signin_enabled
|
2015-07-03 10:50:21 -04:00
|
|
|
end
|
2015-11-12 10:26:39 -05:00
|
|
|
|
|
|
|
class Release < Grape::Entity
|
2015-11-21 11:29:26 -05:00
|
|
|
expose :tag, as: :tag_name
|
|
|
|
expose :description
|
2015-11-12 10:26:39 -05:00
|
|
|
end
|
2015-11-12 17:52:02 -05:00
|
|
|
|
|
|
|
class RepoTag < Grape::Entity
|
2016-07-19 07:30:23 -04:00
|
|
|
expose :name, :message
|
2015-11-12 17:52:02 -05:00
|
|
|
|
2017-07-26 09:53:07 -04:00
|
|
|
expose :commit, using: Entities::RepoCommit do |repo_tag, options|
|
2016-09-26 23:07:31 -04:00
|
|
|
options[:project].repository.commit(repo_tag.dereferenced_target)
|
2015-11-12 17:52:02 -05:00
|
|
|
end
|
|
|
|
|
2016-07-19 07:30:23 -04:00
|
|
|
expose :release, using: Entities::Release do |repo_tag, options|
|
|
|
|
options[:project].releases.find_by(tag: repo_tag.name)
|
2015-11-12 17:52:02 -05:00
|
|
|
end
|
|
|
|
end
|
2015-12-10 12:04:40 -05:00
|
|
|
|
2016-01-08 16:57:42 -05:00
|
|
|
class Runner < Grape::Entity
|
2015-12-28 07:09:51 -05:00
|
|
|
expose :id
|
|
|
|
expose :description
|
|
|
|
expose :active
|
|
|
|
expose :is_shared
|
|
|
|
expose :name
|
|
|
|
end
|
|
|
|
|
2016-01-26 11:03:38 -05:00
|
|
|
class RunnerDetails < Runner
|
|
|
|
expose :tag_list
|
2016-05-06 06:32:17 -04:00
|
|
|
expose :run_untagged
|
2016-06-02 07:06:01 -04:00
|
|
|
expose :locked
|
2016-01-26 11:03:38 -05:00
|
|
|
expose :version, :revision, :platform, :architecture
|
2016-02-17 15:23:14 -05:00
|
|
|
expose :contacted_at
|
2017-04-08 22:20:57 -04:00
|
|
|
expose :token, if: lambda { |runner, options| options[:current_user].admin? || !runner.is_shared? }
|
2016-02-19 07:00:36 -05:00
|
|
|
expose :projects, with: Entities::BasicProjectDetails do |runner, options|
|
2017-04-08 22:20:57 -04:00
|
|
|
if options[:current_user].admin?
|
2016-02-04 08:53:53 -05:00
|
|
|
runner.projects
|
|
|
|
else
|
2016-02-10 06:26:56 -05:00
|
|
|
options[:current_user].authorized_projects.where(id: runner.projects)
|
2016-02-04 08:53:53 -05:00
|
|
|
end
|
|
|
|
end
|
2016-01-26 11:03:38 -05:00
|
|
|
end
|
|
|
|
|
2017-02-14 17:52:02 -05:00
|
|
|
class RunnerRegistrationDetails < Grape::Entity
|
|
|
|
expose :id, :token
|
|
|
|
end
|
|
|
|
|
2017-02-22 05:13:59 -05:00
|
|
|
class JobArtifactFile < Grape::Entity
|
2016-02-08 16:32:36 -05:00
|
|
|
expose :filename, :size
|
|
|
|
end
|
|
|
|
|
2016-09-23 19:43:57 -04:00
|
|
|
class PipelineBasic < Grape::Entity
|
|
|
|
expose :id, :sha, :ref, :status
|
|
|
|
end
|
|
|
|
|
2017-02-22 05:13:59 -05:00
|
|
|
class Job < Grape::Entity
|
2016-01-11 05:15:04 -05:00
|
|
|
expose :id, :status, :stage, :name, :ref, :tag, :coverage
|
2016-01-08 16:57:42 -05:00
|
|
|
expose :created_at, :started_at, :finished_at
|
2016-01-12 12:32:18 -05:00
|
|
|
expose :user, with: User
|
2017-03-06 03:31:37 -05:00
|
|
|
expose :artifacts_file, using: JobArtifactFile, if: -> (job, opts) { job.artifacts? }
|
2016-06-21 08:26:57 -04:00
|
|
|
expose :commit, with: RepoCommit
|
2016-01-08 16:57:42 -05:00
|
|
|
expose :runner, with: Runner
|
2016-09-23 19:43:57 -04:00
|
|
|
expose :pipeline, with: PipelineBasic
|
2015-12-24 13:05:57 -05:00
|
|
|
end
|
2016-01-14 07:30:18 -05:00
|
|
|
|
2016-01-04 10:38:32 -05:00
|
|
|
class Trigger < Grape::Entity
|
2017-03-05 15:18:00 -05:00
|
|
|
expose :id
|
2017-03-05 14:58:08 -05:00
|
|
|
expose :token, :description
|
|
|
|
expose :created_at, :updated_at, :deleted_at, :last_used
|
|
|
|
expose :owner, using: Entities::UserBasic
|
2016-01-04 10:38:32 -05:00
|
|
|
end
|
2016-01-14 07:09:54 -05:00
|
|
|
|
2015-12-31 09:19:13 -05:00
|
|
|
class Variable < Grape::Entity
|
2016-01-07 08:10:49 -05:00
|
|
|
expose :key, :value
|
2017-05-25 07:49:46 -04:00
|
|
|
expose :protected?, as: :protected
|
2015-12-31 09:19:13 -05:00
|
|
|
end
|
2016-04-11 09:49:25 -04:00
|
|
|
|
2016-09-23 19:43:57 -04:00
|
|
|
class Pipeline < PipelineBasic
|
|
|
|
expose :before_sha, :tag, :yaml_errors
|
2016-08-17 04:09:42 -04:00
|
|
|
|
|
|
|
expose :user, with: Entities::UserBasic
|
|
|
|
expose :created_at, :updated_at, :started_at, :finished_at, :committed_at
|
|
|
|
expose :duration
|
2016-11-22 11:28:58 -05:00
|
|
|
expose :coverage
|
2016-08-17 04:09:42 -04:00
|
|
|
end
|
|
|
|
|
2017-05-11 15:12:04 -04:00
|
|
|
class PipelineSchedule < Grape::Entity
|
|
|
|
expose :id
|
|
|
|
expose :description, :ref, :cron, :cron_timezone, :next_run_at, :active
|
2017-05-19 09:24:31 -04:00
|
|
|
expose :created_at, :updated_at
|
2017-05-11 15:12:04 -04:00
|
|
|
expose :owner, using: Entities::UserBasic
|
|
|
|
end
|
|
|
|
|
2017-05-27 08:29:01 -04:00
|
|
|
class PipelineScheduleDetails < PipelineSchedule
|
|
|
|
expose :last_pipeline, using: Entities::PipelineBasic
|
|
|
|
end
|
|
|
|
|
2016-08-23 10:25:17 -04:00
|
|
|
class EnvironmentBasic < Grape::Entity
|
2016-12-07 20:09:18 -05:00
|
|
|
expose :id, :name, :slug, :external_url
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
|
|
|
|
2016-08-23 10:25:17 -04:00
|
|
|
class Environment < EnvironmentBasic
|
2017-03-02 15:36:21 -05:00
|
|
|
expose :project, using: Entities::BasicProjectDetails
|
2016-08-16 02:45:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Deployment < Grape::Entity
|
|
|
|
expose :id, :iid, :ref, :sha, :created_at
|
2016-08-18 15:10:20 -04:00
|
|
|
expose :user, using: Entities::UserBasic
|
|
|
|
expose :environment, using: Entities::EnvironmentBasic
|
2017-02-22 05:13:59 -05:00
|
|
|
expose :deployable, using: Entities::Job
|
2016-07-26 03:37:02 -04:00
|
|
|
end
|
|
|
|
|
2016-04-19 05:08:48 -04:00
|
|
|
class RepoLicense < Grape::Entity
|
2016-04-13 09:56:37 -04:00
|
|
|
expose :key, :name, :nickname
|
|
|
|
expose :featured, as: :popular
|
2016-04-11 09:49:25 -04:00
|
|
|
expose :url, as: :html_url
|
|
|
|
expose(:source_url) { |license| license.meta['source'] }
|
|
|
|
expose(:description) { |license| license.meta['description'] }
|
2016-04-13 09:56:37 -04:00
|
|
|
expose(:conditions) { |license| license.meta['conditions'] }
|
|
|
|
expose(:permissions) { |license| license.meta['permissions'] }
|
|
|
|
expose(:limitations) { |license| license.meta['limitations'] }
|
2016-04-11 09:49:25 -04:00
|
|
|
expose :content
|
|
|
|
end
|
2016-04-29 10:25:03 -04:00
|
|
|
|
2016-05-27 05:00:56 -04:00
|
|
|
class TemplatesList < Grape::Entity
|
2016-04-29 10:25:03 -04:00
|
|
|
expose :name
|
|
|
|
end
|
|
|
|
|
2016-05-27 05:00:56 -04:00
|
|
|
class Template < Grape::Entity
|
2016-04-29 10:25:03 -04:00
|
|
|
expose :name, :content
|
|
|
|
end
|
2016-08-25 19:34:01 -04:00
|
|
|
|
|
|
|
class BroadcastMessage < Grape::Entity
|
|
|
|
expose :id, :message, :starts_at, :ends_at, :color, :font
|
|
|
|
expose :active?, as: :active
|
|
|
|
end
|
2017-02-15 12:08:29 -05:00
|
|
|
|
2017-02-23 12:47:06 -05:00
|
|
|
class PersonalAccessToken < Grape::Entity
|
2016-12-27 11:26:57 -05:00
|
|
|
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
|
|
|
|
|
2017-02-23 12:47:06 -05:00
|
|
|
class PersonalAccessTokenWithToken < PersonalAccessToken
|
2016-12-27 11:26:57 -05:00
|
|
|
expose :token
|
|
|
|
end
|
2017-02-23 12:47:06 -05:00
|
|
|
|
|
|
|
class ImpersonationToken < PersonalAccessTokenWithToken
|
|
|
|
expose :impersonation
|
|
|
|
end
|
2017-03-07 10:29:55 -05:00
|
|
|
|
2017-05-31 17:06:01 -04:00
|
|
|
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-02-15 19:05:44 -05:00
|
|
|
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
|
|
|
|
expose :ref_type do |model|
|
|
|
|
if model.tag
|
|
|
|
'tag'
|
|
|
|
else
|
|
|
|
'branch'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-15 12:08:29 -05:00
|
|
|
|
2017-02-15 19:05:44 -05:00
|
|
|
class RunnerInfo < Grape::Entity
|
|
|
|
expose :timeout
|
|
|
|
end
|
2017-02-15 12:08:29 -05:00
|
|
|
|
2017-02-15 19:05:44 -05:00
|
|
|
class Step < Grape::Entity
|
2017-02-27 10:05:44 -05:00
|
|
|
expose :name, :script, :timeout, :when, :allow_failure
|
2017-02-15 19:05:44 -05:00
|
|
|
end
|
2017-02-15 12:08:29 -05:00
|
|
|
|
2017-02-15 19:05:44 -05:00
|
|
|
class Image < Grape::Entity
|
2017-06-05 10:15:09 -04:00
|
|
|
expose :name, :entrypoint
|
|
|
|
end
|
|
|
|
|
2017-06-12 06:48:15 -04:00
|
|
|
class Service < Image
|
2017-06-05 10:15:09 -04:00
|
|
|
expose :alias, :command
|
2017-02-15 19:05:44 -05:00
|
|
|
end
|
2017-02-15 12:08:29 -05:00
|
|
|
|
2017-02-15 19:05:44 -05:00
|
|
|
class Artifacts < Grape::Entity
|
|
|
|
expose :name, :untracked, :paths, :when, :expire_in
|
2017-02-15 12:08:29 -05:00
|
|
|
end
|
|
|
|
|
2017-02-15 19:05:44 -05:00
|
|
|
class Cache < Grape::Entity
|
2017-06-27 10:38:12 -04:00
|
|
|
expose :key, :untracked, :paths, :policy
|
2017-02-15 12:08:29 -05:00
|
|
|
end
|
|
|
|
|
2017-02-15 19:05:44 -05:00
|
|
|
class Credentials < Grape::Entity
|
|
|
|
expose :type, :url, :username, :password
|
|
|
|
end
|
2017-02-15 12:08:29 -05:00
|
|
|
|
2017-02-15 19:05:44 -05:00
|
|
|
class ArtifactFile < Grape::Entity
|
|
|
|
expose :filename, :size
|
|
|
|
end
|
|
|
|
|
|
|
|
class Dependency < Grape::Entity
|
2017-03-16 00:18:37 -04:00
|
|
|
expose :id, :name, :token
|
2017-02-15 19:05:44 -05:00
|
|
|
expose :artifacts_file, using: ArtifactFile, if: ->(job, _) { job.artifacts? }
|
|
|
|
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-06-12 06:48:15 -04:00
|
|
|
expose :services, using: Service
|
2017-02-15 19:05:44 -05:00
|
|
|
expose :artifacts, using: Artifacts
|
|
|
|
expose :cache, using: Cache
|
|
|
|
expose :credentials, using: Credentials
|
2017-03-16 09:45:05 -04:00
|
|
|
expose :dependencies, using: Dependency
|
2017-02-15 19:05:44 -05:00
|
|
|
end
|
2017-02-15 12:08:29 -05:00
|
|
|
end
|
2017-07-05 08:59:19 -04:00
|
|
|
|
|
|
|
class UserAgentDetail < Grape::Entity
|
|
|
|
expose :user_agent
|
|
|
|
expose :ip_address
|
2017-07-06 09:19:14 -04:00
|
|
|
expose :submitted, as: :akismet_submitted
|
2017-07-05 08:59:19 -04:00
|
|
|
end
|
2017-05-17 12:17:15 -04:00
|
|
|
|
|
|
|
class RepositoryStorageHealth < Grape::Entity
|
|
|
|
expose :storage_name
|
|
|
|
expose :failing_on_hosts
|
|
|
|
expose :total_failures
|
|
|
|
end
|
2012-06-27 07:32:56 -04:00
|
|
|
end
|
|
|
|
end
|