diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 21:09:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 21:09:37 +0300 |
commit | b6e611dd423708f2e31c034e5dcab9b0cd18021a (patch) | |
tree | 161ea6dfda91099f8a00d6802431da1cab160591 /lib/gitlab/hook_data | |
parent | 8bcfcd53f3e3fe8df944eea6dab02556976fd4e3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/hook_data')
-rw-r--r-- | lib/gitlab/hook_data/project_builder.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/gitlab/hook_data/project_builder.rb b/lib/gitlab/hook_data/project_builder.rb new file mode 100644 index 00000000000..65c237f743f --- /dev/null +++ b/lib/gitlab/hook_data/project_builder.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +module Gitlab + module HookData + class ProjectBuilder < BaseBuilder + alias_method :project, :object + + # Sample data + # { + # event_name: "project_rename", + # created_at: "2021-04-19T07:05:36Z", + # updated_at: "2021-04-19T07:05:36Z", + # name: "my_project", + # path: "my_project", + # path_with_namespace: "namespace2/my_project", + # project_id: 1, + # owner_name: "John", + # owner_email: "user1@example.org", + # project_visibility: "internal", + # old_path_with_namespace: "old-path-with-namespace" + # } + + def build(event) + [ + event_data(event), + timestamps_data, + project_data, + event_specific_project_data(event) + ].reduce(:merge) + end + + private + + def project_data + owner = project.owner + + { + name: project.name, + path: project.path, + path_with_namespace: project.full_path, + project_id: project.id, + owner_name: owner.name, + owner_email: owner.respond_to?(:email) ? owner.email : "", + project_visibility: project.visibility.downcase + } + end + + def event_specific_project_data(event) + return {} unless event == :rename || event == :transfer + + { + old_path_with_namespace: project.old_path_with_namespace + } + end + end + end +end |