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
|
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
|
|
|
|
expose :is_admin?, as: :is_admin
|
2016-04-05 19:57:21 -04:00
|
|
|
expose :bio, :location, :skype, :linkedin, :twitter, :website_url
|
2013-03-11 08:35:00 -04:00
|
|
|
end
|
|
|
|
|
2014-11-27 06:34:39 -05:00
|
|
|
class Identity < Grape::Entity
|
|
|
|
expose :provider, :extern_uid
|
|
|
|
end
|
|
|
|
|
2014-06-13 10:46:48 -04:00
|
|
|
class UserFull < User
|
2016-02-24 07:14:37 -05:00
|
|
|
expose :last_sign_in_at
|
|
|
|
expose :confirmed_at
|
2014-06-13 10:46:48 -04:00
|
|
|
expose :email
|
2015-02-09 07:52:42 -05:00
|
|
|
expose :theme_id, :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
|
2015-06-24 01:36:35 -04:00
|
|
|
expose :two_factor_enabled
|
2016-03-14 19:11:20 -04:00
|
|
|
expose :external
|
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
|
|
|
|
|
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
|
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
|
2014-09-19 04:23:18 -04:00
|
|
|
expose :project_id, :push_events
|
2015-12-07 07:23:23 -05:00
|
|
|
expose :issues_events, :merge_requests_events, :tag_push_events, :note_events, :build_events
|
|
|
|
expose :enable_ssl_verification
|
2013-12-04 06:19:53 -05:00
|
|
|
end
|
|
|
|
|
2016-02-19 07:00:36 -05:00
|
|
|
class BasicProjectDetails < Grape::Entity
|
2013-06-27 17:49:26 -04:00
|
|
|
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
|
2015-02-04 20:42:34 -05:00
|
|
|
expose :id, :description, :default_branch, :tag_list
|
2013-11-06 10:13:21 -05:00
|
|
|
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
|
2015-11-09 10:48:03 -05:00
|
|
|
expose :issues_enabled, :merge_requests_enabled, :wiki_enabled, :builds_enabled, :snippets_enabled, :created_at, :last_activity_at
|
2015-12-04 06:55:23 -05:00
|
|
|
expose :shared_runners_enabled
|
2015-04-10 12:35:05 -04:00
|
|
|
expose :creator_id
|
2013-01-02 15:31:20 -05:00
|
|
|
expose :namespace
|
2016-02-19 07:00:36 -05:00
|
|
|
expose :forked_from_project, using: Entities::BasicProjectDetails, if: lambda{ |project, options| project.forked? }
|
2015-02-28 12:07:53 -05:00
|
|
|
expose :avatar_url
|
2015-07-28 09:49:44 -04:00
|
|
|
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] }
|
2016-02-04 06:57:46 -05:00
|
|
|
expose :public_builds
|
2012-06-27 08:51:39 -04:00
|
|
|
end
|
|
|
|
|
2012-09-21 06:23:17 -04:00
|
|
|
class ProjectMember < UserBasic
|
2014-09-15 04:55:36 -04:00
|
|
|
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
|
|
|
|
|
2013-01-08 16:05:00 -05:00
|
|
|
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|
|
2016-03-24 12:00:26 -04:00
|
|
|
Gitlab::Routing.url_helpers.group_url(group)
|
2015-07-30 05:56:15 -04:00
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2013-09-04 11:19:03 -04:00
|
|
|
class GroupMember < UserBasic
|
2014-09-15 04:55:36 -04:00
|
|
|
expose :access_level do |user, options|
|
2014-09-15 09:45:28 -04:00
|
|
|
options[:group].group_members.find_by(user_id: user.id).access_level
|
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
|
2014-07-01 15:05:29 -04:00
|
|
|
expose :safe_message, as: :message
|
2012-09-21 07:34:07 -04:00
|
|
|
end
|
|
|
|
|
2013-12-11 08:41:07 -05:00
|
|
|
class RepoCommitDetail < RepoCommit
|
|
|
|
expose :parent_ids, :committed_date, :authored_date
|
2015-10-06 06:01:16 -04:00
|
|
|
expose :status
|
2013-12-11 08:41:07 -05:00
|
|
|
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
|
2016-03-05 17:17:49 -05:00
|
|
|
expose :updated_at, :created_at
|
2016-03-09 13:25:39 -05:00
|
|
|
|
|
|
|
# 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
|
|
|
|
2013-10-14 09:39:54 -04:00
|
|
|
class ProjectEntity < Grape::Entity
|
|
|
|
expose :id, :iid
|
2015-03-02 21:45:28 -05:00
|
|
|
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
|
|
|
|
|
2015-02-02 16:08:10 -05: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 09:39:54 -04:00
|
|
|
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
|
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
|
|
|
|
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
|
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
|
2015-11-11 08:12:51 -05:00
|
|
|
expose :target_branch, :source_branch
|
2015-11-21 15:36:31 -05:00
|
|
|
expose :upvotes, :downvotes
|
2013-10-14 09:39:54 -04:00
|
|
|
expose :author, :assignee, using: Entities::UserBasic
|
|
|
|
expose :source_project_id, :target_project_id
|
2014-07-30 10:17:29 -04:00
|
|
|
expose :label_names, as: :labels
|
2014-04-15 22:14:05 -04:00
|
|
|
expose :description
|
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
|
2015-11-24 08:59:02 -05:00
|
|
|
expose :merge_when_build_succeeds
|
2016-01-17 13:59:43 -05:00
|
|
|
expose :merge_status
|
2016-04-08 02:41:10 -04:00
|
|
|
|
|
|
|
expose :subscribed do |merge_request, options|
|
|
|
|
merge_request.subscribed?(options[:current_user])
|
|
|
|
end
|
2012-09-16 10:52:06 -04:00
|
|
|
end
|
2012-10-21 07:00:27 -04:00
|
|
|
|
2015-02-02 16:08:10 -05: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
|
2015-02-02 16:08:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
2015-08-29 05:52:21 -04:00
|
|
|
class SSHKeyWithUser < SSHKey
|
|
|
|
expose :user, using: Entities::UserFull
|
|
|
|
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
|
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
|
2015-11-21 15:36:31 -05:00
|
|
|
# upvote? and downvote? are deprecated, always return false
|
2015-08-12 15:39:58 -04:00
|
|
|
expose :upvote?, as: :upvote
|
|
|
|
expose :downvote?, as: :downvote
|
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
|
|
|
|
2014-06-27 10:48:30 -04: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 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,
|
2015-10-26 02:26:03 -04:00
|
|
|
: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
|
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
|
|
|
|
|
|
|
expose :author_username do |event, options|
|
|
|
|
if event.author
|
|
|
|
event.author.username
|
|
|
|
end
|
|
|
|
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
|
|
|
|
expose :id, :project_id, :group_id, :group_access
|
|
|
|
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
|
2014-09-15 04:55:36 -04:00
|
|
|
expose :access_level
|
2014-03-17 08:33:41 -04:00
|
|
|
expose :notification_level
|
|
|
|
end
|
|
|
|
|
|
|
|
class GroupAccess < Grape::Entity
|
2014-09-15 04:55:36 -04:00
|
|
|
expose :access_level
|
2014-03-17 08:33:41 -04:00
|
|
|
expose :notification_level
|
|
|
|
end
|
|
|
|
|
2015-10-12 09:24:00 -04:00
|
|
|
class ProjectService < Grape::Entity
|
|
|
|
expose :id, :title, :created_at, :updated_at, :active
|
2015-12-07 07:23:23 -05:00
|
|
|
expose :push_events, :issues_events, :merge_requests_events, :tag_push_events, :note_events, :build_events
|
2015-10-12 09:24:00 -04:00
|
|
|
# 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
|
|
|
|
|
2014-03-17 08:33:41 -04:00
|
|
|
class ProjectWithAccess < Project
|
|
|
|
expose :permissions do
|
|
|
|
expose :project_access, using: Entities::ProjectAccess do |project, options|
|
2014-09-14 12:32:51 -04:00
|
|
|
project.project_members.find_by(user_id: options[:user].id)
|
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
|
2014-09-14 12:32:51 -04:00
|
|
|
project.group.group_members.find_by(user_id: options[:user].id)
|
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
|
|
|
|
|
|
|
class Label < Grape::Entity
|
2016-03-24 14:38:37 -04:00
|
|
|
expose :name, :color, :description
|
2016-04-06 08:32:36 -04:00
|
|
|
expose :open_issues_count, :closed_issues_count, :open_merge_requests_count
|
2014-03-21 05:18:19 -04:00
|
|
|
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|
|
2016-03-03 12:38:44 -05:00
|
|
|
compare.diffs(all_diffs: true).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
|
|
|
|
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
|
2016-03-08 19:01:33 -05:00
|
|
|
expose :default_group_visibility
|
2015-07-03 10:50:21 -04:00
|
|
|
expose :restricted_signup_domains
|
|
|
|
expose :user_oauth_applications
|
|
|
|
expose :after_sign_out_path
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2016-01-26 11:03:38 -05:00
|
|
|
class RunnerDetails < Runner
|
|
|
|
expose :tag_list
|
|
|
|
expose :version, :revision, :platform, :architecture
|
2016-02-17 15:23:14 -05:00
|
|
|
expose :contacted_at
|
2016-02-10 06:26:56 -05:00
|
|
|
expose :token, if: lambda { |runner, options| options[:current_user].is_admin? || !runner.is_shared? }
|
2016-02-19 07:00:36 -05:00
|
|
|
expose :projects, with: Entities::BasicProjectDetails do |runner, options|
|
2016-02-10 06:26:56 -05:00
|
|
|
if options[:current_user].is_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
|
|
|
|
|
2016-02-08 16:32:36 -05:00
|
|
|
class BuildArtifactFile < Grape::Entity
|
|
|
|
expose :filename, :size
|
|
|
|
end
|
|
|
|
|
2015-12-24 13:05:57 -05:00
|
|
|
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
|
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
|
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
|
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
|
2015-12-31 09:19:13 -05:00
|
|
|
end
|
2012-06-27 07:32:56 -04:00
|
|
|
end
|
|
|
|
end
|