entities.rb 24 KB
Newer Older
1
module API
Nihad Abbasov's avatar
Nihad Abbasov committed
2
  module Entities
3 4 5
    class UserSafe < Grape::Entity
      expose :name, :username
    end
6

7 8
    class UserBasic < UserSafe
      expose :id, :state, :avatar_url
Douwe Maan's avatar
Douwe Maan committed
9 10

      expose :web_url do |user, options|
11
        Gitlab::Routing.url_helpers.user_url(user)
Douwe Maan's avatar
Douwe Maan committed
12
      end
Nihad Abbasov's avatar
Nihad Abbasov committed
13
    end
Nihad Abbasov's avatar
Nihad Abbasov committed
14

15 16 17
    class User < UserBasic
      expose :created_at
      expose :is_admin?, as: :is_admin
18
      expose :bio, :location, :skype, :linkedin, :twitter, :website_url, :organization
19 20
    end

21 22
    class UserActivity < Grape::Entity
      expose :username
23
      expose :last_activity_at
24 25
    end

26 27 28 29
    class Identity < Grape::Entity
      expose :provider, :extern_uid
    end

30
    class UserPublic < User
31 32
      expose :last_sign_in_at
      expose :confirmed_at
33
      expose :email
34
      expose :color_scheme_id, :projects_limit, :current_sign_in_at
35
      expose :identities, using: Entities::Identity
36 37
      expose :can_create_group?, as: :can_create_group
      expose :can_create_project?, as: :can_create_project
38
      expose :two_factor_enabled?, as: :two_factor_enabled
39
      expose :external
40 41
    end

42
    class UserWithPrivateToken < UserPublic
43
      expose :private_token
44 45
    end

46 47 48 49
    class Email < Grape::Entity
      expose :id, :email
    end

miks's avatar
miks committed
50
    class Hook < Grape::Entity
51
      expose :id, :url, :created_at, :push_events, :tag_push_events
52
      expose :enable_ssl_verification
miks's avatar
miks committed
53 54
    end

55
    class ProjectHook < Hook
56
      expose :project_id, :issues_events, :merge_requests_events
57
      expose :note_events, :build_events, :pipeline_events, :wiki_page_events
58
    end
Valery Sizov's avatar
Valery Sizov committed
59

60
    class ProjectPushRule < Grape::Entity
Valery Sizov's avatar
Valery Sizov committed
61 62
      expose :id, :project_id, :created_at
      expose :commit_message_regex, :deny_delete_tag
63 64
      expose :member_check, :prevent_secrets, :author_email_regex
      expose :file_name_regex, :max_file_size
Valery Sizov's avatar
Valery Sizov committed
65
    end
66

67
    class BasicProjectDetails < Grape::Entity
68
      expose :id
69
      expose :http_url_to_repo, :web_url
70 71 72 73
      expose :name, :name_with_namespace
      expose :path, :path_with_namespace
    end

74 75 76 77 78 79 80 81
    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

Nihad Abbasov's avatar
Nihad Abbasov committed
82
    class Project < Grape::Entity
83
      expose :id, :description, :default_branch, :tag_list
84
      expose :archived?, as: :archived
85
      expose :visibility, :ssh_url_to_repo, :http_url_to_repo, :web_url
86
      expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group }
87
      expose :name, :name_with_namespace
88
      expose :path, :path_with_namespace
89 90 91
      expose :container_registry_enabled

      # Expose old field names with the new permissions methods to keep API compatible
92 93 94 95 96
      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(:builds_enabled) { |project, options| project.feature_available?(:builds, options[:current_user]) }
      expose(:snippets_enabled) { |project, options| project.feature_available?(:snippets, options[:current_user]) }
97

98
      expose :created_at, :last_activity_at
99 100
      expose :shared_runners_enabled
      expose :lfs_enabled?, as: :lfs_enabled
101
      expose :creator_id
102
      expose :namespace, using: 'API::Entities::Namespace'
103
      expose :forked_from_project, using: Entities::BasicProjectDetails, if: lambda{ |project, options| project.forked? }
sue445's avatar
sue445 committed
104
      expose :avatar_url
105
      expose :star_count, :forks_count
106
      expose :open_issues_count, if: lambda { |project, options| project.feature_available?(:issues, options[:current_user]) && project.default_issues_tracker? }
107
      expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] }
108
      expose :public_builds
109 110 111
      expose :shared_with_groups do |project, options|
        SharedGroup.represent(project.project_group_links.all, options)
      end
