2015-03-05 18:38:23 +00:00
|
|
|
module Gitlab
|
2016-08-04 15:44:27 +00:00
|
|
|
module DataBuilder
|
2016-08-12 08:09:29 +00:00
|
|
|
module Note
|
2016-08-12 07:33:28 +00:00
|
|
|
extend self
|
2016-08-04 15:44:27 +00:00
|
|
|
|
2015-03-05 18:38:23 +00:00
|
|
|
# Produce a hash of post-receive data
|
|
|
|
#
|
|
|
|
# For all notes:
|
|
|
|
#
|
|
|
|
# data = {
|
|
|
|
# object_kind: "note",
|
|
|
|
# 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?
|
|
|
|
data[:issue] = note.noteable.hook_attrs
|
|
|
|
elsif note.for_merge_request?
|
|
|
|
data[:merge_request] = note.noteable.hook_attrs
|
2016-03-31 07:20:27 +00:00
|
|
|
elsif note.for_snippet?
|
2015-03-05 18:38:23 +00:00
|
|
|
data[:snippet] = note.noteable.hook_attrs
|
|
|
|
end
|
|
|
|
|
|
|
|
data
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_base_data(project, user, note)
|
|
|
|
base_data = {
|
|
|
|
object_kind: "note",
|
|
|
|
user: user.hook_attrs,
|
|
|
|
project_id: project.id,
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 14:20:21 +00:00
|
|
|
project: project.hook_attrs,
|
|
|
|
object_attributes: note.hook_attrs,
|
|
|
|
# DEPRECATED
|
|
|
|
repository: project.hook_attrs.slice(:name, :url, :description, :homepage)
|
2015-03-05 18:38:23 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 09:25:42 +00:00
|
|
|
base_data[:object_attributes][:url] = Gitlab::UrlBuilder.build(note)
|
2015-03-05 18:38:23 +00:00
|
|
|
base_data
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_data_for_commit(project, user, note)
|
|
|
|
# commit_id is the SHA hash
|
2015-04-21 13:13:40 +00:00
|
|
|
commit = project.commit(note.commit_id)
|
2015-04-21 13:15:49 +00:00
|
|
|
commit.hook_attrs
|
2015-03-05 18:38:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|