diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-22 00:08:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-22 00:08:47 +0300 |
commit | b102159513dca6066df9cceb14e35f62ab7ce36f (patch) | |
tree | 9781915122f3e2b286eda1fbed91e420e2fc7448 /lib/gitlab/hook_data | |
parent | 37a492326e7cde47928ee72abcc284ff9cf8f254 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/hook_data')
-rw-r--r-- | lib/gitlab/hook_data/base_builder.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/hook_data/group_builder.rb | 57 |
2 files changed, 63 insertions, 0 deletions
diff --git a/lib/gitlab/hook_data/base_builder.rb b/lib/gitlab/hook_data/base_builder.rb index 434d30d9717..e5bae61ae4e 100644 --- a/lib/gitlab/hook_data/base_builder.rb +++ b/lib/gitlab/hook_data/base_builder.rb @@ -21,6 +21,12 @@ module Gitlab private + def event_data(event) + event_name = "#{object.class.name.downcase}_#{event}" + + { event_name: event_name } + end + def timestamps_data { created_at: object.created_at&.xmlschema, diff --git a/lib/gitlab/hook_data/group_builder.rb b/lib/gitlab/hook_data/group_builder.rb new file mode 100644 index 00000000000..25c34a4c4a7 --- /dev/null +++ b/lib/gitlab/hook_data/group_builder.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +module Gitlab + module HookData + class GroupBuilder < BaseBuilder + alias_method :group, :object + + # Sample data + # { + # :created_at=>"2021-01-20T09:40:12Z", + # :updated_at=>"2021-01-20T09:40:12Z", + # :event_name=>"group_rename", + # :name=>"group1", + # :path=>"group1", + # :full_path=>"group1", + # :group_id=>1, + # :owner_name=>nil, + # :owner_email=>nil, + # :old_path=>"old-path", + # :old_full_path=>"old-path" + # } + + def build(event) + [ + timestamps_data, + event_data(event), + group_data, + event_specific_group_data(event) + ].reduce(:merge) + end + + private + + def group_data + owner = group.owner + + { + name: group.name, + path: group.path, + full_path: group.full_path, + group_id: group.id, + owner_name: owner.try(:name), + owner_email: owner.try(:email) + } + end + + def event_specific_group_data(event) + return {} unless event == :rename + + { + old_path: group.path_before_last_save, + old_full_path: group.full_path_before_last_save + } + end + end + end +end |