debian-mirror-gitlab/lib/gitlab/hook_data/project_builder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
1.9 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# 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",
2022-04-04 11:22:00 +05:30
# owners: [name: "John", email: "user1@example.org"],
2021-06-08 01:23:25 +05:30
# 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
2022-04-04 11:22:00 +05:30
owners = project.owners.compact
# When this is removed, also remove the `deprecated_owner` method
# See https://gitlab.com/gitlab-org/gitlab/-/issues/350603
owner = project.deprecated_owner
2021-06-08 01:23:25 +05:30
{
name: project.name,
path: project.path,
path_with_namespace: project.full_path,
project_id: project.id,
2022-04-04 11:22:00 +05:30
owner_name: owner.try(:name),
owner_email: user_email(owner),
owners: owners.map do |owner|
owner_data(owner)
end,
2021-06-08 01:23:25 +05:30
project_visibility: project.visibility.downcase
}
end
2022-04-04 11:22:00 +05:30
def owner_data(user)
{ name: user.name, email: user_email(user) }
end
def user_email(user)
2023-01-10 11:22:00 +05:30
user.respond_to?(:webhook_email) ? user.webhook_email : ""
2022-04-04 11:22:00 +05:30
end
2021-06-08 01:23:25 +05:30
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