entities.rb 3.02 KB
Newer Older
Nihad Abbasov's avatar
Nihad Abbasov committed
1 2 3
module Gitlab
  module Entities
    class User < Grape::Entity
4
      expose :id, :username, :email, :name, :bio, :skype, :linkedin, :twitter,
5
             :dark_scheme, :theme_id, :state, :created_at, :extern_uid, :provider
Nihad Abbasov's avatar
Nihad Abbasov committed
6
    end
Nihad Abbasov's avatar
Nihad Abbasov committed
7

8 9 10 11
    class UserSafe < Grape::Entity
      expose :name
    end

12
    class UserBasic < Grape::Entity
13
      expose :id, :username, :email, :name, :state, :created_at
14 15
    end

16 17
    class UserLogin < UserBasic
      expose :private_token
18 19 20 21
      expose :is_admin?, as: :is_admin
      expose :can_create_group?, as: :can_create_group
      expose :can_create_project?, as: :can_create_project
      expose :can_create_team?, as: :can_create_team
22 23
    end

miks's avatar
miks committed
24
    class Hook < Grape::Entity
25
      expose :id, :url, :created_at
miks's avatar
miks committed
26 27
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
28
    class Project < Grape::Entity
29
      expose :id, :name, :description, :default_branch
30
      expose :owner, using: Entities::UserBasic
31
      expose :public
32
      expose :path, :path_with_namespace
Nihad Abbasov's avatar
Nihad Abbasov committed
33
      expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :created_at
34
      expose :namespace
Nihad Abbasov's avatar
Nihad Abbasov committed
35 36
    end

37
    class ProjectMember < UserBasic
38
      expose :project_access, as: :access_level do |user, options|
39 40
        options[:project].users_projects.find_by_user_id(user.id).project_access
      end
miks's avatar
miks committed
41 42
    end

43
    class Group < Grape::Entity
44
      expose :id, :name, :path, :owner_id
45
    end
Andrew8xx8's avatar
Andrew8xx8 committed
46

47
    class GroupDetail < Group
48 49 50
      expose :projects, using: Entities::Project
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
51
    class RepoObject < Grape::Entity
Nihad Abbasov's avatar
Nihad Abbasov committed
52
      expose :name, :commit
53 54 55 56 57
      expose :protected do |repo, options|
        if options[:project]
          options[:project].protected_branch? repo.name
        end
      end
Nihad Abbasov's avatar
Nihad Abbasov committed
58
    end
Nihad Abbasov's avatar
Nihad Abbasov committed
59

60 61 62 63
    class RepoCommit < Grape::Entity
      expose :id, :short_id, :title, :author_name, :author_email, :created_at
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
64 65
    class ProjectSnippet < Grape::Entity
      expose :id, :title, :file_name
66
      expose :author, using: Entities::UserBasic
Nihad Abbasov's avatar
Nihad Abbasov committed
67 68
      expose :expires_at, :updated_at, :created_at
    end
Nihad Abbasov's avatar
Nihad Abbasov committed
69 70

    class Milestone < Grape::Entity
71 72
      expose :id
      expose (:project_id) {|milestone| milestone.project.id}
Andrew8xx8's avatar
Andrew8xx8 committed
73
      expose :title, :description, :due_date, :state, :updated_at, :created_at
Nihad Abbasov's avatar
Nihad Abbasov committed
74 75 76
    end

    class Issue < Grape::Entity
77 78 79
      expose :id
      expose (:project_id) {|issue| issue.project.id}
      expose :title, :description
80 81 82
      expose :label_list, as: :labels
      expose :milestone, using: Entities::Milestone
      expose :assignee, :author, using: Entities::UserBasic
Andrew8xx8's avatar
Andrew8xx8 committed
83
      expose :state, :updated_at, :created_at
Nihad Abbasov's avatar
Nihad Abbasov committed
84
    end
Alex Denisov's avatar
Alex Denisov committed
85

86
    class SSHKey < Grape::Entity
87
      expose :id, :title, :key, :created_at
Alex Denisov's avatar
Alex Denisov committed
88
    end
89 90

    class MergeRequest < Grape::Entity
91
      expose :id, :target_branch, :source_branch, :project_id, :title, :state
92 93
      expose :author, :assignee, using: Entities::UserBasic
    end
94 95

    class Note < Grape::Entity
96 97
      expose :id
      expose :note, as: :body
98
      expose :author, using: Entities::UserBasic
99
      expose :created_at
100
    end
101 102 103 104 105

    class MRNote < Grape::Entity
      expose :note
      expose :author, using: Entities::UserBasic
    end
Nihad Abbasov's avatar
Nihad Abbasov committed
106 107
  end
end