{"action":"created","comment":{"url":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls/comments/28499851","id":28499851,"diff_hunk":"@@ -0,0 +1,85 @@\n+from colander import (\n+    MappingSchema, SchemaNode, String, Boolean, OneOf, url)\n+\n+from cornice.resource import resource, view\n+\n+from pyramid import httpexceptions\n+from pyramid.view import view_config\n+\n+from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound\n+\n+from unicore.webhooks.models import DBSession, Webhook\n+from unicore.webhooks.events import (\n+    WebhookDeleted, WebhookCreated, WebhookUpdated)\n+\n+\n+class WebhookSchema(MappingSchema):\n+    url = SchemaNode(String(), location='body', validator=url)\n+    event_type = SchemaNode(\n+        String(), location='body',\n+        validator=OneOf([value for value, label in Webhook.TYPES]))\n+    active = SchemaNode(Boolean(), location='body')\n+\n+\n+# Raise SQLAlchemy exceptions as HTTP 404s\n+@view_config(context=NoResultFound)\n+@view_config(context=MultipleResultsFound)\n+def sqlachemy_error(exception, request):\n+    raise httpexceptions.HTTPNotFound()\n+\n+\n+@resource(collection_path='/hooks.json', path='/hooks/{uuid}.json')\n+class WebhooksResource(object):\n+\n+    def __init__(self, request):\n+        self.request = request\n+        self.webhooks = DBSession.query(Webhook). \\\n+            filter(Webhook.owner == request.authenticated_userid)\n+        self.config = request.registry.settings\n+\n+    @view(renderer='json')\n+    def collection_get(self):\n+        return [webhook.to_dict()\n+                for webhook in self.webhooks.all()]\n+\n+    @view(renderer='json')\n+    def get(self):\n+        return self.webhooks. \\\n+            filter(Webhook.uuid == self.request.matchdict['uuid']). \\\n+            one(). \\\n+            to_dict()\n+\n+    @view(renderer='json')\n+    def delete(self):\n+        webhook = self.webhooks. \\\n+            filter(Webhook.uuid == self.request.matchdict['uuid']). \\\n+            one()\n+        data = webhook.to_dict()\n+        DBSession.delete(webhook)\n+        self.request.registry.notify(WebhookDeleted(webhook, self.request))\n+        return data\n+\n+    @view(renderer='json', schema=WebhookSchema)\n+    def collection_post(self):\n+        url = self.request.validated['url']\n+        event_type = self.request.validated['event_type']\n+        active = self.request.validated['active']\n+        webhook = Webhook(owner=self.request.authenticated_userid,\n+                          url=url,\n+                          event_type=event_type,\n+                          active=active)\n+        data = webhook.to_dict()\n+        DBSession.add(webhook)\n+        self.request.registry.notify(WebhookCreated(webhook, self.request))\n+        return data\n+\n+    @view(renderer='json', schema=WebhookSchema)\n+    def put(self):\n+        webhook = self.webhooks. \\","path":"unicore/webhooks/views.py","position":78,"original_position":78,"commit_id":"1ba2b7686718b06553c6575af409d8f8d3d7fada","original_commit_id":"1ba2b7686718b06553c6575af409d8f8d3d7fada","user":{"login":"miltontony","id":623417,"avatar_url":"https://avatars.githubusercontent.com/u/623417?v=3","gravatar_id":"","url":"https://api.github.com/users/miltontony","html_url":"https://github.com/miltontony","followers_url":"https://api.github.com/users/miltontony/followers","following_url":"https://api.github.com/users/miltontony/following{/other_user}","gists_url":"https://api.github.com/users/miltontony/gists{/gist_id}","starred_url":"https://api.github.com/users/miltontony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miltontony/subscriptions","organizations_url":"https://api.github.com/users/miltontony/orgs","repos_url":"https://api.github.com/users/miltontony/repos","events_url":"https://api.github.com/users/miltontony/events{/privacy}","received_events_url":"https://api.github.com/users/miltontony/received_events","type":"User","site_admin":false},"body":"Cool, I think it does. @Rizziepit can you confirm?","created_at":"2015-04-16T10:50:03Z","updated_at":"2015-04-16T10:50:03Z","html_url":"https://github.com/universalcore/unicore.webhooks/pull/1#discussion_r28499851","pull_request_url":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls/comments/28499851"},"html":{"href":"https://github.com/universalcore/unicore.webhooks/pull/1#discussion_r28499851"},"pull_request":{"href":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls/1","id":33433799,"html_url":"https://github.com/universalcore/unicore.webhooks/pull/1","diff_url":"https://github.com/universalcore/unicore.webhooks/pull/1.diff","patch_url":"https://github.com/universalcore/unicore.webhooks/pull/1.patch","issue_url":"https://api.github.com/repos/universalcore/unicore.webhooks/issues/1","number":1,"state":"open","locked":false,"title":"Move stuff from unicore.distribute over here.","user":{"login":"smn","id":1065,"avatar_url":"https://avatars.githubusercontent.com/u/1065?v=3","gravatar_id":"","url":"https://api.github.com/users/smn","html_url":"https://github.com/smn","followers_url":"https://api.github.com/users/smn/followers","following_url":"https://api.github.com/users/smn/following{/other_user}","gists_url":"https://api.github.com/users/smn/gists{/gist_id}","starred_url":"https://api.github.com/users/smn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smn/subscriptions","organizations_url":"https://api.github.com/users/smn/orgs","repos_url":"https://api.github.com/users/smn/repos","events_url":"https://api.github.com/users/smn/events{/privacy}","received_events_url":"https://api.github.com/users/smn/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-04-16T09:41:34Z","updated_at":"2015-04-16T10:50:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8a55e7553c97f4ba28b2853318d76dc60f5961bd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls/1/commits","review_comments_url":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls/1/comments","review_comment_url":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls/comments{/number}","comments_url":"https://api.github.com/repos/universalcore/unicore.webhooks/issues/1/comments","statuses_url":"https://api.github.com/repos/universalcore/unicore.webhooks/statuses/1ba2b7686718b06553c6575af409d8f8d3d7fada","head":{"label":"universalcore:feature/issue-1-move-stuff-over-from-unicore-distribute","ref":"feature/issue-1-move-stuff-over-from-unicore-distribute","sha":"1ba2b7686718b06553c6575af409d8f8d3d7fada","user":{"login":"universalcore","id":8818658,"avatar_url":"https://avatars.githubusercontent.com/u/8818658?v=3","gravatar_id":"","url":"https://api.github.com/users/universalcore","html_url":"https://github.com/universalcore","followers_url":"https://api.github.com/users/universalcore/followers","following_url":"https://api.github.com/users/universalcore/following{/other_user}","gists_url":"https://api.github.com/users/universalcore/gists{/gist_id}","starred_url":"https://api.github.com/users/universalcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/universalcore/subscriptions","organizations_url":"https://api.github.com/users/universalcore/orgs","repos_url":"https://api.github.com/users/universalcore/repos","events_url":"https://api.github.com/users/universalcore/events{/privacy}","received_events_url":"https://api.github.com/users/universalcore/received_events","type":"Organization","site_admin":false},"repo":{"id":34045607,"name":"unicore.webhooks","full_name":"universalcore/unicore.webhooks","owner":{"login":"universalcore","id":8818658,"avatar_url":"https://avatars.githubusercontent.com/u/8818658?v=3","gravatar_id":"","url":"https://api.github.com/users/universalcore","html_url":"https://github.com/universalcore","followers_url":"https://api.github.com/users/universalcore/followers","following_url":"https://api.github.com/users/universalcore/following{/other_user}","gists_url":"https://api.github.com/users/universalcore/gists{/gist_id}","starred_url":"https://api.github.com/users/universalcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/universalcore/subscriptions","organizations_url":"https://api.github.com/users/universalcore/orgs","repos_url":"https://api.github.com/users/universalcore/repos","events_url":"https://api.github.com/users/universalcore/events{/privacy}","received_events_url":"https://api.github.com/users/universalcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/universalcore/unicore.webhooks","description":null,"fork":false,"url":"https://api.github.com/repos/universalcore/unicore.webhooks","forks_url":"https://api.github.com/repos/universalcore/unicore.webhooks/forks","keys_url":"https://api.github.com/repos/universalcore/unicore.webhooks/keys{/key_id}","collaborators_url":"https://api.github.com/repos/universalcore/unicore.webhooks/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/universalcore/unicore.webhooks/teams","hooks_url":"https://api.github.com/repos/universalcore/unicore.webhooks/hooks","issue_events_url":"https://api.github.com/repos/universalcore/unicore.webhooks/issues/events{/number}","events_url":"https://api.github.com/repos/universalcore/unicore.webhooks/events","assignees_url":"https://api.github.com/repos/universalcore/unicore.webhooks/assignees{/user}","branches_url":"https://api.github.com/repos/universalcore/unicore.webhooks/branches{/branch}","tags_url":"https://api.github.com/repos/universalcore/unicore.webhooks/tags","blobs_url":"https://api.github.com/repos/universalcore/unicore.webhooks/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/universalcore/unicore.webhooks/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/universalcore/unicore.webhooks/git/refs{/sha}","trees_url":"https://api.github.com/repos/universalcore/unicore.webhooks/git/trees{/sha}","statuses_url":"https://api.github.com/repos/universalcore/unicore.webhooks/statuses/{sha}","languages_url":"https://api.github.com/repos/universalcore/unicore.webhooks/languages","stargazers_url":"https://api.github.com/repos/universalcore/unicore.webhooks/stargazers","contributors_url":"https://api.github.com/repos/universalcore/unicore.webhooks/contributors","subscribers_url":"https://api.github.com/repos/universalcore/unicore.webhooks/subscribers","subscription_url":"https://api.github.com/repos/universalcore/unicore.webhooks/subscription","commits_url":"https://api.github.com/repos/universalcore/unicore.webhooks/commits{/sha}","git_commits_url":"https://api.github.com/repos/universalcore/unicore.webhooks/git/commits{/sha}","comments_url":"https://api.github.com/repos/universalcore/unicore.webhooks/comments{/number}","issue_comment_url":"https://api.github.com/repos/universalcore/unicore.webhooks/issues/comments{/number}","contents_url":"https://api.github.com/repos/universalcore/unicore.webhooks/contents/{+path}","compare_url":"https://api.github.com/repos/universalcore/unicore.webhooks/compare/{base}...{head}","merges_url":"https://api.github.com/repos/universalcore/unicore.webhooks/merges","archive_url":"https://api.github.com/repos/universalcore/unicore.webhooks/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/universalcore/unicore.webhooks/downloads","issues_url":"https://api.github.com/repos/universalcore/unicore.webhooks/issues{/number}","pulls_url":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls{/number}","milestones_url":"https://api.github.com/repos/universalcore/unicore.webhooks/milestones{/number}","notifications_url":"https://api.github.com/repos/universalcore/unicore.webhooks/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/universalcore/unicore.webhooks/labels{/name}","releases_url":"https://api.github.com/repos/universalcore/unicore.webhooks/releases{/id}","created_at":"2015-04-16T09:07:09Z","updated_at":"2015-04-16T09:07:09Z","pushed_at":"2015-04-16T09:49:44Z","git_url":"git://github.com/universalcore/unicore.webhooks.git","ssh_url":"git@github.com:universalcore/unicore.webhooks.git","clone_url":"https://github.com/universalcore/unicore.webhooks.git","svn_url":"https://github.com/universalcore/unicore.webhooks","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"base":{"label":"universalcore:develop","ref":"develop","sha":"fbd6d70ff6e3a79bdb06560a15f19faa8d74df80","user":{"login":"universalcore","id":8818658,"avatar_url":"https://avatars.githubusercontent.com/u/8818658?v=3","gravatar_id":"","url":"https://api.github.com/users/universalcore","html_url":"https://github.com/universalcore","followers_url":"https://api.github.com/users/universalcore/followers","following_url":"https://api.github.com/users/universalcore/following{/other_user}","gists_url":"https://api.github.com/users/universalcore/gists{/gist_id}","starred_url":"https://api.github.com/users/universalcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/universalcore/subscriptions","organizations_url":"https://api.github.com/users/universalcore/orgs","repos_url":"https://api.github.com/users/universalcore/repos","events_url":"https://api.github.com/users/universalcore/events{/privacy}","received_events_url":"https://api.github.com/users/universalcore/received_events","type":"Organization","site_admin":false},"repo":{"id":34045607,"name":"unicore.webhooks","full_name":"universalcore/unicore.webhooks","owner":{"login":"universalcore","id":8818658,"avatar_url":"https://avatars.githubusercontent.com/u/8818658?v=3","gravatar_id":"","url":"https://api.github.com/users/universalcore","html_url":"https://github.com/universalcore","followers_url":"https://api.github.com/users/universalcore/followers","following_url":"https://api.github.com/users/universalcore/following{/other_user}","gists_url":"https://api.github.com/users/universalcore/gists{/gist_id}","starred_url":"https://api.github.com/users/universalcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/universalcore/subscriptions","organizations_url":"https://api.github.com/users/universalcore/orgs","repos_url":"https://api.github.com/users/universalcore/repos","events_url":"https://api.github.com/users/universalcore/events{/privacy}","received_events_url":"https://api.github.com/users/universalcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/universalcore/unicore.webhooks","description":null,"fork":false,"url":"https://api.github.com/repos/universalcore/unicore.webhooks","forks_url":"https://api.github.com/repos/universalcore/unicore.webhooks/forks","keys_url":"https://api.github.com/repos/universalcore/unicore.webhooks/keys{/key_id}","collaborators_url":"https://api.github.com/repos/universalcore/unicore.webhooks/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/universalcore/unicore.webhooks/teams","hooks_url":"https://api.github.com/repos/universalcore/unicore.webhooks/hooks","issue_events_url":"https://api.github.com/repos/universalcore/unicore.webhooks/issues/events{/number}","events_url":"https://api.github.com/repos/universalcore/unicore.webhooks/events","assignees_url":"https://api.github.com/repos/universalcore/unicore.webhooks/assignees{/user}","branches_url":"https://api.github.com/repos/universalcore/unicore.webhooks/branches{/branch}","tags_url":"https://api.github.com/repos/universalcore/unicore.webhooks/tags","blobs_url":"https://api.github.com/repos/universalcore/unicore.webhooks/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/universalcore/unicore.webhooks/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/universalcore/unicore.webhooks/git/refs{/sha}","trees_url":"https://api.github.com/repos/universalcore/unicore.webhooks/git/trees{/sha}","statuses_url":"https://api.github.com/repos/universalcore/unicore.webhooks/statuses/{sha}","languages_url":"https://api.github.com/repos/universalcore/unicore.webhooks/languages","stargazers_url":"https://api.github.com/repos/universalcore/unicore.webhooks/stargazers","contributors_url":"https://api.github.com/repos/universalcore/unicore.webhooks/contributors","subscribers_url":"https://api.github.com/repos/universalcore/unicore.webhooks/subscribers","subscription_url":"https://api.github.com/repos/universalcore/unicore.webhooks/subscription","commits_url":"https://api.github.com/repos/universalcore/unicore.webhooks/commits{/sha}","git_commits_url":"https://api.github.com/repos/universalcore/unicore.webhooks/git/commits{/sha}","comments_url":"https://api.github.com/repos/universalcore/unicore.webhooks/comments{/number}","issue_comment_url":"https://api.github.com/repos/universalcore/unicore.webhooks/issues/comments{/number}","contents_url":"https://api.github.com/repos/universalcore/unicore.webhooks/contents/{+path}","compare_url":"https://api.github.com/repos/universalcore/unicore.webhooks/compare/{base}...{head}","merges_url":"https://api.github.com/repos/universalcore/unicore.webhooks/merges","archive_url":"https://api.github.com/repos/universalcore/unicore.webhooks/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/universalcore/unicore.webhooks/downloads","issues_url":"https://api.github.com/repos/universalcore/unicore.webhooks/issues{/number}","pulls_url":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls{/number}","milestones_url":"https://api.github.com/repos/universalcore/unicore.webhooks/milestones{/number}","notifications_url":"https://api.github.com/repos/universalcore/unicore.webhooks/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/universalcore/unicore.webhooks/labels{/name}","releases_url":"https://api.github.com/repos/universalcore/unicore.webhooks/releases{/id}","created_at":"2015-04-16T09:07:09Z","updated_at":"2015-04-16T09:07:09Z","pushed_at":"2015-04-16T09:49:44Z","git_url":"git://github.com/universalcore/unicore.webhooks.git","ssh_url":"git@github.com:universalcore/unicore.webhooks.git","clone_url":"https://github.com/universalcore/unicore.webhooks.git","svn_url":"https://github.com/universalcore/unicore.webhooks","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls/1"},"html":{"href":"https://github.com/universalcore/unicore.webhooks/pull/1"},"issue":{"href":"https://api.github.com/repos/universalcore/unicore.webhooks/issues/1"},"comments":{"href":"https://api.github.com/repos/universalcore/unicore.webhooks/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/universalcore/unicore.webhooks/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/universalcore/unicore.webhooks/statuses/1ba2b7686718b06553c6575af409d8f8d3d7fada"}}}}