{"action":"created","comment":{"url":"https://api.github.com/repos/SUSE/Portus/pulls/comments/65067426","id":65067426,"diff_hunk":"@@ -0,0 +1,148 @@\n+# == Schema Information\n+#\n+# Table name: webhooks\n+#\n+#  id             :integer          not null, primary key\n+#  namespace_id   :integer\n+#  url            :string(255)\n+#  username       :string(255)\n+#  password       :string(255)\n+#  request_method :integer\n+#  content_type   :integer\n+#  enabled        :boolean          default(\"0\")\n+#  created_at     :datetime         not null\n+#  updated_at     :datetime         not null\n+#\n+# Indexes\n+#\n+#  index_webhooks_on_namespace_id  (namespace_id)\n+#\n+\n+require \"base64\"\n+require \"typhoeus\"\n+require \"securerandom\"\n+require \"json\"\n+require \"uri\"\n+\n+# A Webhook describes a kind of callback to an endpoint defined by an URL.\n+# Further parameters are username and password, which are used for basic\n+# authentication. The parameters request_method and content_type are limitted\n+# to GET and POST, and application/json and application/x-www-form-urlencoded\n+# respectively. Webhooks can be enabled or disabled.\n+# After a webhook has been triggered with the provided parameters, a\n+# WebhookDelivery object is created.\n+class Webhook < ActiveRecord::Base\n+  include PublicActivity::Common\n+\n+  enum request_method: [\"GET\", \"POST\"]\n+  enum content_type: [\"application/json\", \"application/x-www-form-urlencoded\"]\n+\n+  belongs_to :namespace\n+\n+  has_many :deliveries, class_name: \"WebhookDelivery\", dependent: :destroy\n+  has_many :headers, class_name: \"WebhookHeader\", dependent: :destroy\n+\n+  validates :url, presence: true, url: true\n+\n+  # default to http if no protocol has been specified. If unspecified, the URL\n+  # validator will fail.\n+  before_validation do\n+    unless url.nil? || url.blank?\n+      self.url = \"http://#{url}\" unless url.start_with?(\"http://\") ||\n+          url.start_with?(\"https://\")\n+    end\n+  end\n+\n+  before_destroy :update_activities!\n+\n+  # Handle a push event from the registry. All enabled webhooks of the provided\n+  # namespace are triggered in parallel.\n+  def self.handle_push_event(event)\n+    registry = Registry.find_from_event(event)\n+    return if registry.nil?\n+\n+    namespace, = Namespace.get_from_name(event[\"target\"][\"repository\"], registry)\n+    return if namespace.nil?\n+\n+    hydra = Typhoeus::Hydra.hydra\n+\n+    Webhook.where(namespace: namespace).find_each do |webhook|\n+      next unless webhook.enabled\n+\n+      headers, auth = headers_from_webhook(webhook)\n+\n+      args = {\n+        method:  webhook.request_method,\n+        headers: headers,\n+        body:    JSON.generate(event),","path":"app/models/webhook.rb","position":77,"original_position":77,"commit_id":"a66bf481576f05b44da580e6f8709e3efe941dfc","original_commit_id":"a66bf481576f05b44da580e6f8709e3efe941dfc","user":{"login":"monstermunchkin","id":244787,"avatar_url":"https://avatars.githubusercontent.com/u/244787?v=3","gravatar_id":"","url":"https://api.github.com/users/monstermunchkin","html_url":"https://github.com/monstermunchkin","followers_url":"https://api.github.com/users/monstermunchkin/followers","following_url":"https://api.github.com/users/monstermunchkin/following{/other_user}","gists_url":"https://api.github.com/users/monstermunchkin/gists{/gist_id}","starred_url":"https://api.github.com/users/monstermunchkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monstermunchkin/subscriptions","organizations_url":"https://api.github.com/users/monstermunchkin/orgs","repos_url":"https://api.github.com/users/monstermunchkin/repos","events_url":"https://api.github.com/users/monstermunchkin/events{/privacy}","received_events_url":"https://api.github.com/users/monstermunchkin/received_events","type":"User","site_admin":false},"body":"If I remember correctly, there were some issues here when not explicitly using `JSON.generate`. I'll look into that again.","created_at":"2016-05-30T12:50:35Z","updated_at":"2016-05-30T12:50:35Z","html_url":"https://github.com/SUSE/Portus/pull/823#discussion_r65067426","pull_request_url":"https://api.github.com/repos/SUSE/Portus/pulls/823","_links":{"self":{"href":"https://api.github.com/repos/SUSE/Portus/pulls/comments/65067426"},"html":{"href":"https://github.com/SUSE/Portus/pull/823#discussion_r65067426"},"pull_request":{"href":"https://api.github.com/repos/SUSE/Portus/pulls/823"}}},"pull_request":{"url":"https://api.github.com/repos/SUSE/Portus/pulls/823","id":66806952,"html_url":"https://github.com/SUSE/Portus/pull/823","diff_url":"https://github.com/SUSE/Portus/pull/823.diff","patch_url":"https://github.com/SUSE/Portus/pull/823.patch","issue_url":"https://api.github.com/repos/SUSE/Portus/issues/823","number":823,"state":"open","locked":false,"title":"Webhook integration","user":{"login":"tboerger","id":156964,"avatar_url":"https://avatars.githubusercontent.com/u/156964?v=3","gravatar_id":"","url":"https://api.github.com/users/tboerger","html_url":"https://github.com/tboerger","followers_url":"https://api.github.com/users/tboerger/followers","following_url":"https://api.github.com/users/tboerger/following{/other_user}","gists_url":"https://api.github.com/users/tboerger/gists{/gist_id}","starred_url":"https://api.github.com/users/tboerger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tboerger/subscriptions","organizations_url":"https://api.github.com/users/tboerger/orgs","repos_url":"https://api.github.com/users/tboerger/repos","events_url":"https://api.github.com/users/tboerger/events{/privacy}","received_events_url":"https://api.github.com/users/tboerger/received_events","type":"User","site_admin":false},"body":"**This is a replacement for https://github.com/SUSE/Portus/pull/814 so that somebody else can takeover this feature**\r\n\r\nI have started to integrate the webhook implementation, this PR is work in progress, I just created this to gather feedback as soon as possible.\r\n\r\nThings that still needs to be done:\r\n\r\n* [x] Backend that triggers the defined webhooks on event\r\n* [x] Fix activities for deleted webhooks\r\n* [x] Webhook delete button fixed\r\n* [x] Listing of webhook deliveries\r\n* [x] Retrigger webhook functionality\r\n* [x] Write full specs","created_at":"2016-04-18T07:03:40Z","updated_at":"2016-05-30T12:50:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5eb730bdde5965a76f5aa989b39bbe3802fe8c7c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SUSE/Portus/pulls/823/commits","review_comments_url":"https://api.github.com/repos/SUSE/Portus/pulls/823/comments","review_comment_url":"https://api.github.com/repos/SUSE/Portus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SUSE/Portus/issues/823/comments","statuses_url":"https://api.github.com/repos/SUSE/Portus/statuses/a66bf481576f05b44da580e6f8709e3efe941dfc","head":{"label":"SUSE:feature/webhooks","ref":"feature/webhooks","sha":"a66bf481576f05b44da580e6f8709e3efe941dfc","user":{"login":"SUSE","id":1067733,"avatar_url":"https://avatars.githubusercontent.com/u/1067733?v=3","gravatar_id":"","url":"https://api.github.com/users/SUSE","html_url":"https://github.com/SUSE","followers_url":"https://api.github.com/users/SUSE/followers","following_url":"https://api.github.com/users/SUSE/following{/other_user}","gists_url":"https://api.github.com/users/SUSE/gists{/gist_id}","starred_url":"https://api.github.com/users/SUSE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUSE/subscriptions","organizations_url":"https://api.github.com/users/SUSE/orgs","repos_url":"https://api.github.com/users/SUSE/repos","events_url":"https://api.github.com/users/SUSE/events{/privacy}","received_events_url":"https://api.github.com/users/SUSE/received_events","type":"Organization","site_admin":false},"repo":{"id":33866783,"name":"Portus","full_name":"SUSE/Portus","owner":{"login":"SUSE","id":1067733,"avatar_url":"https://avatars.githubusercontent.com/u/1067733?v=3","gravatar_id":"","url":"https://api.github.com/users/SUSE","html_url":"https://github.com/SUSE","followers_url":"https://api.github.com/users/SUSE/followers","following_url":"https://api.github.com/users/SUSE/following{/other_user}","gists_url":"https://api.github.com/users/SUSE/gists{/gist_id}","starred_url":"https://api.github.com/users/SUSE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUSE/subscriptions","organizations_url":"https://api.github.com/users/SUSE/orgs","repos_url":"https://api.github.com/users/SUSE/repos","events_url":"https://api.github.com/users/SUSE/events{/privacy}","received_events_url":"https://api.github.com/users/SUSE/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SUSE/Portus","description":"Authorization service and frontend for Docker registry (v2)","fork":false,"url":"https://api.github.com/repos/SUSE/Portus","forks_url":"https://api.github.com/repos/SUSE/Portus/forks","keys_url":"https://api.github.com/repos/SUSE/Portus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SUSE/Portus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SUSE/Portus/teams","hooks_url":"https://api.github.com/repos/SUSE/Portus/hooks","issue_events_url":"https://api.github.com/repos/SUSE/Portus/issues/events{/number}","events_url":"https://api.github.com/repos/SUSE/Portus/events","assignees_url":"https://api.github.com/repos/SUSE/Portus/assignees{/user}","branches_url":"https://api.github.com/repos/SUSE/Portus/branches{/branch}","tags_url":"https://api.github.com/repos/SUSE/Portus/tags","blobs_url":"https://api.github.com/repos/SUSE/Portus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SUSE/Portus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SUSE/Portus/git/refs{/sha}","trees_url":"https://api.github.com/repos/SUSE/Portus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SUSE/Portus/statuses/{sha}","languages_url":"https://api.github.com/repos/SUSE/Portus/languages","stargazers_url":"https://api.github.com/repos/SUSE/Portus/stargazers","contributors_url":"https://api.github.com/repos/SUSE/Portus/contributors","subscribers_url":"https://api.github.com/repos/SUSE/Portus/subscribers","subscription_url":"https://api.github.com/repos/SUSE/Portus/subscription","commits_url":"https://api.github.com/repos/SUSE/Portus/commits{/sha}","git_commits_url":"https://api.github.com/repos/SUSE/Portus/git/commits{/sha}","comments_url":"https://api.github.com/repos/SUSE/Portus/comments{/number}","issue_comment_url":"https://api.github.com/repos/SUSE/Portus/issues/comments{/number}","contents_url":"https://api.github.com/repos/SUSE/Portus/contents/{+path}","compare_url":"https://api.github.com/repos/SUSE/Portus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SUSE/Portus/merges","archive_url":"https://api.github.com/repos/SUSE/Portus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SUSE/Portus/downloads","issues_url":"https://api.github.com/repos/SUSE/Portus/issues{/number}","pulls_url":"https://api.github.com/repos/SUSE/Portus/pulls{/number}","milestones_url":"https://api.github.com/repos/SUSE/Portus/milestones{/number}","notifications_url":"https://api.github.com/repos/SUSE/Portus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SUSE/Portus/labels{/name}","releases_url":"https://api.github.com/repos/SUSE/Portus/releases{/id}","deployments_url":"https://api.github.com/repos/SUSE/Portus/deployments","created_at":"2015-04-13T12:18:20Z","updated_at":"2016-05-30T08:04:57Z","pushed_at":"2016-05-30T10:46:44Z","git_url":"git://github.com/SUSE/Portus.git","ssh_url":"git@github.com:SUSE/Portus.git","clone_url":"https://github.com/SUSE/Portus.git","svn_url":"https://github.com/SUSE/Portus","homepage":"http://port.us.org/","size":19575,"stargazers_count":790,"watchers_count":790,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":147,"mirror_url":null,"open_issues_count":122,"forks":147,"open_issues":122,"watchers":790,"default_branch":"master"}},"base":{"label":"SUSE:master","ref":"master","sha":"52a00e3f86a7ed89cd2d532116a699ef88773d58","user":{"login":"SUSE","id":1067733,"avatar_url":"https://avatars.githubusercontent.com/u/1067733?v=3","gravatar_id":"","url":"https://api.github.com/users/SUSE","html_url":"https://github.com/SUSE","followers_url":"https://api.github.com/users/SUSE/followers","following_url":"https://api.github.com/users/SUSE/following{/other_user}","gists_url":"https://api.github.com/users/SUSE/gists{/gist_id}","starred_url":"https://api.github.com/users/SUSE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUSE/subscriptions","organizations_url":"https://api.github.com/users/SUSE/orgs","repos_url":"https://api.github.com/users/SUSE/repos","events_url":"https://api.github.com/users/SUSE/events{/privacy}","received_events_url":"https://api.github.com/users/SUSE/received_events","type":"Organization","site_admin":false},"repo":{"id":33866783,"name":"Portus","full_name":"SUSE/Portus","owner":{"login":"SUSE","id":1067733,"avatar_url":"https://avatars.githubusercontent.com/u/1067733?v=3","gravatar_id":"","url":"https://api.github.com/users/SUSE","html_url":"https://github.com/SUSE","followers_url":"https://api.github.com/users/SUSE/followers","following_url":"https://api.github.com/users/SUSE/following{/other_user}","gists_url":"https://api.github.com/users/SUSE/gists{/gist_id}","starred_url":"https://api.github.com/users/SUSE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUSE/subscriptions","organizations_url":"https://api.github.com/users/SUSE/orgs","repos_url":"https://api.github.com/users/SUSE/repos","events_url":"https://api.github.com/users/SUSE/events{/privacy}","received_events_url":"https://api.github.com/users/SUSE/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SUSE/Portus","description":"Authorization service and frontend for Docker registry (v2)","fork":false,"url":"https://api.github.com/repos/SUSE/Portus","forks_url":"https://api.github.com/repos/SUSE/Portus/forks","keys_url":"https://api.github.com/repos/SUSE/Portus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SUSE/Portus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SUSE/Portus/teams","hooks_url":"https://api.github.com/repos/SUSE/Portus/hooks","issue_events_url":"https://api.github.com/repos/SUSE/Portus/issues/events{/number}","events_url":"https://api.github.com/repos/SUSE/Portus/events","assignees_url":"https://api.github.com/repos/SUSE/Portus/assignees{/user}","branches_url":"https://api.github.com/repos/SUSE/Portus/branches{/branch}","tags_url":"https://api.github.com/repos/SUSE/Portus/tags","blobs_url":"https://api.github.com/repos/SUSE/Portus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SUSE/Portus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SUSE/Portus/git/refs{/sha}","trees_url":"https://api.github.com/repos/SUSE/Portus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SUSE/Portus/statuses/{sha}","languages_url":"https://api.github.com/repos/SUSE/Portus/languages","stargazers_url":"https://api.github.com/repos/SUSE/Portus/stargazers","contributors_url":"https://api.github.com/repos/SUSE/Portus/contributors","subscribers_url":"https://api.github.com/repos/SUSE/Portus/subscribers","subscription_url":"https://api.github.com/repos/SUSE/Portus/subscription","commits_url":"https://api.github.com/repos/SUSE/Portus/commits{/sha}","git_commits_url":"https://api.github.com/repos/SUSE/Portus/git/commits{/sha}","comments_url":"https://api.github.com/repos/SUSE/Portus/comments{/number}","issue_comment_url":"https://api.github.com/repos/SUSE/Portus/issues/comments{/number}","contents_url":"https://api.github.com/repos/SUSE/Portus/contents/{+path}","compare_url":"https://api.github.com/repos/SUSE/Portus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SUSE/Portus/merges","archive_url":"https://api.github.com/repos/SUSE/Portus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SUSE/Portus/downloads","issues_url":"https://api.github.com/repos/SUSE/Portus/issues{/number}","pulls_url":"https://api.github.com/repos/SUSE/Portus/pulls{/number}","milestones_url":"https://api.github.com/repos/SUSE/Portus/milestones{/number}","notifications_url":"https://api.github.com/repos/SUSE/Portus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SUSE/Portus/labels{/name}","releases_url":"https://api.github.com/repos/SUSE/Portus/releases{/id}","deployments_url":"https://api.github.com/repos/SUSE/Portus/deployments","created_at":"2015-04-13T12:18:20Z","updated_at":"2016-05-30T08:04:57Z","pushed_at":"2016-05-30T10:46:44Z","git_url":"git://github.com/SUSE/Portus.git","ssh_url":"git@github.com:SUSE/Portus.git","clone_url":"https://github.com/SUSE/Portus.git","svn_url":"https://github.com/SUSE/Portus","homepage":"http://port.us.org/","size":19575,"stargazers_count":790,"watchers_count":790,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":147,"mirror_url":null,"open_issues_count":122,"forks":147,"open_issues":122,"watchers":790,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SUSE/Portus/pulls/823"},"html":{"href":"https://github.com/SUSE/Portus/pull/823"},"issue":{"href":"https://api.github.com/repos/SUSE/Portus/issues/823"},"comments":{"href":"https://api.github.com/repos/SUSE/Portus/issues/823/comments"},"review_comments":{"href":"https://api.github.com/repos/SUSE/Portus/pulls/823/comments"},"review_comment":{"href":"https://api.github.com/repos/SUSE/Portus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SUSE/Portus/pulls/823/commits"},"statuses":{"href":"https://api.github.com/repos/SUSE/Portus/statuses/a66bf481576f05b44da580e6f8709e3efe941dfc"}}}}
{"actor":{"display_login":"monstermunchkin"}}