{"action":"created","comment":{"url":"https://api.github.com/repos/privat/nit/pulls/comments/23272136","id":23272136,"diff_hunk":"@@ -0,0 +1,172 @@\n+# This file is part of NIT ( http://www.nitlanguage.org ).\n+#\n+# Licensed under the Apache License, Version 2.0 (the \"License\");\n+# you may not use this file except in compliance with the License.\n+# You may obtain a copy of the License at\n+#\n+#     http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS IS\" BASIS,\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+# See the License for the specific language governing permissions and\n+# limitations under the License.\n+\n+# Github hook event listening with `nitcorn`.\n+#\n+# Usage:\n+#\n+# ~~~\n+# import github::hooks\n+#\n+# # A simple hook listener that print received events in stdout.\n+# class LogHookListener\n+#\tsuper HookListener\n+#\n+#\tredef fun api: GithubAPI do return new GithubAPI(get_github_oauth)\n+#\n+#\tredef fun apply_event(event) do\n+#\t\tprintn \"[{event.repo.full_name}] \"\n+#\t\tif event isa CommitCommentEvent then\n+#\t\t\tprint \"new comment on commit {event.comment.commit.sha}\"\n+#\t\telse if event isa CreateEvent then\n+#\t\t\tprint \"new {event.ref_type} {event.ref}\"\n+#\t\telse if event isa DeleteEvent then\n+#\t\t\tprint \"deleted ref {event.ref_type} {event.ref}\"\n+#\t\telse if event isa DeploymentEvent then\n+#\t\t\tprint \"new deployment {event.name}\"\n+#\t\telse if event isa DeploymentStatusEvent then\n+#\t\t\tprint \"new deployment state {event.state}\"\n+#\t\telse if event isa ForkEvent then\n+#\t\t\tprint \"new fork {event.forkee.full_name}\"\n+#\t\telse if event isa IssueCommentEvent then\n+#\t\t\tprint \"new comment on #{event.issue.number}\"\n+#\t\telse if event isa IssuesEvent then\n+#\t\t\tprint \"new action {event.action} on #{event.issue.number}\"\n+#\t\telse if event isa MemberEvent then\n+#\t\t\tprint \"new member {event.member.login}\"\n+#\t\telse if event isa PullRequestEvent then\n+#\t\t\tprint \"new pr event on #{event.number}\"\n+#\t\telse if event isa PullRequestReviewCommentEvent then\n+#\t\t\tprint \"new pr comment on #{event.pull.number}\"\n+#\t\telse if event isa PushEvent then\n+#\t\t\tprint \"new push event from {event.ref}\"\n+#\t\telse if event isa StatusEvent then\n+#\t\t\tprint \"new status {event.state} for {event.commit.sha}\"\n+#\t\telse\n+#\t\t\tprint \"unknwon event...\"\n+#\t\tend\n+#\tend\n+# end\n+#\n+# var api = new GithubAPI(get_github_oauth)\n+# var listener = new LogHookListener(api, \"127.0.0.1\", 8080)\n+# # listener.listen # uncomment to start listening\n+# ~~~\n+module hooks\n+\n+import events\n+import nitcorn\n+\n+# A nitcorn listener for Github hooks.\n+class HookListener\n+\n+\t# Api client used to perform Github API requests.\n+\tvar api: GithubAPI\n+\n+\t# Host to listen.\n+\tvar host: String\n+\n+\t# Port to listen.\n+\tvar port: Int\n+\n+\t# VirtualHost listened\n+\tprivate var vh: VirtualHost is noinit\n+\n+\tinit do\n+\t\tvh = new VirtualHost(\"{host}:{port}\")\n+\t\tvh.routes.add new Route(\"/\", new HookAction(self))\n+\tend\n+\n+\t# Verbosity level (0: quiet, 1: debug).\n+\t# Default: 0\n+\tvar verbosity = 0\n+\n+\t# Print `message` if `lvl` <= `verbosity`\n+\tfun message(lvl: Int, message: String) do\n+\t\tif lvl <= verbosity then print message\n+\tend\n+\n+\t# Start listening and responding to event.\n+\tfun listen do\n+\t\tmessage(1, \"Hook listening on {host}:{port}\")\n+\t\tvar factory = new HttpFactory.and_libevent\n+\t\tfactory.config.virtual_hosts.add vh\n+\t\tfactory.run\n+\tend\n+\n+\t# How to build events from received json objects.\n+\tfun event_factory(kind: String, json: JsonObject): GithubEvent do\n+\t\tif kind == \"commit_comment\" then\n+\t\t\treturn new CommitCommentEvent.from_json(api, json)\n+\t\telse if kind == \"create\" then\n+\t\t\treturn new CreateEvent.from_json(api, json)\n+\t\telse if kind == \"delete\" then\n+\t\t\treturn new DeleteEvent.from_json(api, json)\n+\t\telse if kind == \"deployment\" then\n+\t\t\treturn new DeploymentEvent.from_json(api, json)\n+\t\telse if kind == \"deployment_status\" then\n+\t\t\treturn new DeploymentStatusEvent.from_json(api, json)\n+\t\telse if kind == \"fork\" then\n+\t\t\treturn new ForkEvent.from_json(api, json)\n+\t\telse if kind == \"issues\" then\n+\t\t\treturn new IssuesEvent.from_json(api, json)\n+\t\telse if kind == \"issue_comment\" then\n+\t\t\treturn new IssueCommentEvent.from_json(api, json)\n+\t\telse if kind == \"member\" then\n+\t\t\treturn new MemberEvent.from_json(api, json)\n+\t\telse if kind == \"pull_request\" then\n+\t\t\treturn new PullRequestEvent.from_json(api, json)\n+\t\telse if kind == \"pull_request_review_comment\" then\n+\t\t\treturn new PullRequestReviewCommentEvent.from_json(api, json)\n+\t\telse if kind == \"push\" then\n+\t\t\treturn new PushEvent.from_json(api, json)\n+\t\telse if kind == \"status\" then\n+\t\t\treturn new StatusEvent.from_json(api, json)\n+\t\telse\n+\t\t\treturn new GithubEvent.from_json(api, json)\n+\t\tend\n+\tend\n+\n+\t# What to do when we receive an event from a hook?\n+\t#\n+\t# This method MUST be defined in specialized listeners.","path":"lib/github/hooks.nit","position":143,"original_position":143,"commit_id":"421d5805d2113947e419c5f773b710fab16fe765","original_commit_id":"421d5805d2113947e419c5f773b710fab16fe765","user":{"login":"privat","id":135828,"avatar_url":"https://avatars.githubusercontent.com/u/135828?v=3","gravatar_id":"","url":"https://api.github.com/users/privat","html_url":"https://github.com/privat","followers_url":"https://api.github.com/users/privat/followers","following_url":"https://api.github.com/users/privat/following{/other_user}","gists_url":"https://api.github.com/users/privat/gists{/gist_id}","starred_url":"https://api.github.com/users/privat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/privat/subscriptions","organizations_url":"https://api.github.com/users/privat/orgs","repos_url":"https://api.github.com/users/privat/repos","events_url":"https://api.github.com/users/privat/events{/privacy}","received_events_url":"https://api.github.com/users/privat/received_events","type":"User","site_admin":false},"body":"est-ce que le `abstract` ne dit pas déjà \"This method MUST be defined in specialized subclasses\"?","created_at":"2015-01-21T01:24:28Z","updated_at":"2015-01-21T01:24:28Z","html_url":"https://github.com/privat/nit/pull/1115#discussion_r23272136","pull_request_url":"https://api.github.com/repos/privat/nit/pulls/1115","_links":{"self":{"href":"https://api.github.com/repos/privat/nit/pulls/comments/23272136"},"html":{"href":"https://github.com/privat/nit/pull/1115#discussion_r23272136"},"pull_request":{"href":"https://api.github.com/repos/privat/nit/pulls/1115"}}},"pull_request":{"url":"https://api.github.com/repos/privat/nit/pulls/1115","id":27691291,"html_url":"https://github.com/privat/nit/pull/1115","diff_url":"https://github.com/privat/nit/pull/1115.diff","patch_url":"https://github.com/privat/nit/pull/1115.patch","issue_url":"https://api.github.com/repos/privat/nit/issues/1115","number":1115,"state":"open","locked":false,"title":"lib/github: uses nitcorn to listen Github hook events.","user":{"login":"Morriar","id":583144,"avatar_url":"https://avatars.githubusercontent.com/u/583144?v=3","gravatar_id":"","url":"https://api.github.com/users/Morriar","html_url":"https://github.com/Morriar","followers_url":"https://api.github.com/users/Morriar/followers","following_url":"https://api.github.com/users/Morriar/following{/other_user}","gists_url":"https://api.github.com/users/Morriar/gists{/gist_id}","starred_url":"https://api.github.com/users/Morriar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Morriar/subscriptions","organizations_url":"https://api.github.com/users/Morriar/orgs","repos_url":"https://api.github.com/users/Morriar/repos","events_url":"https://api.github.com/users/Morriar/events{/privacy}","received_events_url":"https://api.github.com/users/Morriar/received_events","type":"User","site_admin":false},"body":"This module introduces an abstract listener for Github hooks with nitcorn.\r\n\r\nPS: OMG first PR with syntax highligh!!!! Thx @R4PaSs !\r\n\r\nSigned-off-by: Alexandre Terrasa <alexandre@moz-code.org>","created_at":"2015-01-20T16:34:03Z","updated_at":"2015-01-21T01:24:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1a12096d157a837bcd4c2611447f627e25632bf5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/privat/nit/pulls/1115/commits","review_comments_url":"https://api.github.com/repos/privat/nit/pulls/1115/comments","review_comment_url":"https://api.github.com/repos/privat/nit/pulls/comments/{number}","comments_url":"https://api.github.com/repos/privat/nit/issues/1115/comments","statuses_url":"https://api.github.com/repos/privat/nit/statuses/421d5805d2113947e419c5f773b710fab16fe765","head":{"label":"Morriar:github-api","ref":"github-api","sha":"421d5805d2113947e419c5f773b710fab16fe765","user":{"login":"Morriar","id":583144,"avatar_url":"https://avatars.githubusercontent.com/u/583144?v=3","gravatar_id":"","url":"https://api.github.com/users/Morriar","html_url":"https://github.com/Morriar","followers_url":"https://api.github.com/users/Morriar/followers","following_url":"https://api.github.com/users/Morriar/following{/other_user}","gists_url":"https://api.github.com/users/Morriar/gists{/gist_id}","starred_url":"https://api.github.com/users/Morriar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Morriar/subscriptions","organizations_url":"https://api.github.com/users/Morriar/orgs","repos_url":"https://api.github.com/users/Morriar/repos","events_url":"https://api.github.com/users/Morriar/events{/privacy}","received_events_url":"https://api.github.com/users/Morriar/received_events","type":"User","site_admin":false},"repo":{"id":1456691,"name":"nit","full_name":"Morriar/nit","owner":{"login":"Morriar","id":583144,"avatar_url":"https://avatars.githubusercontent.com/u/583144?v=3","gravatar_id":"","url":"https://api.github.com/users/Morriar","html_url":"https://github.com/Morriar","followers_url":"https://api.github.com/users/Morriar/followers","following_url":"https://api.github.com/users/Morriar/following{/other_user}","gists_url":"https://api.github.com/users/Morriar/gists{/gist_id}","starred_url":"https://api.github.com/users/Morriar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Morriar/subscriptions","organizations_url":"https://api.github.com/users/Morriar/orgs","repos_url":"https://api.github.com/users/Morriar/repos","events_url":"https://api.github.com/users/Morriar/events{/privacy}","received_events_url":"https://api.github.com/users/Morriar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Morriar/nit","description":"Nit language","fork":true,"url":"https://api.github.com/repos/Morriar/nit","forks_url":"https://api.github.com/repos/Morriar/nit/forks","keys_url":"https://api.github.com/repos/Morriar/nit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Morriar/nit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Morriar/nit/teams","hooks_url":"https://api.github.com/repos/Morriar/nit/hooks","issue_events_url":"https://api.github.com/repos/Morriar/nit/issues/events{/number}","events_url":"https://api.github.com/repos/Morriar/nit/events","assignees_url":"https://api.github.com/repos/Morriar/nit/assignees{/user}","branches_url":"https://api.github.com/repos/Morriar/nit/branches{/branch}","tags_url":"https://api.github.com/repos/Morriar/nit/tags","blobs_url":"https://api.github.com/repos/Morriar/nit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Morriar/nit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Morriar/nit/git/refs{/sha}","trees_url":"https://api.github.com/repos/Morriar/nit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Morriar/nit/statuses/{sha}","languages_url":"https://api.github.com/repos/Morriar/nit/languages","stargazers_url":"https://api.github.com/repos/Morriar/nit/stargazers","contributors_url":"https://api.github.com/repos/Morriar/nit/contributors","subscribers_url":"https://api.github.com/repos/Morriar/nit/subscribers","subscription_url":"https://api.github.com/repos/Morriar/nit/subscription","commits_url":"https://api.github.com/repos/Morriar/nit/commits{/sha}","git_commits_url":"https://api.github.com/repos/Morriar/nit/git/commits{/sha}","comments_url":"https://api.github.com/repos/Morriar/nit/comments{/number}","issue_comment_url":"https://api.github.com/repos/Morriar/nit/issues/comments/{number}","contents_url":"https://api.github.com/repos/Morriar/nit/contents/{+path}","compare_url":"https://api.github.com/repos/Morriar/nit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Morriar/nit/merges","archive_url":"https://api.github.com/repos/Morriar/nit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Morriar/nit/downloads","issues_url":"https://api.github.com/repos/Morriar/nit/issues{/number}","pulls_url":"https://api.github.com/repos/Morriar/nit/pulls{/number}","milestones_url":"https://api.github.com/repos/Morriar/nit/milestones{/number}","notifications_url":"https://api.github.com/repos/Morriar/nit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Morriar/nit/labels{/name}","releases_url":"https://api.github.com/repos/Morriar/nit/releases{/id}","created_at":"2011-03-08T22:16:33Z","updated_at":"2015-01-17T00:05:41Z","pushed_at":"2015-01-20T16:37:11Z","git_url":"git://github.com/Morriar/nit.git","ssh_url":"git@github.com:Morriar/nit.git","clone_url":"https://github.com/Morriar/nit.git","svn_url":"https://github.com/Morriar/nit","homepage":"http://nitlanguage.org","size":56212,"stargazers_count":2,"watchers_count":2,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":0,"forks":2,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"privat:master","ref":"master","sha":"036be01595b2709b2c8e5187c0e50177a1e06f89","user":{"login":"privat","id":135828,"avatar_url":"https://avatars.githubusercontent.com/u/135828?v=3","gravatar_id":"","url":"https://api.github.com/users/privat","html_url":"https://github.com/privat","followers_url":"https://api.github.com/users/privat/followers","following_url":"https://api.github.com/users/privat/following{/other_user}","gists_url":"https://api.github.com/users/privat/gists{/gist_id}","starred_url":"https://api.github.com/users/privat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/privat/subscriptions","organizations_url":"https://api.github.com/users/privat/orgs","repos_url":"https://api.github.com/users/privat/repos","events_url":"https://api.github.com/users/privat/events{/privacy}","received_events_url":"https://api.github.com/users/privat/received_events","type":"User","site_admin":false},"repo":{"id":328597,"name":"nit","full_name":"privat/nit","owner":{"login":"privat","id":135828,"avatar_url":"https://avatars.githubusercontent.com/u/135828?v=3","gravatar_id":"","url":"https://api.github.com/users/privat","html_url":"https://github.com/privat","followers_url":"https://api.github.com/users/privat/followers","following_url":"https://api.github.com/users/privat/following{/other_user}","gists_url":"https://api.github.com/users/privat/gists{/gist_id}","starred_url":"https://api.github.com/users/privat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/privat/subscriptions","organizations_url":"https://api.github.com/users/privat/orgs","repos_url":"https://api.github.com/users/privat/repos","events_url":"https://api.github.com/users/privat/events{/privacy}","received_events_url":"https://api.github.com/users/privat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/privat/nit","description":"Nit language","fork":false,"url":"https://api.github.com/repos/privat/nit","forks_url":"https://api.github.com/repos/privat/nit/forks","keys_url":"https://api.github.com/repos/privat/nit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/privat/nit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/privat/nit/teams","hooks_url":"https://api.github.com/repos/privat/nit/hooks","issue_events_url":"https://api.github.com/repos/privat/nit/issues/events{/number}","events_url":"https://api.github.com/repos/privat/nit/events","assignees_url":"https://api.github.com/repos/privat/nit/assignees{/user}","branches_url":"https://api.github.com/repos/privat/nit/branches{/branch}","tags_url":"https://api.github.com/repos/privat/nit/tags","blobs_url":"https://api.github.com/repos/privat/nit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/privat/nit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/privat/nit/git/refs{/sha}","trees_url":"https://api.github.com/repos/privat/nit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/privat/nit/statuses/{sha}","languages_url":"https://api.github.com/repos/privat/nit/languages","stargazers_url":"https://api.github.com/repos/privat/nit/stargazers","contributors_url":"https://api.github.com/repos/privat/nit/contributors","subscribers_url":"https://api.github.com/repos/privat/nit/subscribers","subscription_url":"https://api.github.com/repos/privat/nit/subscription","commits_url":"https://api.github.com/repos/privat/nit/commits{/sha}","git_commits_url":"https://api.github.com/repos/privat/nit/git/commits{/sha}","comments_url":"https://api.github.com/repos/privat/nit/comments{/number}","issue_comment_url":"https://api.github.com/repos/privat/nit/issues/comments/{number}","contents_url":"https://api.github.com/repos/privat/nit/contents/{+path}","compare_url":"https://api.github.com/repos/privat/nit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/privat/nit/merges","archive_url":"https://api.github.com/repos/privat/nit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/privat/nit/downloads","issues_url":"https://api.github.com/repos/privat/nit/issues{/number}","pulls_url":"https://api.github.com/repos/privat/nit/pulls{/number}","milestones_url":"https://api.github.com/repos/privat/nit/milestones{/number}","notifications_url":"https://api.github.com/repos/privat/nit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/privat/nit/labels{/name}","releases_url":"https://api.github.com/repos/privat/nit/releases{/id}","created_at":"2009-10-06T15:03:00Z","updated_at":"2015-01-20T07:23:19Z","pushed_at":"2015-01-20T07:31:06Z","git_url":"git://github.com/privat/nit.git","ssh_url":"git@github.com:privat/nit.git","clone_url":"https://github.com/privat/nit.git","svn_url":"https://github.com/privat/nit","homepage":"http://nitlanguage.org","size":73102,"stargazers_count":65,"watchers_count":65,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":36,"mirror_url":null,"open_issues_count":97,"forks":36,"open_issues":97,"watchers":65,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/privat/nit/pulls/1115"},"html":{"href":"https://github.com/privat/nit/pull/1115"},"issue":{"href":"https://api.github.com/repos/privat/nit/issues/1115"},"comments":{"href":"https://api.github.com/repos/privat/nit/issues/1115/comments"},"review_comments":{"href":"https://api.github.com/repos/privat/nit/pulls/1115/comments"},"review_comment":{"href":"https://api.github.com/repos/privat/nit/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/privat/nit/pulls/1115/commits"},"statuses":{"href":"https://api.github.com/repos/privat/nit/statuses/421d5805d2113947e419c5f773b710fab16fe765"}}}}