{"action":"created","comment":{"url":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls/comments/41153404","id":41153404,"diff_hunk":"@@ -0,0 +1,72 @@\n+\"\"\"Sync external ressources with elastic search.\"\"\"\n+\n+import re\n+import requests\n+import logging\n+\n+from substanced.util import find_service\n+from pyramid.traversal import find_interface\n+\n+from adhocracy_core.interfaces import IResourceCreatedAndAdded, search_query\n+from adhocracy_core.interfaces import IResourceSheetModified\n+from adhocracy_core.resources.comment import IComment\n+from adhocracy_core.resources.external_resource import IExternalResource\n+from adhocracy_core.sheets.name import IName\n+from adhocracy_core.utils import get_sheet\n+\n+log = logging.getLogger(__name__)\n+\n+\n+def update_elasticsearch_policycompass(event):\n+    \"\"\"Push comments of IExternalResource ressources to elastic search.\"\"\"\n+    comment = event.object\n+    external_resource = find_interface(comment, IExternalResource)\n+\n+    if external_resource is None:\n+        return\n+\n+    ressource_name = get_sheet(external_resource, IName).get()['name']\n+    match = re.match(\n+        '(?P<type>visualization|event|dataset|metric|model|indicator)'\n+        '_(?P<id>[0-9]+)',\n+        ressource_name)\n+\n+    # this is not a known policycompass external resource\n+    if (match is None):\n+        return\n+\n+    resource_type = match.group('type')\n+    resource_id = match.group('id')\n+\n+    # count comments using catalog\n+    catalogs = find_service(external_resource, 'catalogs')\n+    query = search_query._replace(interfaces=IComment, only_visible=True)\n+    comment_count = catalogs.search(query).count\n+\n+    settings = event.registry.settings\n+    es_endpoint = settings.get('adhocracy_pcompass.elasticsearch_endpoint',\n+                               'http://localhost:9000')\n+    es_index = settings.get('adhocracy_pcompass.elasticsearch_index',\n+                            'policycompass_search')\n+    r = requests.post(\n+        '%s/%s/%s/%s/_update' %","path":"src/adhocracy_pcompass/adhocracy_pcompass/resources/subscriber.py","position":52,"original_position":52,"commit_id":"30d9dc139e7311890ba23aba12aa826c69e50ca2","original_commit_id":"30d9dc139e7311890ba23aba12aa826c69e50ca2","user":{"login":"pallix","id":676838,"avatar_url":"https://avatars.githubusercontent.com/u/676838?v=3","gravatar_id":"","url":"https://api.github.com/users/pallix","html_url":"https://github.com/pallix","followers_url":"https://api.github.com/users/pallix/followers","following_url":"https://api.github.com/users/pallix/following{/other_user}","gists_url":"https://api.github.com/users/pallix/gists{/gist_id}","starred_url":"https://api.github.com/users/pallix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pallix/subscriptions","organizations_url":"https://api.github.com/users/pallix/orgs","repos_url":"https://api.github.com/users/pallix/repos","events_url":"https://api.github.com/users/pallix/events{/privacy}","received_events_url":"https://api.github.com/users/pallix/received_events","type":"User","site_admin":false},"body":"the format method of the string class should be used instead for python3","created_at":"2015-10-05T14:57:29Z","updated_at":"2015-10-05T14:57:29Z","html_url":"https://github.com/liqd/adhocracy3.mercator/pull/1715#discussion_r41153404","pull_request_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls/1715","_links":{"self":{"href":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls/comments/41153404"},"html":{"href":"https://github.com/liqd/adhocracy3.mercator/pull/1715#discussion_r41153404"},"pull_request":{"href":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls/1715"}}},"pull_request":{"url":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls/1715","id":46645798,"html_url":"https://github.com/liqd/adhocracy3.mercator/pull/1715","diff_url":"https://github.com/liqd/adhocracy3.mercator/pull/1715.diff","patch_url":"https://github.com/liqd/adhocracy3.mercator/pull/1715.patch","issue_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/issues/1715","number":1715,"state":"open","locked":false,"title":"Add policycompass elastic search sync","user":{"login":"slomo","id":141032,"avatar_url":"https://avatars.githubusercontent.com/u/141032?v=3","gravatar_id":"","url":"https://api.github.com/users/slomo","html_url":"https://github.com/slomo","followers_url":"https://api.github.com/users/slomo/followers","following_url":"https://api.github.com/users/slomo/following{/other_user}","gists_url":"https://api.github.com/users/slomo/gists{/gist_id}","starred_url":"https://api.github.com/users/slomo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slomo/subscriptions","organizations_url":"https://api.github.com/users/slomo/orgs","repos_url":"https://api.github.com/users/slomo/repos","events_url":"https://api.github.com/users/slomo/events{/privacy}","received_events_url":"https://api.github.com/users/slomo/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-02T15:08:38Z","updated_at":"2015-10-05T14:57:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"786d2585e6156351164fb67507673dd78ac9e08c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls/1715/commits","review_comments_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls/1715/comments","review_comment_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls/comments{/number}","comments_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/issues/1715/comments","statuses_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/statuses/30d9dc139e7311890ba23aba12aa826c69e50ca2","head":{"label":"liqd:2015-10-ym-pcompass-subscriber-elasticsearch","ref":"2015-10-ym-pcompass-subscriber-elasticsearch","sha":"30d9dc139e7311890ba23aba12aa826c69e50ca2","user":{"login":"liqd","id":2312088,"avatar_url":"https://avatars.githubusercontent.com/u/2312088?v=3","gravatar_id":"","url":"https://api.github.com/users/liqd","html_url":"https://github.com/liqd","followers_url":"https://api.github.com/users/liqd/followers","following_url":"https://api.github.com/users/liqd/following{/other_user}","gists_url":"https://api.github.com/users/liqd/gists{/gist_id}","starred_url":"https://api.github.com/users/liqd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liqd/subscriptions","organizations_url":"https://api.github.com/users/liqd/orgs","repos_url":"https://api.github.com/users/liqd/repos","events_url":"https://api.github.com/users/liqd/events{/privacy}","received_events_url":"https://api.github.com/users/liqd/received_events","type":"Organization","site_admin":false},"repo":{"id":22982974,"name":"adhocracy3.mercator","full_name":"liqd/adhocracy3.mercator","owner":{"login":"liqd","id":2312088,"avatar_url":"https://avatars.githubusercontent.com/u/2312088?v=3","gravatar_id":"","url":"https://api.github.com/users/liqd","html_url":"https://github.com/liqd","followers_url":"https://api.github.com/users/liqd/followers","following_url":"https://api.github.com/users/liqd/following{/other_user}","gists_url":"https://api.github.com/users/liqd/gists{/gist_id}","starred_url":"https://api.github.com/users/liqd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liqd/subscriptions","organizations_url":"https://api.github.com/users/liqd/orgs","repos_url":"https://api.github.com/users/liqd/repos","events_url":"https://api.github.com/users/liqd/events{/privacy}","received_events_url":"https://api.github.com/users/liqd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/liqd/adhocracy3.mercator","description":"Adhocracy customizations for advocate-europe","fork":false,"url":"https://api.github.com/repos/liqd/adhocracy3.mercator","forks_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/forks","keys_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/teams","hooks_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/hooks","issue_events_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/issues/events{/number}","events_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/events","assignees_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/assignees{/user}","branches_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/branches{/branch}","tags_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/tags","blobs_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/git/refs{/sha}","trees_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/statuses/{sha}","languages_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/languages","stargazers_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/stargazers","contributors_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/contributors","subscribers_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/subscribers","subscription_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/subscription","commits_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/commits{/sha}","git_commits_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/git/commits{/sha}","comments_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/comments{/number}","issue_comment_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/issues/comments{/number}","contents_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/contents/{+path}","compare_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/merges","archive_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/downloads","issues_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/issues{/number}","pulls_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls{/number}","milestones_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/milestones{/number}","notifications_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/labels{/name}","releases_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/releases{/id}","created_at":"2014-08-15T08:07:57Z","updated_at":"2015-07-14T11:35:13Z","pushed_at":"2015-10-05T14:07:03Z","git_url":"git://github.com/liqd/adhocracy3.mercator.git","ssh_url":"git@github.com:liqd/adhocracy3.mercator.git","clone_url":"https://github.com/liqd/adhocracy3.mercator.git","svn_url":"https://github.com/liqd/adhocracy3.mercator","homepage":"","size":34381,"stargazers_count":8,"watchers_count":8,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":72,"forks":5,"open_issues":72,"watchers":8,"default_branch":"master"}},"base":{"label":"liqd:master","ref":"master","sha":"0ae112dcea7982b7b53bd68ad3f808aafb07c918","user":{"login":"liqd","id":2312088,"avatar_url":"https://avatars.githubusercontent.com/u/2312088?v=3","gravatar_id":"","url":"https://api.github.com/users/liqd","html_url":"https://github.com/liqd","followers_url":"https://api.github.com/users/liqd/followers","following_url":"https://api.github.com/users/liqd/following{/other_user}","gists_url":"https://api.github.com/users/liqd/gists{/gist_id}","starred_url":"https://api.github.com/users/liqd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liqd/subscriptions","organizations_url":"https://api.github.com/users/liqd/orgs","repos_url":"https://api.github.com/users/liqd/repos","events_url":"https://api.github.com/users/liqd/events{/privacy}","received_events_url":"https://api.github.com/users/liqd/received_events","type":"Organization","site_admin":false},"repo":{"id":22982974,"name":"adhocracy3.mercator","full_name":"liqd/adhocracy3.mercator","owner":{"login":"liqd","id":2312088,"avatar_url":"https://avatars.githubusercontent.com/u/2312088?v=3","gravatar_id":"","url":"https://api.github.com/users/liqd","html_url":"https://github.com/liqd","followers_url":"https://api.github.com/users/liqd/followers","following_url":"https://api.github.com/users/liqd/following{/other_user}","gists_url":"https://api.github.com/users/liqd/gists{/gist_id}","starred_url":"https://api.github.com/users/liqd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liqd/subscriptions","organizations_url":"https://api.github.com/users/liqd/orgs","repos_url":"https://api.github.com/users/liqd/repos","events_url":"https://api.github.com/users/liqd/events{/privacy}","received_events_url":"https://api.github.com/users/liqd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/liqd/adhocracy3.mercator","description":"Adhocracy customizations for advocate-europe","fork":false,"url":"https://api.github.com/repos/liqd/adhocracy3.mercator","forks_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/forks","keys_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/teams","hooks_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/hooks","issue_events_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/issues/events{/number}","events_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/events","assignees_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/assignees{/user}","branches_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/branches{/branch}","tags_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/tags","blobs_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/git/refs{/sha}","trees_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/statuses/{sha}","languages_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/languages","stargazers_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/stargazers","contributors_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/contributors","subscribers_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/subscribers","subscription_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/subscription","commits_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/commits{/sha}","git_commits_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/git/commits{/sha}","comments_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/comments{/number}","issue_comment_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/issues/comments{/number}","contents_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/contents/{+path}","compare_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/merges","archive_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/downloads","issues_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/issues{/number}","pulls_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls{/number}","milestones_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/milestones{/number}","notifications_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/labels{/name}","releases_url":"https://api.github.com/repos/liqd/adhocracy3.mercator/releases{/id}","created_at":"2014-08-15T08:07:57Z","updated_at":"2015-07-14T11:35:13Z","pushed_at":"2015-10-05T14:07:03Z","git_url":"git://github.com/liqd/adhocracy3.mercator.git","ssh_url":"git@github.com:liqd/adhocracy3.mercator.git","clone_url":"https://github.com/liqd/adhocracy3.mercator.git","svn_url":"https://github.com/liqd/adhocracy3.mercator","homepage":"","size":34381,"stargazers_count":8,"watchers_count":8,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":72,"forks":5,"open_issues":72,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls/1715"},"html":{"href":"https://github.com/liqd/adhocracy3.mercator/pull/1715"},"issue":{"href":"https://api.github.com/repos/liqd/adhocracy3.mercator/issues/1715"},"comments":{"href":"https://api.github.com/repos/liqd/adhocracy3.mercator/issues/1715/comments"},"review_comments":{"href":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls/1715/comments"},"review_comment":{"href":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/liqd/adhocracy3.mercator/pulls/1715/commits"},"statuses":{"href":"https://api.github.com/repos/liqd/adhocracy3.mercator/statuses/30d9dc139e7311890ba23aba12aa826c69e50ca2"}}}}