112
      expose :only_allow_merge_if_pipeline_succeeds
113
      expose :repository_storage, if: lambda { |_project, options| options[:current_user].try(:admin?) }
114
      expose :request_access_enabled
115
      expose :only_allow_merge_if_all_discussions_are_resolved
116
      expose :approvals_before_merge
117

118 119 120 121 122 123 124 125 126
      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
Nihad Abbasov's avatar
Nihad Abbasov committed
127 128
    end

129
    class Member < UserBasic
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
130
      expose :access_level do |user, options|
131
        member = options[:member] || options[:source].members.find_by(user_id: user.id)
132 133
        member.access_level
      end
134
      expose :expires_at do |user, options|
135
        member = options[:member] || options[:source].members.find_by(user_id: user.id)
136 137
        member.expires_at
      end
138 139 140 141
    end

    class AccessRequester < UserBasic
      expose :requested_at do |user, options|
142
        access_requester = options[:access_requester] || options[:source].requesters.find_by(user_id: user.id)
143
        access_requester.requested_at
144
      end
miks's avatar
miks committed
145 146
    end

147 148 149 150
    class LdapGroupLink < Grape::Entity
      expose :cn, :group_access, :provider
    end

151
    class Group < Grape::Entity
152
      expose :id, :name, :path, :description, :visibility
153
<<<<<<< HEAD
Douwe Maan's avatar
Douwe Maan committed
154

155 156 157 158
      expose :ldap_cn, :ldap_access
      expose :ldap_group_links,
        using: Entities::LdapGroupLink,
        if: lambda { |group, options| group.ldap_group_links.any? }
Douwe Maan's avatar
Douwe Maan committed
159

160 161
=======
>>>>>>> ce-com/master
162
      expose :lfs_enabled?, as: :lfs_enabled
163
      expose :avatar_url
164
      expose :web_url
165
      expose :request_access_enabled
166
      expose :full_name, :full_path
167
      expose :parent_id
168 169 170 171 172 173 174 175 176

      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
        end
      end
177
    end
Andrew8xx8's avatar
Andrew8xx8 committed
178

179
    class GroupDetail < Group
180
      expose :projects, using: Entities::Project
181
      expose :shared_projects, using: Entities::Project
182 183
    end

184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
    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

201
    class RepoBranch < Grape::Entity
202 203
      expose :name

204
      expose :commit, using: Entities::RepoCommit do |repo_branch, options|
205
        options[:project].repository.commit(repo_branch.dereferenced_target)
206 207
      end

208 209 210 211
      expose :merged do |repo_branch, options|
        options[:project].repository.merged_to_root_ref?(repo_branch.name)
      end

212
      expose :protected do |repo_branch, options|
213
        options[:project].protected_branch?(repo_branch.name)
214 215
      end

216
      expose :developers_can_push do |repo_branch, options|
217
        project = options[:project]
218 219
        access_levels = project.protected_branches.matching(repo_branch.name).map(&:push_access_levels).flatten
        access_levels.any? { |access_level| access_level.access_level == Gitlab::Access::DEVELOPER }
220
      end
221

222
      expose :developers_can_merge do |repo_branch, options|
223
        project = options[:project]
224 225
        access_levels = project.protected_branches.matching(repo_branch.name).map(&:merge_access_levels).flatten
        access_levels.any? { |access_level| access_level.access_level == Gitlab::Access::DEVELOPER }
226
      end
Nihad Abbasov's avatar
Nihad Abbasov committed
227
    end
Nihad Abbasov's avatar
Nihad Abbasov committed
228

229
    class RepoTreeObject < Grape::Entity
230
      expose :id, :name, :type, :path
231 232 233 234 235 236 237 238

      expose :mode do |obj, options|
        filemode = obj.mode.to_s(8)
        filemode = "0" + filemode if filemode.length < 6
        filemode
      end
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
239 240
    class ProjectSnippet < Grape::Entity
      expose :id, :title, :file_name
241
      expose :author, using: Entities::UserBasic
242
      expose :updated_at, :created_at
243

244 245 246
      expose :web_url do |snippet, options|
        Gitlab::UrlBuilder.build(snippet)
      end
Nihad Abbasov's avatar
Nihad Abbasov committed
247
    end
Nihad Abbasov's avatar
Nihad Abbasov committed
248

