2013-05-14 12:33:31 +00:00
|
|
|
module API
|
2012-06-27 11:32:56 +00:00
|
|
|
module Entities
|
2014-06-13 14:46:48 +00:00
|
|
|
class UserSafe < Grape::Entity
|
|
|
|
expose :name, :username
|
|
|
|
end
|
2014-02-13 13:45:24 +00:00
|
|
|
|
2014-06-13 14:46:48 +00:00
|
|
|
class UserBasic < UserSafe
|
|
|
|
expose :id, :state, :avatar_url
|
2015-07-30 09:56:15 +00:00
|
|
|
|
|
|
|
expose :web_url do |user, options|
|
2015-08-26 01:42:46 +00:00
|
|
|
Gitlab::Application.routes.url_helpers.user_url(user)
|
2015-07-30 09:56:15 +00:00
|
|
|
end
|
2012-06-27 11:32:56 +00:00
|
|
|
end
|
2012-06-27 12:51:39 +00:00
|
|
|
|
2014-06-13 14:46:48 +00:00
|
|
|
class User < UserBasic
|
|
|
|
expose :created_at
|
|
|
|
expose :is_admin?, as: :is_admin
|
|
|
|
expose :bio, :skype, :linkedin, :twitter, :website_url
|
2013-03-11 12:35:00 +00:00
|
|
|
end
|
|
|
|
|
2014-11-27 11:34:39 +00:00
|
|
|
class Identity < Grape::Entity
|
|
|
|
expose :provider, :extern_uid
|
|
|
|
end
|
|
|
|
|
2014-06-13 14:46:48 +00:00
|
|
|
class UserFull < User
|
|
|
|
expose :email
|
2015-02-09 12:52:42 +00:00
|
|
|
expose :theme_id, :color_scheme_id, :projects_limit, :current_sign_in_at
|
2014-11-27 11:34:39 +00:00
|
|
|
expose :identities, using: Entities::Identity
|
2014-06-13 14:46:48 +00:00
|
|
|
expose :can_create_group?, as: :can_create_group
|
|
|
|
expose :can_create_project?, as: :can_create_project
|
2015-06-24 05:36:35 +00:00
|
|
|
expose :two_factor_enabled
|
2012-07-05 13:47:00 +00:00
|
|
|
end
|
|
|
|
|
2014-06-13 14:46:48 +00:00
|
|
|
class UserLogin < UserFull
|
2012-09-20 15:36:43 +00:00
|
|
|
expose :private_token
|
2012-09-20 14:44:44 +00:00
|
|
|
end
|
|
|
|
|
2015-07-29 13:40:08 +00:00
|
|
|
class Email < Grape::Entity
|
|
|
|
expose :id, :email
|
|
|
|
end
|
|
|
|
|
2012-09-08 17:51:12 +00:00
|
|
|
class Hook < Grape::Entity
|
2012-11-29 22:59:56 +00:00
|
|
|
expose :id, :url, :created_at
|
2012-09-08 17:51:12 +00:00
|
|
|
end
|
|
|
|
|
2013-12-04 11:19:53 +00:00
|
|
|
class ProjectHook < Hook
|
2014-09-19 08:23:18 +00:00
|
|
|
expose :project_id, :push_events
|
2015-09-24 16:33:11 +00:00
|
|
|
expose :issues_events, :merge_requests_events, :tag_push_events, :note_events, :enable_ssl_verification
|
2013-12-04 11:19:53 +00:00
|
|
|
end
|
|
|
|
|
2013-06-27 21:49:26 +00:00
|
|
|
class ForkedFromProject < Grape::Entity
|
|
|
|
expose :id
|
|
|
|
expose :name, :name_with_namespace
|
|
|
|
expose :path, :path_with_namespace
|
|
|
|
end
|
|
|
|
|
2012-06-27 12:51:39 +00:00
|
|
|
class Project < Grape::Entity
|
2015-02-05 01:42:34 +00:00
|
|
|
expose :id, :description, :default_branch, :tag_list
|
2013-11-06 15:13:21 +00:00
|
|
|
expose :public?, as: :public
|
2014-04-18 15:55:06 +00:00
|
|
|
expose :archived?, as: :archived
|
2013-11-06 15:13:21 +00:00
|
|
|
expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url
|
2014-03-17 12:33:41 +00:00
|
|
|
expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group }
|
2013-06-03 16:49:04 +00:00
|
|
|
expose :name, :name_with_namespace
|
2013-01-31 07:11:35 +00:00
|
|
|
expose :path, :path_with_namespace
|
2014-06-13 11:24:54 +00:00
|
|
|
expose :issues_enabled, :merge_requests_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at
|
2015-04-10 16:35:05 +00:00
|
|
|
expose :creator_id
|
2013-01-02 20:31:20 +00:00
|
|
|
expose :namespace
|
2015-02-03 03:30:09 +00:00
|
|
|
expose :forked_from_project, using: Entities::ForkedFromProject, if: lambda{ | project, options | project.forked? }
|
2015-02-28 17:07:53 +00:00
|
|
|
expose :avatar_url
|
2015-07-28 13:49:44 +00:00
|
|
|
expose :star_count, :forks_count
|
2012-06-27 12:51:39 +00:00
|
|
|
end
|
|
|
|
|
2012-09-21 10:23:17 +00:00
|
|
|
class ProjectMember < UserBasic
|
2014-09-15 08:55:36 +00:00
|
|
|
expose :access_level do |user, options|
|
|
|
|
options[:project].project_members.find_by(user_id: user.id).access_level
|
2012-09-21 10:23:17 +00:00
|
|
|
end
|
2012-09-06 20:49:29 +00:00
|
|
|
end
|
|
|
|
|
2013-01-08 21:05:00 +00:00
|
|
|
class Group < Grape::Entity
|
2015-02-18 00:23:44 +00:00
|
|
|
expose :id, :name, :path, :description
|
2015-07-30 09:56:15 +00:00
|
|
|
expose :avatar_url
|
|
|
|
|
|
|
|
expose :web_url do |group, options|
|
2015-08-26 01:42:46 +00:00
|
|
|
Gitlab::Application.routes.url_helpers.group_url(group)
|
2015-07-30 09:56:15 +00:00
|
|
|
end
|
2013-01-08 21:05:00 +00:00
|
|
|
end
|
2013-02-18 09:10:58 +00:00
|
|
|
|
2013-02-03 18:38:33 +00:00
|
|
|
class GroupDetail < Group
|
2013-01-08 21:05:00 +00:00
|
|
|
expose :projects, using: Entities::Project
|
|
|
|
end
|
|
|
|
|
2013-09-04 15:19:03 +00:00
|
|
|
class GroupMember < UserBasic
|
2014-09-15 08:55:36 +00:00
|
|
|
expose :access_level do |user, options|
|
2014-09-15 13:45:28 +00:00
|
|
|
options[:group].group_members.find_by(user_id: user.id).access_level
|
2013-09-04 15:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-25 02:30:06 +00:00
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2012-07-06 13:08:17 +00:00
|
|
|
class RepoObject < Grape::Entity
|
2014-02-04 12:46:15 +00:00
|
|
|
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
|
|
|
|
|
2013-01-28 17:22:44 +00:00
|
|
|
expose :protected do |repo, options|
|
|
|
|
if options[:project]
|
|
|
|
options[:project].protected_branch? repo.name
|
|
|
|
end
|
|
|
|
end
|
2012-06-27 12:51:39 +00:00
|
|
|
end
|
2012-06-29 13:34:08 +00:00
|
|
|
|
2014-02-04 12:46:15 +00: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
|
|
|
|
|
2012-09-21 11:34:07 +00:00
|
|
|
class RepoCommit < Grape::Entity
|
|
|
|
expose :id, :short_id, :title, :author_name, :author_email, :created_at
|
2014-07-01 19:05:29 +00:00
|
|
|
expose :safe_message, as: :message
|
2012-09-21 11:34:07 +00:00
|
|
|
end
|
|
|
|
|
2013-12-11 13:41:07 +00:00
|
|
|
class RepoCommitDetail < RepoCommit
|
|
|
|
expose :parent_ids, :committed_date, :authored_date
|
|
|
|
end
|
|
|
|
|
2012-06-29 13:34:08 +00:00
|
|
|
class ProjectSnippet < Grape::Entity
|
|
|
|
expose :id, :title, :file_name
|
2012-08-10 22:07:50 +00:00
|
|
|
expose :author, using: Entities::UserBasic
|
2012-06-29 13:34:08 +00:00
|
|
|
expose :expires_at, :updated_at, :created_at
|
|
|
|
end
|
2012-07-24 12:19:51 +00:00
|
|
|
|
2013-10-14 13:39:54 +00:00
|
|
|
class ProjectEntity < Grape::Entity
|
|
|
|
expose :id, :iid
|
2015-03-03 02:45:28 +00:00
|
|
|
expose(:project_id) { |entity| entity.project.id }
|
2014-04-09 15:24:12 +00:00
|
|
|
expose :title, :description
|
|
|
|
expose :state, :created_at, :updated_at
|
2013-10-14 13:39:54 +00:00
|
|
|
end
|
|
|
|
|
2015-02-02 21:08:10 +00:00
|
|
|
class RepoDiff < Grape::Entity
|
|
|
|
expose :old_path, :new_path, :a_mode, :b_mode, :diff
|
|
|
|
expose :new_file, :renamed_file, :deleted_file
|
|
|
|
end
|
|
|
|
|
2013-10-14 13:39:54 +00:00
|
|
|
class Milestone < ProjectEntity
|
2014-04-09 15:24:12 +00:00
|
|
|
expose :due_date
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
|
|
|
|
2013-10-14 13:39:54 +00:00
|
|
|
class Issue < ProjectEntity
|
2014-07-30 14:17:29 +00:00
|
|
|
expose :label_names, as: :labels
|
2012-08-10 22:07:50 +00:00
|
|
|
expose :milestone, using: Entities::Milestone
|
|
|
|
expose :assignee, :author, using: Entities::UserBasic
|
2012-07-24 12:19:51 +00:00
|
|
|
end
|
2012-09-16 14:52:06 +00:00
|
|
|
|
2013-10-14 13:39:54 +00:00
|
|
|
class MergeRequest < ProjectEntity
|
2014-04-09 15:24:12 +00:00
|
|
|
expose :target_branch, :source_branch, :upvotes, :downvotes
|
2013-10-14 13:39:54 +00:00
|
|
|
expose :author, :assignee, using: Entities::UserBasic
|
|
|
|
expose :source_project_id, :target_project_id
|
2014-07-30 14:17:29 +00:00
|
|
|
expose :label_names, as: :labels
|
2014-04-16 02:14:05 +00:00
|
|
|
expose :description
|
2015-07-09 17:21:37 +00:00
|
|
|
expose :work_in_progress?, as: :work_in_progress
|
2014-04-16 02:14:05 +00:00
|
|
|
expose :milestone, using: Entities::Milestone
|
2012-09-16 14:52:06 +00:00
|
|
|
end
|
2012-10-21 11:00:27 +00:00
|
|
|
|
2015-02-02 21:08:10 +00:00
|
|
|
class MergeRequestChanges < MergeRequest
|
|
|
|
expose :diffs, as: :changes, using: Entities::RepoDiff do |compare, _|
|
|
|
|
compare.diffs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-14 13:39:54 +00:00
|
|
|
class SSHKey < Grape::Entity
|
|
|
|
expose :id, :title, :key, :created_at
|
2012-10-21 11:00:27 +00:00
|
|
|
end
|
2012-10-21 16:48:56 +00:00
|
|
|
|
2015-08-29 09:52:21 +00:00
|
|
|
class SSHKeyWithUser < SSHKey
|
|
|
|
expose :user, using: Entities::UserFull
|
|
|
|
end
|
|
|
|
|
2012-10-21 16:48:56 +00:00
|
|
|
class Note < Grape::Entity
|
2012-11-27 19:43:39 +00:00
|
|
|
expose :id
|
|
|
|
expose :note, as: :body
|
2013-03-19 11:28:29 +00:00
|
|
|
expose :attachment_identifier, as: :attachment
|
2012-10-21 16:48:56 +00:00
|
|
|
expose :author, using: Entities::UserBasic
|
2012-11-29 22:41:24 +00:00
|
|
|
expose :created_at
|
2015-08-12 19:39:58 +00:00
|
|
|
expose :system?, as: :system
|
|
|
|
expose :upvote?, as: :upvote
|
|
|
|
expose :downvote?, as: :downvote
|
2012-10-21 16:48:56 +00:00
|
|
|
end
|
2012-11-29 20:10:07 +00:00
|
|
|
|
|
|
|
class MRNote < Grape::Entity
|
|
|
|
expose :note
|
|
|
|
expose :author, using: Entities::UserBasic
|
|
|
|
end
|
2013-06-06 16:19:17 +00:00
|
|
|
|
2014-06-27 14:48:30 +00:00
|
|
|
class CommitNote < Grape::Entity
|
|
|
|
expose :note
|
|
|
|
expose(:path) { |note| note.diff_file_name }
|
|
|
|
expose(:line) { |note| note.diff_new_line }
|
|
|
|
expose(:line_type) { |note| note.diff_line_type }
|
|
|
|
expose :author, using: Entities::UserBasic
|
2015-08-19 06:29:18 +00:00
|
|
|
expose :created_at
|
2014-06-27 14:48:30 +00:00
|
|
|
end
|
|
|
|
|
2013-06-06 16:19:17 +00:00
|
|
|
class Event < Grape::Entity
|
|
|
|
expose :title, :project_id, :action_name
|
|
|
|
expose :target_id, :target_type, :author_id
|
|
|
|
expose :data, :target_title
|
2014-04-09 15:24:12 +00:00
|
|
|
expose :created_at
|
2014-10-31 10:08:45 +00:00
|
|
|
|
|
|
|
expose :author_username do |event, options|
|
|
|
|
if event.author
|
|
|
|
event.author.username
|
|
|
|
end
|
|
|
|
end
|
2013-06-06 16:19:17 +00:00
|
|
|
end
|
2013-11-15 13:24:10 +00:00
|
|
|
|
|
|
|
class Namespace < Grape::Entity
|
|
|
|
expose :id, :path, :kind
|
|
|
|
end
|
2014-03-17 12:33:41 +00:00
|
|
|
|
|
|
|
class ProjectAccess < Grape::Entity
|
2014-09-15 08:55:36 +00:00
|
|
|
expose :access_level
|
2014-03-17 12:33:41 +00:00
|
|
|
expose :notification_level
|
|
|
|
end
|
|
|
|
|
|
|
|
class GroupAccess < Grape::Entity
|
2014-09-15 08:55:36 +00:00
|
|
|
expose :access_level
|
2014-03-17 12:33:41 +00:00
|
|
|
expose :notification_level
|
|
|
|
end
|
|
|
|
|
|
|
|
class ProjectWithAccess < Project
|
|
|
|
expose :permissions do
|
|
|
|
expose :project_access, using: Entities::ProjectAccess do |project, options|
|
2014-09-14 16:32:51 +00:00
|
|
|
project.project_members.find_by(user_id: options[:user].id)
|
2014-03-17 12:33:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :group_access, using: Entities::GroupAccess do |project, options|
|
2014-03-17 13:14:27 +00:00
|
|
|
if project.group
|
2014-09-14 16:32:51 +00:00
|
|
|
project.group.group_members.find_by(user_id: options[:user].id)
|
2014-03-17 13:14:27 +00:00
|
|
|
end
|
2014-03-17 12:33:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-03-21 09:18:19 +00:00
|
|
|
|
|
|
|
class Label < Grape::Entity
|
2014-08-12 12:16:25 +00:00
|
|
|
expose :name, :color
|
2014-03-21 09:18:19 +00:00
|
|
|
end
|
2014-05-26 13:08:22 +00:00
|
|
|
|
|
|
|
class Compare < Grape::Entity
|
|
|
|
expose :commit, using: Entities::RepoCommit do |compare, options|
|
2015-04-21 13:09:15 +00:00
|
|
|
Commit.decorate(compare.commits, nil).last
|
2014-05-26 13:08:22 +00:00
|
|
|
end
|
2014-07-29 11:29:59 +00:00
|
|
|
|
2014-05-26 13:08:22 +00:00
|
|
|
expose :commits, using: Entities::RepoCommit do |compare, options|
|
2015-04-21 13:09:15 +00:00
|
|
|
Commit.decorate(compare.commits, nil)
|
2014-05-26 13:08:22 +00:00
|
|
|
end
|
2014-07-29 11:29:59 +00:00
|
|
|
|
2014-05-26 13:08:22 +00:00
|
|
|
expose :diffs, using: Entities::RepoDiff do |compare, options|
|
|
|
|
compare.diffs
|
|
|
|
end
|
2014-05-27 08:16:50 +00:00
|
|
|
|
|
|
|
expose :compare_timeout do |compare, options|
|
|
|
|
compare.timeout
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :same, as: :compare_same_ref
|
2014-05-26 13:08:22 +00:00
|
|
|
end
|
2014-07-02 12:09:06 +00:00
|
|
|
|
|
|
|
class Contributor < Grape::Entity
|
|
|
|
expose :name, :email, :commits, :additions, :deletions
|
|
|
|
end
|
2015-02-07 15:41:30 +00:00
|
|
|
|
|
|
|
class BroadcastMessage < Grape::Entity
|
|
|
|
expose :message, :starts_at, :ends_at, :color, :font
|
|
|
|
end
|
2015-07-03 14:50:21 +00:00
|
|
|
|
|
|
|
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 :twitter_sharing_enabled
|
|
|
|
expose :restricted_visibility_levels
|
|
|
|
expose :max_attachment_size
|
|
|
|
expose :session_expire_delay
|
|
|
|
expose :default_project_visibility
|
|
|
|
expose :default_snippet_visibility
|
|
|
|
expose :restricted_signup_domains
|
|
|
|
expose :user_oauth_applications
|
|
|
|
expose :after_sign_out_path
|
|
|
|
end
|
2012-06-27 11:32:56 +00:00
|
|
|
end
|
|
|
|
end
|