debian-mirror-gitlab/lib/gitlab/data_builder/note.rb

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

82 lines
2.2 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
module Gitlab
2016-09-13 17:45:13 +05:30
module DataBuilder
module Note
extend self
2015-04-26 12:48:37 +05:30
# Produce a hash of post-receive data
#
# For all notes:
#
# data = {
# object_kind: "note",
2018-04-05 14:03:07 +05:30
# event_type: "confidential_note",
2015-04-26 12:48:37 +05:30
# user: {
# name: String,
# username: String,
# avatar_url: String
# }
# project_id: Integer,
# repository: {
# name: String,
# url: String,
# description: String,
# homepage: String,
# }
# object_attributes: {
# <hook data for note>
# }
# <note-specific data>: {
# }
# note-specific data is a hash with one of the following keys and contains
# the hook data for that type.
# - commit
# - issue
# - merge_request
# - snippet
#
def build(note, user)
project = note.project
data = build_base_data(project, user, note)
if note.for_commit?
data[:commit] = build_data_for_commit(project, user, note)
elsif note.for_issue?
2022-06-21 17:19:12 +05:30
data[:issue] = Gitlab::HookData::IssueBuilder.new(note.noteable).build
2015-04-26 12:48:37 +05:30
elsif note.for_merge_request?
2022-06-21 17:19:12 +05:30
data[:merge_request] = Gitlab::HookData::MergeRequestBuilder.new(note.noteable).build
2016-06-02 11:05:42 +05:30
elsif note.for_snippet?
2015-04-26 12:48:37 +05:30
data[:snippet] = note.noteable.hook_attrs
end
data
end
def build_base_data(project, user, note)
2020-06-23 00:09:42 +05:30
event_type = note.confidential?(include_noteable: true) ? 'confidential_note' : 'note'
2018-04-05 14:03:07 +05:30
2015-04-26 12:48:37 +05:30
base_data = {
object_kind: "note",
2018-04-05 14:03:07 +05:30
event_type: event_type,
2015-04-26 12:48:37 +05:30
user: user.hook_attrs,
project_id: project.id,
2016-04-02 18:10:28 +05:30
project: project.hook_attrs,
object_attributes: note.hook_attrs,
# DEPRECATED
repository: project.hook_attrs.slice(:name, :url, :description, :homepage)
2015-04-26 12:48:37 +05:30
}
2016-06-02 11:05:42 +05:30
base_data[:object_attributes][:url] = Gitlab::UrlBuilder.build(note)
2015-04-26 12:48:37 +05:30
base_data
end
def build_data_for_commit(project, user, note)
# commit_id is the SHA hash
2015-09-11 14:41:01 +05:30
commit = project.commit(note.commit_id)
commit.hook_attrs
2015-04-26 12:48:37 +05:30
end
end
end
end