249 250 251 252 253 254 255 256 257 258 259 260 261
    class PersonalSnippet < Grape::Entity
      expose :id, :title, :file_name
      expose :author, using: Entities::UserBasic
      expose :updated_at, :created_at

      expose :web_url do |snippet|
        Gitlab::UrlBuilder.build(snippet)
      end
      expose :raw_url do |snippet|
        Gitlab::UrlBuilder.build(snippet) + "/raw"
      end
    end

262 263
    class ProjectEntity < Grape::Entity
      expose :id, :iid
264
      expose(:project_id) { |entity| entity.project.id }
265 266
      expose :title, :description
      expose :state, :created_at, :updated_at
267 268
    end

269 270 271 272 273
    class RepoDiff < Grape::Entity
      expose :old_path, :new_path, :a_mode, :b_mode, :diff
      expose :new_file, :renamed_file, :deleted_file
    end

274
    class Milestone < ProjectEntity
275
      expose :due_date
276
      expose :start_date
Nihad Abbasov's avatar
Nihad Abbasov committed
277 278
    end

279
    class Issue < ProjectEntity
280
      expose :label_names, as: :labels
281 282
      expose :milestone, using: Entities::Milestone
      expose :assignee, :author, using: Entities::UserBasic
283 284

      expose :subscribed do |issue, options|
285
        issue.subscribed?(options[:current_user], options[:project] || issue.project)
286
      end
287
      expose :user_notes_count
288
      expose :upvotes, :downvotes
289
      expose :due_date
290
      expose :confidential
291
      expose :weight
292 293 294 295

      expose :web_url do |issue, options|
        Gitlab::UrlBuilder.build(issue)
      end
Nihad Abbasov's avatar
Nihad Abbasov committed
296
    end
Alex Denisov's avatar
Alex Denisov committed
297

298 299 300 301 302 303 304
    class IssuableTimeStats < Grape::Entity
      expose :time_estimate
      expose :total_time_spent
      expose :human_time_estimate
      expose :human_total_time_spent
    end

305 306 307 308 309
    class ExternalIssue < Grape::Entity
      expose :title
      expose :id
    end

310
    class MergeRequest < ProjectEntity
311
      expose :target_branch, :source_branch
312
      expose :upvotes, :downvotes
313 314
      expose :author, :assignee, using: Entities::UserBasic
      expose :source_project_id, :target_project_id
315
      expose :label_names, as: :labels
316
      expose :work_in_progress?, as: :work_in_progress
317
      expose :milestone, using: Entities::Milestone
318
      expose :merge_when_pipeline_succeeds
319
      expose :merge_status
320 321
      expose :diff_head_sha, as: :sha
      expose :merge_commit_sha
322

323
      expose :subscribed do |merge_request, options|
324
        merge_request.subscribed?(options[:current_user], options[:project])
325
      end
326

327
      expose :user_notes_count
328
      expose :approvals_before_merge
329 330
      expose :should_remove_source_branch?, as: :should_remove_source_branch
      expose :force_remove_source_branch?, as: :force_remove_source_branch
Sean McGivern's avatar
Sean McGivern committed
331
      expose :squash
332 333 334 335

      expose :web_url do |merge_request, options|
        Gitlab::UrlBuilder.build(merge_request)
      end
Alex Denisov's avatar
Alex Denisov committed
336
    end
337

338 339
    class MergeRequestChanges < MergeRequest
      expose :diffs, as: :changes, using: Entities::RepoDiff do |compare, _|
340
        compare.raw_diffs(all_diffs: true).to_a
341 342 343
      end
    end

Patricio Cano's avatar
Patricio Cano committed
344
    class Approvals < Grape::Entity
Patricio Cano's avatar
Patricio Cano committed
345
      expose :user, using: Entities::UserBasic
Patricio Cano's avatar
Patricio Cano committed
346 347 348 349
    end

    class MergeRequestApprovals < ProjectEntity
      expose :merge_status
350 351
      expose :approvals_required
      expose :approvals_left
Patricio Cano's avatar
Patricio Cano committed
352
      expose :approvals, as: :approved_by, using: Entities::Approvals
353
      expose :approvers_left, as: :suggested_approvers, using: Entities::UserBasic
354 355 356 357 358 359 360 361

      expose :user_has_approved do |merge_request, options|
        merge_request.has_approved?(options[:current_user])
      end

      expose :user_can_approve do |merge_request, options|
        merge_request.can_approve?(options[:current_user])
      end
Patricio Cano's avatar
Patricio Cano committed
362 363
    end

