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
|
|
|
|
expose :id, :state, :avatar_url
|
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
|
|
|
|
expose :is_admin?, as: :is_admin
|
|
|
|
expose :bio, :skype, :linkedin, :twitter, :website_url
|
2013-03-11 08:35:00 -04:00
|
|
|
end
|
|
|
|
|
2014-06-13 10:46:48 -04:00
|
|
|
class UserFull < User
|
|
|
|
expose :email
|
|
|
|
expose :theme_id, :color_scheme_id, :extern_uid, :provider
|
|
|
|
expose :can_create_group?, as: :can_create_group
|
|
|
|
expose :can_create_project?, as: :can_create_project
|
2012-07-05 09:47:00 -04:00
|
|
|
end
|
|
|
|
|
2014-06-13 10:46:48 -04:00
|
|
|
class UserLogin < UserFull
|
2012-09-20 11:36:43 -04:00
|
|
|
expose :private_token
|
2012-09-20 10:44:44 -04:00
|
|
|
end
|
|
|
|
|
2012-09-08 13:51:12 -04:00
|
|
|
class Hook < Grape::Entity
|
2012-11-29 17:59:56 -05:00
|
|
|
expose :id, :url, :created_at
|
2012-09-08 13:51:12 -04:00
|
|
|
end
|
|
|
|
|
2013-12-04 06:19:53 -05:00
|
|
|
class ProjectHook < Hook
|
|
|
|
expose :project_id, :push_events, :issues_events, :merge_requests_events
|
|
|
|
end
|
|
|
|
|
2013-06-27 17:49:26 -04:00
|
|
|
class ForkedFromProject < 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
|
2013-11-06 10:13:21 -05:00
|
|
|
expose :id, :description, :default_branch
|
|
|
|
expose :public?, as: :public
|
2014-04-18 11:55:06 -04:00
|
|
|
expose :archived?, as: :archived
|
2013-11-06 10:13:21 -05:00
|
|
|
expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url
|
2014-03-17 08:33:41 -04:00
|
|
|
expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group }
|
2013-06-03 12:49:04 -04:00
|
|
|
expose :name, :name_with_namespace
|
2013-01-31 02:11:35 -05:00
|
|
|
expose :path, :path_with_namespace
|
2014-06-13 07:24:54 -04:00
|
|
|
expose :issues_enabled, :merge_requests_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at
|
2013-01-02 15:31:20 -05:00
|
|
|
expose :namespace
|
2013-06-27 17:49:26 -04:00
|
|
|
expose :forked_from_project, using: Entities::ForkedFromProject, :if => lambda{ | project, options | project.forked? }
|
2012-06-27 08:51:39 -04:00
|
|
|
end
|
|
|
|
|
2012-09-21 06:23:17 -04:00
|
|
|
class ProjectMember < UserBasic
|
2013-03-18 16:11:28 -04:00
|
|
|
expose :project_access, as: :access_level do |user, options|
|
2014-01-19 13:55:59 -05:00
|
|
|
options[:project].users_projects.find_by(user_id: user.id).project_access
|
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
|
2013-02-01 09:00:12 -05:00
|
|
|
expose :id, :name, :path, :owner_id
|
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
|
|
|
|
end
|
|
|
|
|
2013-09-04 11:19:03 -04:00
|
|
|
class GroupMember < UserBasic
|
|
|
|
expose :group_access, as: :access_level do |user, options|
|
2014-01-19 13:55:59 -05:00
|
|
|
options[:group].users_groups.find_by(user_id: user.id).group_access
|
2013-09-04 11:19:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-06 09:08:17 -04:00
|
|
|
class RepoObject < Grape::Entity
|
2014-02-04 07:46:15 -05: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 12:22:44 -05:00
|
|
|
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
|
|
|
|
2014-02-04 07:46:15 -05: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 07:34:07 -04:00
|
|
|
class RepoCommit < Grape::Entity
|
|
|
|
expose :id, :short_id, :title, :author_name, :author_email, :created_at
|
|
|
|
end
|
|
|
|
|
2013-12-11 08:41:07 -05:00
|
|
|
class RepoCommitDetail < RepoCommit
|
|
|
|
expose :parent_ids, :committed_date, :authored_date
|
|
|
|
end
|
|
|
|
|
2012-06-29 09:34:08 -04:00
|
|
|
class ProjectSnippet < Grape::Entity
|
|
|
|
expose :id, :title, :file_name
|
2012-08-10 18:07:50 -04:00
|
|
|
expose :author, using: Entities::UserBasic
|
2012-06-29 09:34:08 -04:00
|
|
|
expose :expires_at, :updated_at, :created_at
|
|
|
|
end
|
2012-07-24 08:19:51 -04:00
|
|
|
|
2013-10-14 09:39:54 -04:00
|
|
|
class ProjectEntity < Grape::Entity
|
|
|
|
expose :id, :iid
|
|
|
|
expose (:project_id) { |entity| entity.project.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
|
|
|
|
|
|
|
|
class Milestone < ProjectEntity
|
2014-04-09 11:24:12 -04:00
|
|
|
expose :due_date
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
|
2013-10-14 09:39:54 -04:00
|
|
|
class Issue < ProjectEntity
|
2012-08-10 18:07:50 -04:00
|
|
|
expose :label_list, as: :labels
|
|
|
|
expose :milestone, using: Entities::Milestone
|
|
|
|
expose :assignee, :author, using: Entities::UserBasic
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
2012-09-16 10:52:06 -04:00
|
|
|
|
2013-10-14 09:39:54 -04:00
|
|
|
class MergeRequest < ProjectEntity
|
2014-04-09 11:24:12 -04:00
|
|
|
expose :target_branch, :source_branch, :upvotes, :downvotes
|
2013-10-14 09:39:54 -04:00
|
|
|
expose :author, :assignee, using: Entities::UserBasic
|
|
|
|
expose :source_project_id, :target_project_id
|
2014-04-14 21:12:07 -04:00
|
|
|
expose :label_list, as: :labels
|
2012-09-16 10:52:06 -04:00
|
|
|
end
|
2012-10-21 07:00:27 -04:00
|
|
|
|
2013-10-14 09:39:54 -04:00
|
|
|
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 Note < Grape::Entity
|
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
|
2012-11-29 17:41:24 -05:00
|
|
|
expose :created_at
|
2012-10-21 12:48:56 -04:00
|
|
|
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
|
|
|
|
|
|
|
class Event < Grape::Entity
|
|
|
|
expose :title, :project_id, :action_name
|
|
|
|
expose :target_id, :target_type, :author_id
|
|
|
|
expose :data, :target_title
|
2014-04-09 11:24:12 -04:00
|
|
|
expose :created_at
|
2013-06-06 12:19:17 -04:00
|
|
|
end
|
2013-11-15 08:24:10 -05:00
|
|
|
|
|
|
|
class Namespace < Grape::Entity
|
|
|
|
expose :id, :path, :kind
|
|
|
|
end
|
2014-03-17 08:33:41 -04:00
|
|
|
|
|
|
|
class ProjectAccess < Grape::Entity
|
|
|
|
expose :project_access, as: :access_level
|
|
|
|
expose :notification_level
|
|
|
|
end
|
|
|
|
|
|
|
|
class GroupAccess < Grape::Entity
|
|
|
|
expose :group_access, as: :access_level
|
|
|
|
expose :notification_level
|
|
|
|
end
|
|
|
|
|
|
|
|
class ProjectWithAccess < Project
|
|
|
|
expose :permissions do
|
|
|
|
expose :project_access, using: Entities::ProjectAccess do |project, options|
|
|
|
|
project.users_projects.find_by(user_id: options[:user].id)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :group_access, using: Entities::GroupAccess do |project, options|
|
2014-03-17 09:14:27 -04:00
|
|
|
if project.group
|
|
|
|
project.group.users_groups.find_by(user_id: options[:user].id)
|
|
|
|
end
|
2014-03-17 08:33:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-03-21 05:18:19 -04:00
|
|
|
|
|
|
|
class Label < Grape::Entity
|
|
|
|
expose :name
|
|
|
|
end
|
2014-05-26 09:08:22 -04:00
|
|
|
|
|
|
|
class RepoDiff < Grape::Entity
|
|
|
|
expose :old_path, :new_path, :a_mode, :b_mode, :diff
|
|
|
|
expose :new_file, :renamed_file, :deleted_file
|
|
|
|
end
|
|
|
|
|
|
|
|
class Compare < Grape::Entity
|
|
|
|
expose :commit, using: Entities::RepoCommit do |compare, options|
|
2014-05-27 04:27:42 -04:00
|
|
|
if compare.commit
|
|
|
|
Commit.new compare.commit
|
|
|
|
end
|
2014-05-26 09:08:22 -04:00
|
|
|
end
|
|
|
|
expose :commits, using: Entities::RepoCommit do |compare, options|
|
|
|
|
Commit.decorate compare.commits
|
|
|
|
end
|
|
|
|
expose :diffs, using: Entities::RepoDiff do |compare, options|
|
|
|
|
compare.diffs
|
|
|
|
end
|
2014-05-27 04:16:50 -04:00
|
|
|
|
|
|
|
expose :compare_timeout do |compare, options|
|
|
|
|
compare.timeout
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :same, as: :compare_same_ref
|
2014-05-26 09:08:22 -04:00
|
|
|
end
|
2012-06-27 07:32:56 -04:00
|
|
|
end
|
|
|
|
end
|