2014-09-02 18:07:02 +05:30
|
|
|
module API
|
|
|
|
module Entities
|
|
|
|
class UserSafe < Grape::Entity
|
|
|
|
expose :name, :username
|
|
|
|
end
|
|
|
|
|
|
|
|
class UserBasic < UserSafe
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :id, :state
|
|
|
|
expose :avatar_url do |user, options|
|
|
|
|
user.avatar_url(only_path: false)
|
|
|
|
end
|
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
|
|
|
|
expose :created_at
|
2016-11-03 12:29:30 +05:30
|
|
|
expose :bio, :location, :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
|
|
|
|
|
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
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :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
|
2016-06-16 23:09:34 +05:30
|
|
|
expose :two_factor_enabled?, as: :two_factor_enabled
|
2016-06-02 11:05:42 +05:30
|
|
|
expose :external
|
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
|
|
|
|
|
|
|
|
class UserWithPrivateDetails < UserWithAdmin
|
2014-09-02 18:07:02 +05:30
|
|
|
expose :private_token
|
|
|
|
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
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :id, :url, :created_at, :push_events, :tag_push_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
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :project_id, :issues_events, :merge_requests_events
|
|
|
|
expose :note_events, :pipeline_events, :wiki_page_events
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :job_events
|
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
|
|
|
|
expose :group_access, as: :group_access_level
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
class BasicProjectDetails < Grape::Entity
|
2015-04-26 12:48:37 +05:30
|
|
|
expose :id, :description, :default_branch, :tag_list
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :ssh_url_to_repo, :http_url_to_repo, :web_url
|
2014-09-02 18:07:02 +05:30
|
|
|
expose :name, :name_with_namespace
|
|
|
|
expose :path, :path_with_namespace
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :star_count, :forks_count
|
|
|
|
expose :created_at, :last_activity_at
|
|
|
|
end
|
|
|
|
|
|
|
|
class Project < BasicProjectDetails
|
|
|
|
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
|
|
|
|
|
|
|
|
expose :archived?, as: :archived
|
|
|
|
expose :visibility
|
|
|
|
expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group }
|
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
|
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
|
|
|
|
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
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :namespace, using: 'API::Entities::Namespace'
|
2016-04-02 18:10:28 +05:30
|
|
|
expose :forked_from_project, using: Entities::BasicProjectDetails, if: lambda{ |project, options| project.forked? }
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :import_status
|
|
|
|
expose :import_error, if: lambda { |_project, options| options[:user_can_admin_project] }
|
|
|
|
expose :avatar_url do |user, options|
|
|
|
|
user.avatar_url(only_path: false)
|
|
|
|
end
|
|
|
|
expose :open_issues_count, if: lambda { |project, options| project.feature_available?(:issues, options[:current_user]) }
|
2016-01-19 16:12:03 +05:30
|
|
|
expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] }
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :public_builds, as: :public_jobs
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :ci_config_path
|
2016-08-24 12:49:21 +05:30
|
|
|
expose :shared_with_groups do |project, options|
|
|
|
|
SharedGroup.represent(project.project_group_links.all, options)
|
|
|
|
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
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :printing_merge_request_link_enabled
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
expose :build_artifacts_size, as: :job_artifacts_size
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
class Member < UserBasic
|
2015-04-26 12:48:37 +05:30
|
|
|
expose :access_level do |user, options|
|
2016-09-29 09:46:39 +05:30
|
|
|
member = options[:member] || options[:source].members.find_by(user_id: user.id)
|
2016-09-13 17:45:13 +05:30
|
|
|
member.access_level
|
|
|
|
end
|
|
|
|
expose :expires_at do |user, options|
|
2016-09-29 09:46:39 +05:30
|
|
|
member = options[:member] || options[:source].members.find_by(user_id: user.id)
|
2016-09-13 17:45:13 +05:30
|
|
|
member.expires_at
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class AccessRequester < UserBasic
|
|
|
|
expose :requested_at do |user, options|
|
2016-09-29 09:46:39 +05:30
|
|
|
access_requester = options[:access_requester] || options[:source].requesters.find_by(user_id: user.id)
|
2016-09-13 17:45:13 +05:30
|
|
|
access_requester.requested_at
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Group < Grape::Entity
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :id, :name, :path, :description, :visibility
|
2016-09-29 09:46:39 +05:30
|
|
|
expose :lfs_enabled?, as: :lfs_enabled
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :avatar_url do |user, options|
|
|
|
|
user.avatar_url(only_path: false)
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
expose :web_url
|
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
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
if ::Group.supports_nested_groups?
|
|
|
|
expose :parent_id
|
|
|
|
end
|
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
|
|
|
|
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
|
|
|
|
expose :projects, using: Entities::Project
|
2016-08-24 12:49:21 +05:30
|
|
|
expose :shared_projects, using: Entities::Project
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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-08-24 12:49:21 +05:30
|
|
|
class RepoBranch < Grape::Entity
|
2014-09-02 18:07:02 +05:30
|
|
|
expose :name
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :commit, using: Entities::RepoCommit 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|
|
|
|
|
options[:project].repository.merged_to_root_ref?(repo_branch.name)
|
|
|
|
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|
|
2017-08-17 22:00:37 +05:30
|
|
|
options[:project].protected_branches.developers_can?(:push, repo_branch.name)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :developers_can_merge do |repo_branch, options|
|
2017-08-17 22:00:37 +05:30
|
|
|
options[:project].protected_branches.developers_can?(:merge, repo_branch.name)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RepoTreeObject < 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
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class ProjectSnippet < Grape::Entity
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :id, :title, :file_name, :description
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :author, using: Entities::UserBasic
|
|
|
|
expose :updated_at, :created_at
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :web_url do |snippet, options|
|
|
|
|
Gitlab::UrlBuilder.build(snippet)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class PersonalSnippet < Grape::Entity
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :id, :title, :file_name, :description
|
2014-09-02 18:07:02 +05:30
|
|
|
expose :author, using: Entities::UserBasic
|
2016-06-02 11:05:42 +05:30
|
|
|
expose :updated_at, :created_at
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :web_url do |snippet|
|
2016-09-29 09:46:39 +05:30
|
|
|
Gitlab::UrlBuilder.build(snippet)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :raw_url do |snippet|
|
|
|
|
Gitlab::UrlBuilder.build(snippet) + "/raw"
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
class ProjectEntity < Grape::Entity
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class RepoDiff < Grape::Entity
|
|
|
|
expose :old_path, :new_path, :a_mode, :b_mode, :diff
|
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
|
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
|
|
|
|
|
|
|
|
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
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class IssueBasic < ProjectEntity
|
2014-09-02 18:07:02 +05:30
|
|
|
expose :label_names, as: :labels
|
|
|
|
expose :milestone, using: Entities::Milestone
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :assignees, :author, using: Entities::UserBasic
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :assignee, using: ::API::Entities::UserBasic do |issue, options|
|
|
|
|
issue.assignees.first
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
expose :user_notes_count
|
2016-06-16 23:09:34 +05:30
|
|
|
expose :upvotes, :downvotes
|
2016-08-24 12:49:21 +05:30
|
|
|
expose :due_date
|
2016-09-29 09:46:39 +05:30
|
|
|
expose :confidential
|
|
|
|
|
|
|
|
expose :web_url do |issue, options|
|
|
|
|
Gitlab::UrlBuilder.build(issue)
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class Issue < IssueBasic
|
2017-09-10 17:25:29 +05:30
|
|
|
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-08-17 22:00:37 +05:30
|
|
|
expose :subscribed do |issue, options|
|
|
|
|
issue.subscribed?(options[:current_user], options[:project] || issue.project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class IssuableTimeStats < Grape::Entity
|
|
|
|
expose :time_estimate
|
|
|
|
expose :total_time_spent
|
|
|
|
expose :human_time_estimate
|
|
|
|
expose :human_total_time_spent
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
class ExternalIssue < Grape::Entity
|
|
|
|
expose :title
|
|
|
|
expose :id
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
class MergeRequestSimple < ProjectEntity
|
|
|
|
expose :title
|
|
|
|
expose :web_url do |merge_request, options|
|
|
|
|
Gitlab::UrlBuilder.build(merge_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class MergeRequestBasic < ProjectEntity
|
2015-11-26 14:37:03 +05:30
|
|
|
expose :target_branch, :source_branch
|
2017-09-10 17:25:29 +05:30
|
|
|
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
|
2014-09-02 18:07:02 +05:30
|
|
|
expose :author, :assignee, using: Entities::UserBasic
|
|
|
|
expose :source_project_id, :target_project_id
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :labels do |merge_request, options|
|
|
|
|
# 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
|
2016-04-02 18:10:28 +05:30
|
|
|
expose :merge_status
|
2016-09-29 09:46:39 +05:30
|
|
|
expose :diff_head_sha, as: :sha
|
|
|
|
expose :merge_commit_sha
|
2016-06-02 11:05:42 +05:30
|
|
|
expose :user_notes_count
|
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
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
expose :web_url do |merge_request, options|
|
|
|
|
Gitlab::UrlBuilder.build(merge_request)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class MergeRequest < MergeRequestBasic
|
|
|
|
expose :subscribed do |merge_request, options|
|
|
|
|
merge_request.subscribed?(options[:current_user], options[:project])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class MergeRequestChanges < MergeRequest
|
|
|
|
expose :diffs, as: :changes, using: Entities::RepoDiff 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
|
|
|
|
expose :commits, using: Entities::RepoCommit
|
|
|
|
|
|
|
|
expose :diffs, using: Entities::RepoDiff 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
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :id, :title, :key, :created_at, :can_push
|
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
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
# 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
|
|
|
|
|
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
|
|
|
|
expose :commit_count, :action, :ref_type, :commit_from, :commit_to
|
|
|
|
expose :ref, :commit_title
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
class Event < Grape::Entity
|
|
|
|
expose :title, :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,
|
|
|
|
if: -> (event, _) { event.push? }
|
|
|
|
|
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
|
|
|
|
expose :project, using: Entities::BasicProjectDetails
|
|
|
|
expose :author, using: Entities::UserBasic
|
|
|
|
expose :action_name
|
|
|
|
expose :target_type
|
|
|
|
|
|
|
|
expose :target do |todo, options|
|
2017-08-17 22:00:37 +05:30
|
|
|
target = todo.target_type == 'Commit' ? 'RepoCommit' : todo.target_type
|
|
|
|
Entities.const_get(target).represent(todo.target, options)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :target_url do |todo, options|
|
|
|
|
target_type = todo.target_type.underscore
|
|
|
|
target_url = "namespace_project_#{target_type}_url"
|
|
|
|
target_anchor = "note_#{todo.note_id}" if todo.note_id?
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::Routing.url_helpers.public_send(target_url,
|
2016-08-24 12:49:21 +05:30
|
|
|
todo.project.namespace, todo.project, todo.target, anchor: target_anchor)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :body
|
|
|
|
expose :state
|
|
|
|
expose :created_at
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
class Namespace < Grape::Entity
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :id, :name, :path, :kind, :full_path, :parent_id
|
|
|
|
|
|
|
|
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
|
|
|
|
::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-24 18:46:33 +05:30
|
|
|
class ProjectService < Grape::Entity
|
|
|
|
expose :id, :title, :created_at, :updated_at, :active
|
2016-09-13 17:45:13 +05:30
|
|
|
expose :push_events, :issues_events, :merge_requests_events
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :tag_push_events, :note_events, :pipeline_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|
|
2017-09-10 17:25:29 +05:30
|
|
|
field_names = service.fields
|
|
|
|
.select { |field| options[:include_passwords] || field[:type] != 'password' }
|
|
|
|
.map { |field| field[:name] }
|
2015-10-24 18:46:33 +05:30
|
|
|
service.properties.slice(*field_names)
|
|
|
|
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|
|
2017-09-10 17:25:29 +05:30
|
|
|
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-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :group_access, using: Entities::GroupAccess do |project, options|
|
|
|
|
if project.group
|
2017-09-10 17:25:29 +05:30
|
|
|
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-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
class LabelBasic < Grape::Entity
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :id, :name, :color, :description
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
class Label < LabelBasic
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :open_issues_count do |label, options|
|
|
|
|
label.open_issues_count(options[:current_user])
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :closed_issues_count do |label, options|
|
|
|
|
label.closed_issues_count(options[:current_user])
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :open_merge_requests_count do |label, options|
|
|
|
|
label.open_merge_requests_count(options[:current_user])
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :priority do |label, options|
|
|
|
|
label.priority(options[:project])
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
expose :subscribed do |label, options|
|
2017-08-17 22:00:37 +05:30
|
|
|
label.subscribed?(options[:current_user], options[:project])
|
2016-06-02 11:05:42 +05:30
|
|
|
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
|
|
|
|
expose :lists, using: Entities::List do |board|
|
|
|
|
board.lists.destroyable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
class Compare < Grape::Entity
|
|
|
|
expose :commit, using: Entities::RepoCommit do |compare, options|
|
2015-09-11 14:41:01 +05:30
|
|
|
Commit.decorate(compare.commits, nil).last
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :commits, using: Entities::RepoCommit do |compare, options|
|
2015-09-11 14:41:01 +05:30
|
|
|
Commit.decorate(compare.commits, nil)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
expose :diffs, using: Entities::RepoDiff 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
|
|
|
|
expose :message, :starts_at, :ends_at, :color, :font
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
|
|
|
class ApplicationSetting < Grape::Entity
|
|
|
|
expose :id
|
2017-09-10 17:25:29 +05:30
|
|
|
expose(*::ApplicationSettingsHelper.visible_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) }
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :password_authentication_enabled, as: :signin_enabled
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2015-11-26 14:37:03 +05:30
|
|
|
|
|
|
|
class Release < Grape::Entity
|
|
|
|
expose :tag, as: :tag_name
|
|
|
|
expose :description
|
|
|
|
end
|
|
|
|
|
|
|
|
class RepoTag < Grape::Entity
|
2016-08-24 12:49:21 +05:30
|
|
|
expose :name, :message
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :commit, using: Entities::RepoCommit 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
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
expose :release, using: Entities::Release do |repo_tag, options|
|
|
|
|
options[:project].releases.find_by(tag: repo_tag.name)
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
end
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2016-01-19 16:12:03 +05:30
|
|
|
class Runner < Grape::Entity
|
|
|
|
expose :id
|
|
|
|
expose :description
|
|
|
|
expose :active
|
|
|
|
expose :is_shared
|
|
|
|
expose :name
|
|
|
|
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
|
2016-04-02 18:10:28 +05:30
|
|
|
expose :version, :revision, :platform, :architecture
|
|
|
|
expose :contacted_at
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :token, if: lambda { |runner, options| options[:current_user].admin? || !runner.is_shared? }
|
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
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class RunnerRegistrationDetails < Grape::Entity
|
|
|
|
expose :id, :token
|
|
|
|
end
|
|
|
|
|
|
|
|
class JobArtifactFile < Grape::Entity
|
2016-04-02 18:10:28 +05:30
|
|
|
expose :filename, :size
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
class PipelineBasic < Grape::Entity
|
|
|
|
expose :id, :sha, :ref, :status
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class Job < Grape::Entity
|
2016-01-19 16:12:03 +05:30
|
|
|
expose :id, :status, :stage, :name, :ref, :tag, :coverage
|
|
|
|
expose :created_at, :started_at, :finished_at
|
|
|
|
expose :user, with: User
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :artifacts_file, using: JobArtifactFile, if: -> (job, opts) { job.artifacts? }
|
2016-06-22 15:30:34 +05:30
|
|
|
expose :commit, with: RepoCommit
|
2016-01-19 16:12:03 +05:30
|
|
|
expose :runner, with: Runner
|
2016-11-03 12:29:30 +05:30
|
|
|
expose :pipeline, with: PipelineBasic
|
2016-01-19 16:12:03 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
class Trigger < Grape::Entity
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :id
|
|
|
|
expose :token, :description
|
|
|
|
expose :created_at, :updated_at, :deleted_at, :last_used
|
|
|
|
expose :owner, using: Entities::UserBasic
|
2016-01-19 16:12:03 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
class Variable < Grape::Entity
|
|
|
|
expose :key, :value
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :protected?, as: :protected
|
2016-01-19 16:12:03 +05:30
|
|
|
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
|
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
|
|
|
|
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
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
class Environment < EnvironmentBasic
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :project, using: Entities::BasicProjectDetails
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
class Deployment < Grape::Entity
|
|
|
|
expose :id, :iid, :ref, :sha, :created_at
|
|
|
|
expose :user, using: Entities::UserBasic
|
|
|
|
expose :environment, using: Entities::EnvironmentBasic
|
2017-08-17 22:00:37 +05:30
|
|
|
expose :deployable, using: Entities::Job
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
class RepoLicense < Grape::Entity
|
|
|
|
expose :key, :name, :nickname
|
|
|
|
expose :featured, as: :popular
|
|
|
|
expose :url, as: :html_url
|
|
|
|
expose(:source_url) { |license| license.meta['source'] }
|
|
|
|
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
|
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
|
|
|
|
|
|
|
|
class ImpersonationToken < PersonalAccessTokenWithToken
|
|
|
|
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
|
|
|
|
expose :ref_type do |model|
|
|
|
|
if model.tag
|
|
|
|
'tag'
|
|
|
|
else
|
|
|
|
'branch'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RunnerInfo < Grape::Entity
|
|
|
|
expose :timeout
|
|
|
|
end
|
|
|
|
|
|
|
|
class Step < Grape::Entity
|
|
|
|
expose :name, :script, :timeout, :when, :allow_failure
|
|
|
|
end
|
|
|
|
|
|
|
|
class Image < Grape::Entity
|
2017-09-10 17:25:29 +05:30
|
|
|
expose :name, :entrypoint
|
|
|
|
end
|
|
|
|
|
|
|
|
class Service < Image
|
|
|
|
expose :alias, :command
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
class Artifacts < Grape::Entity
|
|
|
|
expose :name, :untracked, :paths, :when, :expire_in
|
|
|
|
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 ArtifactFile < Grape::Entity
|
|
|
|
expose :filename, :size
|
|
|
|
end
|
|
|
|
|
|
|
|
class Dependency < Grape::Entity
|
|
|
|
expose :id, :name, :token
|
|
|
|
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-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
|
|
|
|
expose :dependencies, using: Dependency
|
|
|
|
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
|
|
|
|
|
|
|
|
class RepositoryStorageHealth < Grape::Entity
|
|
|
|
expose :storage_name
|
|
|
|
expose :failing_on_hosts
|
|
|
|
expose :total_failures
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|