364 365 366
    class MergeRequestDiff < Grape::Entity
      expose :id, :head_commit_sha, :base_commit_sha, :start_commit_sha,
        :created_at, :merge_request_id, :state, :real_size
367
    end
368

369
    class MergeRequestDiffFull < MergeRequestDiff
370 371 372
      expose :commits, using: Entities::RepoCommit

      expose :diffs, using: Entities::RepoDiff do |compare, _|
373
        compare.raw_diffs(all_diffs: true).to_a
374 375 376
      end
    end

377
    class SSHKey < Grape::Entity
378
      expose :id, :title, :key, :created_at, :can_push
379
    end
380

381
    class SSHKeyWithUser < SSHKey
382
      expose :user, using: Entities::UserPublic
383 384
    end

385
    class Note < Grape::Entity
386 387
      expose :id
      expose :note, as: :body
388
      expose :attachment_identifier, as: :attachment
389
      expose :author, using: Entities::UserBasic
390
      expose :created_at, :updated_at
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
391
      expose :system?, as: :system
392
      expose :noteable_id, :noteable_type
393
    end
394

395 396 397 398 399 400 401 402
    class AwardEmoji < Grape::Entity
      expose :id
      expose :name
      expose :user, using: Entities::UserBasic
      expose :created_at, :updated_at
      expose :awardable_id, :awardable_type
    end

403 404 405 406
    class MRNote < Grape::Entity
      expose :note
      expose :author, using: Entities::UserBasic
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
407

408 409
    class CommitNote < Grape::Entity
      expose :note
410 411 412
      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? }
413
      expose :author, using: Entities::UserBasic
414
      expose :created_at
415 416
    end

417 418
    class CommitStatus < Grape::Entity
      expose :id, :sha, :ref, :status, :name, :target_url, :description,
419
             :created_at, :started_at, :finished_at, :allow_failure, :coverage
Kamil Trzcinski's avatar
Kamil Trzcinski committed
420
      expose :author, using: Entities::UserBasic
421 422
    end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
423 424 425 426
    class Event < Grape::Entity
      expose :title, :project_id, :action_name
      expose :target_id, :target_type, :author_id
      expose :data, :target_title
427
      expose :created_at
428 429
      expose :note, using: Entities::Note, if: ->(event, options) { event.note? }
      expose :author, using: Entities::UserBasic, if: ->(event, options) { event.author }
430 431

      expose :author_username do |event, options|
432
        event.author&.username
433
      end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
434
    end
435 436 437 438

    class LdapGroup < Grape::Entity
      expose :cn
    end
439 440

    class ProjectGroupLink < Grape::Entity
441
      expose :id, :project_id, :group_id, :group_access, :expires_at
442
    end
443

Douglas Barbosa Alexandre's avatar
Douglas Barbosa Alexandre committed
444 445 446 447
    class Todo < Grape::Entity
      expose :id
      expose :project, using: Entities::BasicProjectDetails
      expose :author, using: Entities::UserBasic
Robert Schilling's avatar
Robert Schilling committed
448
      expose :action_name
Douglas Barbosa Alexandre's avatar
Douglas Barbosa Alexandre committed
449
      expose :target_type
450 451

      expose :target do |todo, options|
452 453
        target = todo.target_type == 'Commit' ? 'RepoCommit' : todo.target_type
        Entities.const_get(target).represent(todo.target, options)
Douglas Barbosa Alexandre's avatar
Douglas Barbosa Alexandre committed
454 455 456 457 458
      end

      expose :target_url do |todo, options|
        target_type   = todo.target_type.underscore
        target_url    = "namespace_project_#{target_type}_url"
459
        target_anchor = "note_#{todo.note_id}" if todo.note_id?
Douglas Barbosa Alexandre's avatar
Douglas Barbosa Alexandre committed
460 461 462 463 464 465 466 467 468 469

        Gitlab::Application.routes.url_helpers.public_send(target_url,
          todo.project.namespace, todo.project, todo.target, anchor: target_anchor)
      end

      expose :body
      expose :state
      expose :created_at
    end

470
    class Namespace < Grape::Entity
471
      expose :id, :name, :path, :kind, :full_path
472
    end
473

474
    class MemberAccess < Grape::Entity
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
475
      expose :access_level
476 477
      expose :notification_level do |member, options|
        if member.notification_setting
478
          ::NotificationSetting.levels[member.notification_setting.level]
479 480
        end
      end
