gitlab-org--gitlab-foss/lib/api/entities.rb

461 lines
14 KiB
Ruby
Raw Normal View History

module API
2012-06-27 07:32:56 -04:00
module Entities
class UserSafe < Grape::Entity
expose :name, :username
end
class UserBasic < UserSafe
expose :id, :state, :avatar_url
2015-07-30 05:56:15 -04:00
expose :web_url do |user, options|
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
class User < UserBasic
expose :created_at
expose :is_admin?, as: :is_admin
2016-04-05 19:57:21 -04:00
expose :bio, :location, :skype, :linkedin, :twitter, :website_url
end
class Identity < Grape::Entity
expose :provider, :extern_uid
end
class UserFull < User
expose :last_sign_in_at
expose :confirmed_at
expose :email
2015-02-09 07:52:42 -05:00
expose :theme_id, :color_scheme_id, :projects_limit, :current_sign_in_at
expose :identities, using: Entities::Identity
expose :can_create_group?, as: :can_create_group
expose :can_create_project?, as: :can_create_project
expose :two_factor_enabled
2016-03-14 19:11:20 -04:00
expose :external
end
class UserLogin < UserFull
expose :private_token
end
class Email < Grape::Entity
expose :id, :email
end
2012-09-08 13:51:12 -04:00
class Hook < Grape::Entity
expose :id, :url, :created_at
2012-09-08 13:51:12 -04:00
end
class ProjectHook < Hook
expose :project_id, :push_events
expose :issues_events, :merge_requests_events, :tag_push_events, :note_events, :build_events
expose :enable_ssl_verification
end
class BasicProjectDetails < Grape::Entity
expose :id
expose :name, :name_with_namespace
expose :path, :path_with_namespace
end
2012-06-27 08:51:39 -04:00
class Project < Grape::Entity
expose :id, :description, :default_branch, :tag_list
expose :public?, as: :public
expose :archived?, as: :archived
expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url
expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group }
expose :name, :name_with_namespace
expose :path, :path_with_namespace
expose :issues_enabled, :merge_requests_enabled, :wiki_enabled, :builds_enabled, :snippets_enabled, :container_registry_enabled
2016-04-18 08:23:17 -04:00
expose :created_at, :last_activity_at
2015-12-04 06:55:23 -05:00
expose :shared_runners_enabled
expose :creator_id
expose :namespace
expose :forked_from_project, using: Entities::BasicProjectDetails, if: lambda{ |project, options| project.forked? }
expose :avatar_url
expose :star_count, :forks_count
2015-12-16 14:40:16 -05:00
expose :open_issues_count, if: lambda { |project, options| project.issues_enabled? && project.default_issues_tracker? }
2016-01-11 09:27:20 -05:00
expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] }
expose :public_builds
2012-06-27 08:51:39 -04:00
end
2012-09-21 06:23:17 -04:00
class ProjectMember < UserBasic
expose :access_level do |user, options|
options[:project].project_members.find_by(user_id: user.id).access_level
2012-09-21 06:23:17 -04:00
end
2012-09-06 16:49:29 -04:00
end
class Group < Grape::Entity
2016-03-18 08:28:16 -04:00
expose :id, :name, :path, :description, :visibility_level
2015-07-30 05:56:15 -04:00
expose :avatar_url
expose :web_url do |group, options|
Gitlab::Routing.url_helpers.group_url(group)
2015-07-30 05:56:15 -04:00
end
end
2013-02-18 04:10:58 -05:00
class GroupDetail < Group
expose :projects, using: Entities::Project
end
class GroupMember < UserBasic
expose :access_level do |user, options|
options[:group].group_members.find_by(user_id: user.id).access_level
end
end
2012-07-06 09:08:17 -04:00
class RepoObject < Grape::Entity
expose :name
expose :commit do |repo_obj, options|
if repo_obj.respond_to?(:commit)
repo_obj.commit
elsif options[:project]
options[:project].repository.commit(repo_obj.target)
end
end
expose :protected do |repo, options|
if options[:project]
options[:project].protected_branch? repo.name
end
end
2012-06-27 08:51:39 -04:00
end
2012-06-29 09:34:08 -04:00
class RepoTreeObject < Grape::Entity
expose :id, :name, :type
expose :mode do |obj, options|
filemode = obj.mode.to_s(8)
filemode = "0" + filemode if filemode.length < 6
filemode
end
end
class RepoCommit < Grape::Entity
expose :id, :short_id, :title, :author_name, :author_email, :created_at
expose :safe_message, as: :message
end
class RepoCommitDetail < RepoCommit
expose :parent_ids, :committed_date, :authored_date
2015-10-06 06:01:16 -04:00
expose :status
end
2012-06-29 09:34:08 -04:00
class ProjectSnippet < Grape::Entity
expose :id, :title, :file_name
expose :author, using: Entities::UserBasic
expose :updated_at, :created_at
# TODO (rspeicher): Deprecated; remove in 9.0
expose(:expires_at) { |snippet| nil }
2012-06-29 09:34:08 -04:00
end
2012-07-24 08:19:51 -04:00
class ProjectEntity < Grape::Entity
expose :id, :iid
expose(:project_id) { |entity| entity.project.id }
expose :title, :description
expose :state, :created_at, :updated_at
end
class RepoDiff < Grape::Entity
expose :old_path, :new_path, :a_mode, :b_mode, :diff
expose :new_file, :renamed_file, :deleted_file
end
class Milestone < ProjectEntity
expose :due_date
2012-07-24 08:19:51 -04:00
end
class Issue < ProjectEntity
expose :label_names, as: :labels
expose :milestone, using: Entities::Milestone
expose :assignee, :author, using: Entities::UserBasic
2016-04-08 02:41:10 -04:00
expose :subscribed do |issue, options|
issue.subscribed?(options[:current_user])
end
2016-02-23 16:59:32 -05:00
expose :user_notes_count
2012-07-24 08:19:51 -04:00
end
2012-09-16 10:52:06 -04:00
class MergeRequest < ProjectEntity
2015-11-11 08:12:51 -05:00
expose :target_branch, :source_branch
expose :upvotes, :downvotes
expose :author, :assignee, using: Entities::UserBasic
expose :source_project_id, :target_project_id
expose :label_names, as: :labels
expose :description
2015-07-09 13:21:37 -04:00
expose :work_in_progress?, as: :work_in_progress
expose :milestone, using: Entities::Milestone
2015-11-24 08:59:02 -05:00
expose :merge_when_build_succeeds
expose :merge_status
2016-04-08 02:41:10 -04:00
expose :subscribed do |merge_request, options|
merge_request.subscribed?(options[:current_user])
end
expose :user_notes_count
2012-09-16 10:52:06 -04:00
end
2012-10-21 07:00:27 -04:00
class MergeRequestChanges < MergeRequest
expose :diffs, as: :changes, using: Entities::RepoDiff do |compare, _|
2016-03-03 12:38:44 -05:00
compare.diffs(all_diffs: true).to_a
end
end
class SSHKey < Grape::Entity
expose :id, :title, :key, :created_at
2012-10-21 07:00:27 -04:00
end
2012-10-21 12:48:56 -04:00
class SSHKeyWithUser < SSHKey
expose :user, using: Entities::UserFull
end
2012-10-21 12:48:56 -04:00
class Note < Grape::Entity
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
expose :system?, as: :system
expose :noteable_id, :noteable_type
# upvote? and downvote? are deprecated, always return false
expose :upvote?, as: :upvote
expose :downvote?, as: :downvote
2012-10-21 12:48:56 -04:00
end
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-05-13 15:53:31 -04:00
expose(:path) { |note| note.diff_file_path if note.legacy_diff_note? }
2016-05-10 18:41:46 -04:00
expose(:line) { |note| note.diff_new_line if note.legacy_diff_note? }
expose(:line_type) { |note| note.diff_line_type if note.legacy_diff_note? }
2014-06-27 10:48:30 -04:00
expose :author, using: Entities::UserBasic
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,
:created_at, :started_at, :finished_at, :allow_failure
2015-10-12 06:15:48 -04:00
expose :author, using: Entities::UserBasic
2015-10-06 06:01:16 -04:00
end
2013-06-06 12:19:17 -04:00
class Event < Grape::Entity
expose :title, :project_id, :action_name
expose :target_id, :target_type, :author_id
expose :data, :target_title
expose :created_at
expose :note, using: Entities::Note, if: ->(event, options) { event.note? }
expose :author, using: Entities::UserBasic, if: ->(event, options) { event.author }
expose :author_username do |event, options|
if event.author
event.author.username
end
end
2013-06-06 12:19:17 -04:00
end
class ProjectGroupLink < Grape::Entity
expose :id, :project_id, :group_id, :group_access
end
class Namespace < Grape::Entity
expose :id, :path, :kind
end
class Member < Grape::Entity
expose :access_level
expose :notification_level do |member, options|
if member.notification_setting
NotificationSetting.levels[member.notification_setting.level]
end
end
end
class ProjectAccess < Member
end
class GroupAccess < Member
end
class ProjectService < Grape::Entity
expose :id, :title, :created_at, :updated_at, :active
expose :push_events, :issues_events, :merge_requests_events, :tag_push_events, :note_events, :build_events
# Expose serialized properties
expose :properties do |service, options|
field_names = service.fields.
select { |field| options[:include_passwords] || field[:type] != 'password' }.
map { |field| field[:name] }
service.properties.slice(*field_names)
end
end
class ProjectWithAccess < Project
expose :permissions do
expose :project_access, using: Entities::ProjectAccess do |project, options|
project.project_members.find_by(user_id: options[:user].id)
end
expose :group_access, using: Entities::GroupAccess do |project, options|
if project.group
project.group.group_members.find_by(user_id: options[:user].id)
end
end
end
end
class Label < Grape::Entity
2016-03-24 14:38:37 -04:00
expose :name, :color, :description
expose :open_issues_count, :closed_issues_count, :open_merge_requests_count
expose :subscribed do |label, options|
label.subscribed?(options[:current_user])
end
end
class Compare < Grape::Entity
expose :commit, using: Entities::RepoCommit do |compare, options|
Commit.decorate(compare.commits, nil).last
end
expose :commits, using: Entities::RepoCommit do |compare, options|
Commit.decorate(compare.commits, nil)
end
expose :diffs, using: Entities::RepoDiff do |compare, options|
2016-03-03 12:38:44 -05:00
compare.diffs(all_diffs: true).to_a
end
expose :compare_timeout do |compare, options|
2016-03-03 12:38:44 -05:00
compare.diffs.overflow?
end
expose :same, as: :compare_same_ref
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
class ApplicationSetting < Grape::Entity
expose :id
expose :default_projects_limit
expose :signup_enabled
expose :signin_enabled
expose :gravatar_enabled
expose :sign_in_text
expose :created_at
expose :updated_at
expose :home_page_url
expose :default_branch_protection
expose :restricted_visibility_levels
expose :max_attachment_size
expose :session_expire_delay
expose :default_project_visibility
expose :default_snippet_visibility
expose :default_group_visibility
expose :restricted_signup_domains
expose :user_oauth_applications
expose :after_sign_out_path
end
class Release < Grape::Entity
expose :tag, as: :tag_name
expose :description
end
class RepoTag < Grape::Entity
expose :name
expose :message do |repo_obj, _options|
if repo_obj.respond_to?(:message)
repo_obj.message
else
nil
end
end
expose :commit do |repo_obj, options|
if repo_obj.respond_to?(:commit)
repo_obj.commit
elsif options[:project]
options[:project].repository.commit(repo_obj.target)
end
end
expose :release, using: Entities::Release do |repo_obj, options|
if options[:project]
options[:project].releases.find_by(tag: repo_obj.name)
end
end
end
2015-12-10 12:04:40 -05:00
class TriggerRequest < Grape::Entity
expose :id, :variables
end
2016-01-04 10:38:32 -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
class RunnerDetails < Runner
expose :tag_list
expose :version, :revision, :platform, :architecture
expose :contacted_at
expose :token, if: lambda { |runner, options| options[:current_user].is_admin? || !runner.is_shared? }
expose :projects, with: Entities::BasicProjectDetails do |runner, options|
if options[:current_user].is_admin?
runner.projects
else
options[:current_user].authorized_projects.where(id: runner.projects)
end
end
end
class BuildArtifactFile < Grape::Entity
expose :filename, :size
end
class Build < 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
2016-02-19 12:07:05 -05:00
expose :artifacts_file, using: BuildArtifactFile, if: -> (build, opts) { build.artifacts? }
2016-01-08 16:57:42 -05:00
expose :commit, with: RepoCommit do |repo_obj, _options|
if repo_obj.respond_to?(:commit)
repo_obj.commit.commit_data
end
end
expose :runner, with: Runner
end
2016-01-04 10:38:32 -05:00
class Trigger < Grape::Entity
2016-01-13 06:16:27 -05:00
expose :token, :created_at, :updated_at, :deleted_at, :last_used
2016-01-04 10:38:32 -05:00
end
class Variable < Grape::Entity
2016-01-07 08:10:49 -05:00
expose :key, :value
end
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
2012-06-27 07:32:56 -04:00
end
end