summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Zaitsev <kirik910@gmail.com>2014-09-15 11:10:35 +0400
committerKirill Zaitsev <kirik910@gmail.com>2014-10-02 12:58:02 +0400
commit1c9d2e39c1aef8e10ebff6e57c174c197a3a1c93 (patch)
tree15d71443e6cf169c2f50d1f4798634ca8cb318c0
parente2073f286e1eceb961795af5ea88a39b440e49ac (diff)
downloadgitlab-ce-1c9d2e39c1aef8e10ebff6e57c174c197a3a1c93.tar.gz
Hook attributes
-rw-r--r--app/models/commit.rb15
-rw-r--r--app/models/concerns/issuable.rb2
-rw-r--r--app/models/issue.rb4
-rw-r--r--app/models/merge_request.rb14
-rw-r--r--app/models/project.rb10
-rw-r--r--app/services/git_push_service.rb11
-rw-r--r--doc/web_hooks/web_hooks.md26
7 files changed, 70 insertions, 12 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index c8b2e0475ff..d18738a72dc 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -88,6 +88,21 @@ class Commit
description.present?
end
+ def hook_attrs(project)
+ path_with_namespace = project.path_with_namespace
+
+ {
+ id: id,
+ message: safe_message,
+ timestamp: committed_date.xmlschema,
+ url: "#{Gitlab.config.gitlab.url}/#{path_with_namespace}/commit/#{id}",
+ author: {
+ name: author_name,
+ email: author_email
+ }
+ }
+ end
+
# Discover issues should be closed when this commit is pushed to a project's
# default branch.
def closes_issues project
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index 698b5b8c30a..553087946d6 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -134,7 +134,7 @@ module Issuable
def to_hook_data
{
object_kind: self.class.name.underscore,
- object_attributes: self.attributes
+ object_attributes: hook_attrs
}
end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 45a8e43b03d..7c0344d38c2 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -48,6 +48,10 @@ class Issue < ActiveRecord::Base
state :closed
end
+ def hook_attrs
+ attributes
+ end
+
# Mentionable overrides.
def gfm_reference
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 4894c617674..e0358c1889c 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -211,6 +211,20 @@ class MergeRequest < ActiveRecord::Base
Gitlab::Satellite::MergeAction.new(current_user, self).format_patch
end
+ def hook_attrs
+ attrs = {
+ source: source_project.hook_attrs,
+ target: target_project.hook_attrs,
+ last_commit: nil
+ }
+
+ unless last_commit.nil?
+ attrs.merge!(last_commit: last_commit.hook_attrs(source_project))
+ end
+
+ attributes.merge!(attrs)
+ end
+
def for_fork?
target_project != source_project
end
diff --git a/app/models/project.rb b/app/models/project.rb
index f9278f19dad..f070e16b972 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -544,6 +544,16 @@ class Project < ActiveRecord::Base
end
end
+ def hook_attrs
+ {
+ name: name,
+ ssh_url: ssh_url_to_repo,
+ http_url: http_url_to_repo,
+ namespace: namespace.name,
+ visibility_level: visibility_level
+ }
+ end
+
# Reset events cache related to this project
#
# Since we do cache @event we need to reset cache in special cases:
diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb
index 17c84c78d2d..b2d20491392 100644
--- a/app/services/git_push_service.rb
+++ b/app/services/git_push_service.rb
@@ -150,16 +150,7 @@ class GitPushService
# will be passed as post receive hook data.
#
push_commits_limited.each do |commit|
- data[:commits] << {
- id: commit.id,
- message: commit.safe_message,
- timestamp: commit.committed_date.xmlschema,
- url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/commit/#{commit.id}",
- author: {
- name: commit.author_name,
- email: commit.author_email
- }
- }
+ data[:commits] << commit.hook_attrs(project)
end
data
diff --git a/doc/web_hooks/web_hooks.md b/doc/web_hooks/web_hooks.md
index 16817d1933d..31791da8074 100644
--- a/doc/web_hooks/web_hooks.md
+++ b/doc/web_hooks/web_hooks.md
@@ -109,7 +109,31 @@ Triggered when a new merge request is created or an existing merge request was u
"merge_status": "unchecked",
"target_project_id": 14,
"iid": 1,
- "description": ""
+ "description": "",
+ "source": {
+ "name": "awesome_project",
+ "ssh_url": "ssh://git@example.com/awesome_space/awesome_project.git",
+ "http_url": "http://example.com/awesome_space/awesome_project.git",
+ "visibility_level": 20,
+ "namespace": "awesome_space"
+ },
+ "target": {
+ "name": "awesome_project",
+ "ssh_url": "ssh://git@example.com/awesome_space/awesome_project.git",
+ "http_url": "http://example.com/awesome_space/awesome_project.git",
+ "visibility_level": 20,
+ "namespace": "awesome_space"
+ },
+ "last_commit": {
+ "id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
+ "message": "fixed readme",
+ "timestamp": "2012-01-03T23:36:29+02:00",
+ "url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
+ "author": {
+ "name": "GitLab dev user",
+ "email": "gitlabdev@dv6700.(none)"
+ }
+ }
}
}
```