diff options
author | Rémy Coutable <remy@rymai.me> | 2017-09-19 19:23:15 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-10-09 15:07:10 +0200 |
commit | 075d6516047d899746d22b5323d3b74558e200d0 (patch) | |
tree | f958ce8b1ab36d898e9d8dc894e0ed63fbcf7ebd /lib | |
parent | 67d5ca9f9220e5572f3fa6d0d8290cd7b802f02f (diff) | |
download | gitlab-ce-075d6516047d899746d22b5323d3b74558e200d0.tar.gz |
Start adding Gitlab::HookData::IssuableBuilder
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/hook_data/issuable_builder.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/gitlab/hook_data/issuable_builder.rb b/lib/gitlab/hook_data/issuable_builder.rb new file mode 100644 index 00000000000..e817c6af94a --- /dev/null +++ b/lib/gitlab/hook_data/issuable_builder.rb @@ -0,0 +1,36 @@ +module Gitlab + module HookData + class IssuableBuilder + attr_accessor :issuable + + def initialize(issuable) + @issuable = issuable + end + + def build(user: nil, changes: {}) + hook_data = { + object_kind: issuable.class.name.underscore, + user: user.hook_attrs, + project: issuable.project.hook_attrs, + object_attributes: issuable.hook_attrs, + labels: issuable.labels.map(&:hook_attrs), + changes: changes.slice(*safe_keys), + # DEPRECATED + repository: issuable.project.hook_attrs.slice(:name, :url, :description, :homepage) + } + + if issuable.is_a?(Issue) + hook_data[:assignees] = issuable.assignees.map(&:hook_attrs) if issuable.assignees.any? + else + hook_data[:assignee] = issuable.assignee.hook_attrs if issuable.assignee + end + + hook_data + end + + def safe_keys + issuable.class.safe_hook_attributes + issuable.class.safe_hook_relations + end + end + end +end |