diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /lib/gitlab/hook_data | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'lib/gitlab/hook_data')
-rw-r--r-- | lib/gitlab/hook_data/base_builder.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/hook_data/group_member_builder.rb | 65 |
2 files changed, 72 insertions, 0 deletions
diff --git a/lib/gitlab/hook_data/base_builder.rb b/lib/gitlab/hook_data/base_builder.rb index d54175bce81..434d30d9717 100644 --- a/lib/gitlab/hook_data/base_builder.rb +++ b/lib/gitlab/hook_data/base_builder.rb @@ -21,6 +21,13 @@ module Gitlab private + def timestamps_data + { + created_at: object.created_at&.xmlschema, + updated_at: object.updated_at&.xmlschema + } + end + def absolute_image_urls(markdown_text) return markdown_text unless markdown_text.present? diff --git a/lib/gitlab/hook_data/group_member_builder.rb b/lib/gitlab/hook_data/group_member_builder.rb new file mode 100644 index 00000000000..32cfd032ffe --- /dev/null +++ b/lib/gitlab/hook_data/group_member_builder.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +module Gitlab + module HookData + class GroupMemberBuilder < BaseBuilder + alias_method :group_member, :object + + # Sample data + + # { + # :event_name=>"user_add_to_group", + # :group_name=>"GitLab group", + # :group_path=>"gitlab", + # :group_id=>1, + # :user_username=>"robert", + # :user_name=>"Robert Mills", + # :user_email=>"robert@example.com", + # :user_id=>14, + # :group_access=>"Guest", + # :created_at=>"2020-11-04T10:12:10Z", + # :updated_at=>"2020-11-04T10:12:10Z", + # :expires_at=>"2020-12-04T10:12:10Z" + # } + + def build(event) + [ + timestamps_data, + group_member_data, + event_data(event) + ].reduce(:merge) + end + + private + + def group_member_data + { + group_name: group_member.group.name, + group_path: group_member.group.path, + group_id: group_member.group.id, + user_username: group_member.user.username, + user_name: group_member.user.name, + user_email: group_member.user.email, + user_id: group_member.user.id, + group_access: group_member.human_access, + expires_at: group_member.expires_at&.xmlschema + } + end + + def event_data(event) + event_name = case event + when :create + 'user_add_to_group' + when :destroy + 'user_remove_from_group' + when :update + 'user_update_for_group' + end + + { event_name: event_name } + end + end + end +end + +Gitlab::HookData::GroupMemberBuilder.prepend_if_ee('EE::Gitlab::HookData::GroupMemberBuilder') |