Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-09-19 20:23:15 +0300
committerRémy Coutable <remy@rymai.me>2017-10-09 16:07:10 +0300
commit075d6516047d899746d22b5323d3b74558e200d0 (patch)
treef958ce8b1ab36d898e9d8dc894e0ed63fbcf7ebd /lib/gitlab/hook_data
parent67d5ca9f9220e5572f3fa6d0d8290cd7b802f02f (diff)
Start adding Gitlab::HookData::IssuableBuilder
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/gitlab/hook_data')
-rw-r--r--lib/gitlab/hook_data/issuable_builder.rb36
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