481 482
    end

483
    class ProjectAccess < MemberAccess
484 485
    end

486
    class GroupAccess < MemberAccess
487 488
    end

489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
    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

504 505
    class ProjectService < Grape::Entity
      expose :id, :title, :created_at, :updated_at, :active
506 507
      expose :push_events, :issues_events, :merge_requests_events
      expose :tag_push_events, :note_events, :build_events, :pipeline_events
508 509 510 511 512 513 514 515 516
      # 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

517 518 519
    class ProjectWithAccess < Project
      expose :permissions do
        expose :project_access, using: Entities::ProjectAccess do |project, options|
520
          project.project_members.find_by(user_id: options[:current_user].id)
521 522 523
        end

        expose :group_access, using: Entities::GroupAccess do |project, options|
524
          if project.group
525
            project.group.group_members.find_by(user_id: options[:current_user].id)
526
          end
527 528 529
        end
      end
    end
530

531
    class LabelBasic < Grape::Entity
Rares Sfirlogea's avatar
Rares Sfirlogea committed
532
      expose :id, :name, :color, :description
533 534 535
    end

    class Label < LabelBasic
536
      expose :open_issues_count do |label, options|
Francesco Coda Zabetta's avatar
Francesco Coda Zabetta committed
537 538
        label.open_issues_count(options[:current_user])
      end
539

Francesco Coda Zabetta's avatar
Francesco Coda Zabetta committed
540 541 542
      expose :closed_issues_count do |label, options|
        label.closed_issues_count(options[:current_user])
      end
543

Francesco Coda Zabetta's avatar
Francesco Coda Zabetta committed
544 545
      expose :open_merge_requests_count do |label, options|
        label.open_merge_requests_count(options[:current_user])
546 547
      end

548 549 550
      expose :priority do |label, options|
        label.priority(options[:project])
      end
551 552

      expose :subscribed do |label, options|
553
        label.subscribed?(options[:current_user], options[:project])
554
      end
555
    end
556

557 558 559 560 561 562 563 564 565 566 567 568 569
    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

570 571
    class Compare < Grape::Entity
      expose :commit, using: Entities::RepoCommit do |compare, options|
572
        Commit.decorate(compare.commits, nil).last
573
      end
574

575
      expose :commits, using: Entities::RepoCommit do |compare, options|
576
        Commit.decorate(compare.commits, nil)
577
      end
578

579
      expose :diffs, using: Entities::RepoDiff do |compare, options|
580
        compare.diffs(all_diffs: true).to_a
581
      end
582 583

      expose :compare_timeout do |compare, options|
584
        compare.diffs.overflow?
585 586 587
      end

      expose :same, as: :compare_same_ref
588
    end
589 590 591 592

    class Contributor < Grape::Entity
      expose :name, :email, :commits, :additions, :deletions
    end
593 594 595 596

    class BroadcastMessage < Grape::Entity
      expose :message, :starts_at, :ends_at, :color, :font
    end
597 598 599 600 601 602 603 604

    class ApplicationSetting < Grape::Entity
      expose :id
      expose :default_projects_limit
      expose :signup_enabled
      expose :signin_enabled
      expose :gravatar_enabled
      expose :sign_in_text
605
      expose :after_sign_up_text
606 607 608 609
      expose :created_at
      expose :updated_at
      expose :home_page_url
      expose :default_branch_protection
610 611 612
      expose(:restricted_visibility_levels) do |setting, _options|
        setting.restricted_visibility_levels.map { |level| Gitlab::VisibilityLevel.string_level(level) }
      end
613 614
      expose :max_attachment_size
      expose :session_expire_delay
615 616 617
      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) }
618
      expose :default_artifacts_expire_in
619
      expose :domain_whitelist
620 621
      expose :domain_blacklist_enabled
      expose :domain_blacklist
622 623
      expose :user_oauth_applications
      expose :after_sign_out_path
624
      expose :container_registry_token_expire_delay
625
      expose :repository_storages
626 627
      expose :koding_enabled
      expose :koding_url
628 629
      expose :plantuml_enabled
      expose :plantuml_url
630
      expose :terminal_max_session_time
631
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
632 633

    class Release < Grape::Entity
634 635
      expose :tag, as: :tag_name
      expose :description
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
636
    end
637 638

    class RepoTag < Grape::Entity
639
      expose :name, :message
640

641
      expose :commit do |repo_tag, options|
642
        options[:project].repository.commit(repo_tag.dereferenced_target)
643 644
      end

645 646
      expose :release, using: Entities::Release do |repo_tag, options|
        options[:project].releases.find_by(tag: repo_tag.name)
647 648
      end
    end
649 650

    class License < Grape::Entity
651
      expose :starts_at, :expires_at, :licensee, :add_ons
652 653 654 655 656 657 658 659 660

      expose :user_limit do |license, options|
        license.restricted?(:active_user_count) ? license.restrictions[:active_user_count] : 0
      end

      expose :active_users do |license, options|
        ::User.active.count
      end
    end
661

Kamil Trzcinski's avatar
Kamil Trzcinski committed
662 663 664
    class TriggerRequest < Grape::Entity
      expose :id, :variables
    end
665 666 667 668 669 670 671 672 673

    class Runner < Grape::Entity
      expose :id
      expose :description
      expose :active
      expose :is_shared
      expose :name
    end

674 675
    class RunnerDetails < Runner
      expose :tag_list
676
      expose :run_untagged
677
      expose :locked
678
      expose :version, :revision, :platform, :architecture
679
      expose :contacted_at
680
      expose :token, if: lambda { |runner, options| options[:current_user].is_admin? || !runner.is_shared? }
681
      expose :projects, with: Entities::BasicProjectDetails do |runner, options|
682
        if options[:current_user].is_admin?
683 684
          runner.projects
        else
685
          options[:current_user].authorized_projects.where(id: runner.projects)
686 687
        end
      end
688 689
    end

690 691 692 693
    class RunnerRegistrationDetails < Grape::Entity
      expose :id, :token
    end

694 695 696 697
    class BuildArtifactFile < Grape::Entity
      expose :filename, :size
    end

698 699 700 701
    class PipelineBasic < Grape::Entity
      expose :id, :sha, :ref, :status
    end

702 703 704 705
    class Build < Grape::Entity
      expose :id, :status, :stage, :name, :ref, :tag, :coverage
      expose :created_at, :started_at, :finished_at
      expose :user, with: User
Kamil Trzcinski's avatar
Kamil Trzcinski committed
706
      expose :artifacts_file, using: BuildArtifactFile, if: -> (build, opts) { build.artifacts? }
707
      expose :commit, with: RepoCommit
708
      expose :runner, with: Runner
709
      expose :pipeline, with: PipelineBasic
710 711 712 713 714 715 716 717 718
    end

    class Trigger < Grape::Entity
      expose :token, :created_at, :updated_at, :deleted_at, :last_used
    end

    class Variable < Grape::Entity
      expose :key, :value
    end
719

720 721
    class Pipeline < PipelineBasic
      expose :before_sha, :tag, :yaml_errors
722 723 724 725

      expose :user, with: Entities::UserBasic
      expose :created_at, :updated_at, :started_at, :finished_at, :committed_at
      expose :duration
726
      expose :coverage
727 728
    end

729
    class EnvironmentBasic < Grape::Entity
Nick Thomas's avatar
Nick Thomas committed
730
      expose :id, :name, :slug, :external_url
731 732
    end

733 734
    class Environment < EnvironmentBasic
      expose :project, using: Entities::Project
735 736 737 738 739 740 741
    end

    class Deployment < Grape::Entity
      expose :id, :iid, :ref, :sha, :created_at
      expose :user,        using: Entities::UserBasic
      expose :environment, using: Entities::EnvironmentBasic
      expose :deployable,  using: Entities::Build
742 743
    end

744
    class RepoLicense < Grape::Entity
745 746
      expose :key, :name, :nickname
      expose :featured, as: :popular
747 748 749
      expose :url, as: :html_url
      expose(:source_url) { |license| license.meta['source'] }
      expose(:description) { |license| license.meta['description'] }
750 751 752
      expose(:conditions) { |license| license.meta['conditions'] }
      expose(:permissions) { |license| license.meta['permissions'] }
      expose(:limitations) { |license| license.meta['limitations'] }
753 754
      expose :content
    end
755

756
    class TemplatesList < Grape::Entity
757 758 759
      expose :name
    end

760
    class Template < Grape::Entity
761 762
      expose :name, :content
    end
763 764 765 766 767

    class BroadcastMessage < Grape::Entity
      expose :id, :message, :starts_at, :ends_at, :color, :font
      expose :active?, as: :active
    end
Nihad Abbasov's avatar
Nihad Abbasov committed
768 769
  end
end