GitHub PullRequestReviewCommentEvent at 2014-12-08 10:26:20
Repository: SimpSpector
Actor: DavidBadura
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/simplethings/SimpSpector/pulls/comments/21444733","id":21444733,"diff_hunk":"@@ -0,0 +1,112 @@\n+<?php\n+\n+namespace SimpleThings\\AppBundle\\Gadget;\n+\n+use SimpleThings\\AppBundle\\Entity\\Issue;\n+use SimpleThings\\AppBundle\\Workspace;\n+use Symfony\\Component\\OptionsResolver\\Options;\n+use Symfony\\Component\\OptionsResolver\\OptionsResolver;\n+\n+/**\n+ * @author Lars Wallenborn <lars@wallenborn.net>\n+ */\n+class CommentBlacklistGadget extends AbstractGadget\n+{\n+    const NAME = 'comment_blacklist';\n+\n+    /**\n+     * @param Workspace $workspace\n+     * @return Issue[]\n+     */\n+    public function run(Workspace $workspace)\n+    {\n+        $options = $this->prepareOptions(\n+            (array)$workspace->config[self::NAME],\n+            [\n+                'files'     => './',\n+                'blacklist' => [\n+                    'todo'        => Issue::LEVEL_NOTICE,\n+                    'dont commit' => Issue::LEVEL_ERROR,\n+                ]\n+            ],\n+            ['files', 'blacklist']\n+        );\n+        $issues  = [];\n+        foreach ($this->findPhpFiles($workspace->path, $options['files']) as $filename) {\n+            $issues = array_merge($this->processFile($filename, $options), $issues);\n+        }\n+\n+        return $issues;\n+    }\n+\n+    /**\n+     * @return string\n+     */\n+    public function getName()\n+    {\n+        return self::NAME;\n+    }\n+\n+    /**\n+     * @param string $filename\n+     * @param array $options\n+     * @return Issue[]\n+     */\n+    private function processFile($filename, array $options)\n+    {\n+        $comments = $this->extract($filename);\n+        $issues   = [];\n+        foreach ($comments as $comment) {\n+            $issues = array_merge($issues, $this->processComment($filename, $options, $comment));\n+        }\n+\n+        return $issues;\n+    }\n+\n+    /**\n+     * @param string $filename\n+     * @return array\n+     */\n+    private function extract($filename)\n+    {\n+        $allTokens     = token_get_all(file_get_contents($filename));\n+        $commentTokens = array_filter($allTokens, function ($token) {\n+            return (count($token) === 3) && (in_array($token[0], [372 /* T_COMMENT */, 373 /* T_DOC_COMMENT */]));\n+        });\n+\n+        return array_map(function ($comment) {\n+            return [\n+                'content' => $comment[1],\n+                'line'    => $comment[2],\n+            ];\n+        }, $commentTokens);\n+    }\n+\n+    /**\n+     * @param $filename\n+     * @param array $options\n+     * @param $comment\n+     * @return array\n+     */\n+    private function processComment($filename, array $options, $comment)\n+    {\n+        $issues = [];\n+        foreach ($options['blacklist'] as $needle => $level) {\n+            $segment = explode($needle, $comment['content']);\n+            array_pop($segment); // $segment has n+1 elements if there are n $needel s.\n+\n+            $offset = 0;\n+            foreach ($segment as $s) {\n+                $offset += count(explode(\"\\n\", $s)) - 1; // calculate the exact line number of the issue\n+\n+                $issue = new Issue(sprintf('found \"%s\" in a comment', $needle), $this->getName(), $level);","path":"src/SimpleThings/AppBundle/Gadget/CommentBlacklistGadget.php","position":102,"original_position":102,"commit_id":"a3f23c21844d9b45844ea5f35d2ebf1073c713b6","original_commit_id":"a3f23c21844d9b45844ea5f35d2ebf1073c713b6","user":{"login":"DavidBadura","id":470138,"avatar_url":"https://avatars.githubusercontent.com/u/470138?v=3","gravatar_id":"","url":"https://api.github.com/users/DavidBadura","html_url":"https://github.com/DavidBadura","followers_url":"https://api.github.com/users/DavidBadura/followers","following_url":"https://api.github.com/users/DavidBadura/following{/other_user}","gists_url":"https://api.github.com/users/DavidBadura/gists{/gist_id}","starred_url":"https://api.github.com/users/DavidBadura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DavidBadura/subscriptions","organizations_url":"https://api.github.com/users/DavidBadura/orgs","repos_url":"https://api.github.com/users/DavidBadura/repos","events_url":"https://api.github.com/users/DavidBadura/events{/privacy}","received_events_url":"https://api.github.com/users/DavidBadura/received_events","type":"User","site_admin":false},"body":"I think translating is not necessary. better you tests the configuration whether it has valid issue levels.","created_at":"2014-12-08T10:26:20Z","updated_at":"2014-12-08T10:26:20Z","html_url":"https://github.com/simplethings/SimpSpector/pull/38#discussion_r21444733","pull_request_url":"https://api.github.com/repos/simplethings/SimpSpector/pulls/38","_links":{"self":{"href":"https://api.github.com/repos/simplethings/SimpSpector/pulls/comments/21444733"},"html":{"href":"https://github.com/simplethings/SimpSpector/pull/38#discussion_r21444733"},"pull_request":{"href":"https://api.github.com/repos/simplethings/SimpSpector/pulls/38"}}},"pull_request":{"url":"https://api.github.com/repos/simplethings/SimpSpector/pulls/38","id":25228781,"html_url":"https://github.com/simplethings/SimpSpector/pull/38","diff_url":"https://github.com/simplethings/SimpSpector/pull/38.diff","patch_url":"https://github.com/simplethings/SimpSpector/pull/38.patch","issue_url":"https://api.github.com/repos/simplethings/SimpSpector/issues/38","number":38,"state":"open","locked":false,"title":"Feature/comment commenter gadget","user":{"login":"larsborn","id":1826897,"avatar_url":"https://avatars.githubusercontent.com/u/1826897?v=3","gravatar_id":"","url":"https://api.github.com/users/larsborn","html_url":"https://github.com/larsborn","followers_url":"https://api.github.com/users/larsborn/followers","following_url":"https://api.github.com/users/larsborn/following{/other_user}","gists_url":"https://api.github.com/users/larsborn/gists{/gist_id}","starred_url":"https://api.github.com/users/larsborn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/larsborn/subscriptions","organizations_url":"https://api.github.com/users/larsborn/orgs","repos_url":"https://api.github.com/users/larsborn/repos","events_url":"https://api.github.com/users/larsborn/events{/privacy}","received_events_url":"https://api.github.com/users/larsborn/received_events","type":"User","site_admin":false},"body":"see #29 for reference, so far we would like to test\r\n\r\n* [ ] `// @todo`\r\n* [ ] `// dont commit` or something similar\r\n\r\nboth features can be enabled/disabled in the config","created_at":"2014-11-29T23:46:18Z","updated_at":"2014-12-08T10:26:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"acffa4cae0da09f8ce86640611dd23c77fc7dd61","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/simplethings/SimpSpector/pulls/38/commits","review_comments_url":"https://api.github.com/repos/simplethings/SimpSpector/pulls/38/comments","review_comment_url":"https://api.github.com/repos/simplethings/SimpSpector/pulls/comments/{number}","comments_url":"https://api.github.com/repos/simplethings/SimpSpector/issues/38/comments","statuses_url":"https://api.github.com/repos/simplethings/SimpSpector/statuses/a3f23c21844d9b45844ea5f35d2ebf1073c713b6","head":{"label":"simplethings:feature/comment-commenter-gadget","ref":"feature/comment-commenter-gadget","sha":"a3f23c21844d9b45844ea5f35d2ebf1073c713b6","user":{"login":"simplethings","id":731482,"avatar_url":"https://avatars.githubusercontent.com/u/731482?v=3","gravatar_id":"","url":"https://api.github.com/users/simplethings","html_url":"https://github.com/simplethings","followers_url":"https://api.github.com/users/simplethings/followers","following_url":"https://api.github.com/users/simplethings/following{/other_user}","gists_url":"https://api.github.com/users/simplethings/gists{/gist_id}","starred_url":"https://api.github.com/users/simplethings/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simplethings/subscriptions","organizations_url":"https://api.github.com/users/simplethings/orgs","repos_url":"https://api.github.com/users/simplethings/repos","events_url":"https://api.github.com/users/simplethings/events{/privacy}","received_events_url":"https://api.github.com/users/simplethings/received_events","type":"Organization","site_admin":false},"repo":{"id":26141279,"name":"SimpSpector","full_name":"simplethings/SimpSpector","owner":{"login":"simplethings","id":731482,"avatar_url":"https://avatars.githubusercontent.com/u/731482?v=3","gravatar_id":"","url":"https://api.github.com/users/simplethings","html_url":"https://github.com/simplethings","followers_url":"https://api.github.com/users/simplethings/followers","following_url":"https://api.github.com/users/simplethings/following{/other_user}","gists_url":"https://api.github.com/users/simplethings/gists{/gist_id}","starred_url":"https://api.github.com/users/simplethings/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simplethings/subscriptions","organizations_url":"https://api.github.com/users/simplethings/orgs","repos_url":"https://api.github.com/users/simplethings/repos","events_url":"https://api.github.com/users/simplethings/events{/privacy}","received_events_url":"https://api.github.com/users/simplethings/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/simplethings/SimpSpector","description":"SimpleThings Code Inspector for gitlab (not even alpha) - Metrics, Static Code Analytics, Coding Standards, ...","fork":false,"url":"https://api.github.com/repos/simplethings/SimpSpector","forks_url":"https://api.github.com/repos/simplethings/SimpSpector/forks","keys_url":"https://api.github.com/repos/simplethings/SimpSpector/keys{/key_id}","collaborators_url":"https://api.github.com/repos/simplethings/SimpSpector/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/simplethings/SimpSpector/teams","hooks_url":"https://api.github.com/repos/simplethings/SimpSpector/hooks","issue_events_url":"https://api.github.com/repos/simplethings/SimpSpector/issues/events{/number}","events_url":"https://api.github.com/repos/simplethings/SimpSpector/events","assignees_url":"https://api.github.com/repos/simplethings/SimpSpector/assignees{/user}","branches_url":"https://api.github.com/repos/simplethings/SimpSpector/branches{/branch}","tags_url":"https://api.github.com/repos/simplethings/SimpSpector/tags","blobs_url":"https://api.github.com/repos/simplethings/SimpSpector/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/simplethings/SimpSpector/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/simplethings/SimpSpector/git/refs{/sha}","trees_url":"https://api.github.com/repos/simplethings/SimpSpector/git/trees{/sha}","statuses_url":"https://api.github.com/repos/simplethings/SimpSpector/statuses/{sha}","languages_url":"https://api.github.com/repos/simplethings/SimpSpector/languages","stargazers_url":"https://api.github.com/repos/simplethings/SimpSpector/stargazers","contributors_url":"https://api.github.com/repos/simplethings/SimpSpector/contributors","subscribers_url":"https://api.github.com/repos/simplethings/SimpSpector/subscribers","subscription_url":"https://api.github.com/repos/simplethings/SimpSpector/subscription","commits_url":"https://api.github.com/repos/simplethings/SimpSpector/commits{/sha}","git_commits_url":"https://api.github.com/repos/simplethings/SimpSpector/git/commits{/sha}","comments_url":"https://api.github.com/repos/simplethings/SimpSpector/comments{/number}","issue_comment_url":"https://api.github.com/repos/simplethings/SimpSpector/issues/comments/{number}","contents_url":"https://api.github.com/repos/simplethings/SimpSpector/contents/{+path}","compare_url":"https://api.github.com/repos/simplethings/SimpSpector/compare/{base}...{head}","merges_url":"https://api.github.com/repos/simplethings/SimpSpector/merges","archive_url":"https://api.github.com/repos/simplethings/SimpSpector/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/simplethings/SimpSpector/downloads","issues_url":"https://api.github.com/repos/simplethings/SimpSpector/issues{/number}","pulls_url":"https://api.github.com/repos/simplethings/SimpSpector/pulls{/number}","milestones_url":"https://api.github.com/repos/simplethings/SimpSpector/milestones{/number}","notifications_url":"https://api.github.com/repos/simplethings/SimpSpector/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/simplethings/SimpSpector/labels{/name}","releases_url":"https://api.github.com/repos/simplethings/SimpSpector/releases{/id}","created_at":"2014-11-03T22:12:14Z","updated_at":"2014-12-08T09:07:08Z","pushed_at":"2014-12-08T07:56:20Z","git_url":"git://github.com/simplethings/SimpSpector.git","ssh_url":"git@github.com:simplethings/SimpSpector.git","clone_url":"https://github.com/simplethings/SimpSpector.git","svn_url":"https://github.com/simplethings/SimpSpector","homepage":"","size":1066,"stargazers_count":5,"watchers_count":5,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":15,"forks":1,"open_issues":15,"watchers":5,"default_branch":"master"}},"base":{"label":"simplethings:master","ref":"master","sha":"5bf183b5aba08bec5ac1f881de9171299b889d34","user":{"login":"simplethings","id":731482,"avatar_url":"https://avatars.githubusercontent.com/u/731482?v=3","gravatar_id":"","url":"https://api.github.com/users/simplethings","html_url":"https://github.com/simplethings","followers_url":"https://api.github.com/users/simplethings/followers","following_url":"https://api.github.com/users/simplethings/following{/other_user}","gists_url":"https://api.github.com/users/simplethings/gists{/gist_id}","starred_url":"https://api.github.com/users/simplethings/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simplethings/subscriptions","organizations_url":"https://api.github.com/users/simplethings/orgs","repos_url":"https://api.github.com/users/simplethings/repos","events_url":"https://api.github.com/users/simplethings/events{/privacy}","received_events_url":"https://api.github.com/users/simplethings/received_events","type":"Organization","site_admin":false},"repo":{"id":26141279,"name":"SimpSpector","full_name":"simplethings/SimpSpector","owner":{"login":"simplethings","id":731482,"avatar_url":"https://avatars.githubusercontent.com/u/731482?v=3","gravatar_id":"","url":"https://api.github.com/users/simplethings","html_url":"https://github.com/simplethings","followers_url":"https://api.github.com/users/simplethings/followers","following_url":"https://api.github.com/users/simplethings/following{/other_user}","gists_url":"https://api.github.com/users/simplethings/gists{/gist_id}","starred_url":"https://api.github.com/users/simplethings/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simplethings/subscriptions","organizations_url":"https://api.github.com/users/simplethings/orgs","repos_url":"https://api.github.com/users/simplethings/repos","events_url":"https://api.github.com/users/simplethings/events{/privacy}","received_events_url":"https://api.github.com/users/simplethings/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/simplethings/SimpSpector","description":"SimpleThings Code Inspector for gitlab (not even alpha) - Metrics, Static Code Analytics, Coding Standards, ...","fork":false,"url":"https://api.github.com/repos/simplethings/SimpSpector","forks_url":"https://api.github.com/repos/simplethings/SimpSpector/forks","keys_url":"https://api.github.com/repos/simplethings/SimpSpector/keys{/key_id}","collaborators_url":"https://api.github.com/repos/simplethings/SimpSpector/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/simplethings/SimpSpector/teams","hooks_url":"https://api.github.com/repos/simplethings/SimpSpector/hooks","issue_events_url":"https://api.github.com/repos/simplethings/SimpSpector/issues/events{/number}","events_url":"https://api.github.com/repos/simplethings/SimpSpector/events","assignees_url":"https://api.github.com/repos/simplethings/SimpSpector/assignees{/user}","branches_url":"https://api.github.com/repos/simplethings/SimpSpector/branches{/branch}","tags_url":"https://api.github.com/repos/simplethings/SimpSpector/tags","blobs_url":"https://api.github.com/repos/simplethings/SimpSpector/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/simplethings/SimpSpector/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/simplethings/SimpSpector/git/refs{/sha}","trees_url":"https://api.github.com/repos/simplethings/SimpSpector/git/trees{/sha}","statuses_url":"https://api.github.com/repos/simplethings/SimpSpector/statuses/{sha}","languages_url":"https://api.github.com/repos/simplethings/SimpSpector/languages","stargazers_url":"https://api.github.com/repos/simplethings/SimpSpector/stargazers","contributors_url":"https://api.github.com/repos/simplethings/SimpSpector/contributors","subscribers_url":"https://api.github.com/repos/simplethings/SimpSpector/subscribers","subscription_url":"https://api.github.com/repos/simplethings/SimpSpector/subscription","commits_url":"https://api.github.com/repos/simplethings/SimpSpector/commits{/sha}","git_commits_url":"https://api.github.com/repos/simplethings/SimpSpector/git/commits{/sha}","comments_url":"https://api.github.com/repos/simplethings/SimpSpector/comments{/number}","issue_comment_url":"https://api.github.com/repos/simplethings/SimpSpector/issues/comments/{number}","contents_url":"https://api.github.com/repos/simplethings/SimpSpector/contents/{+path}","compare_url":"https://api.github.com/repos/simplethings/SimpSpector/compare/{base}...{head}","merges_url":"https://api.github.com/repos/simplethings/SimpSpector/merges","archive_url":"https://api.github.com/repos/simplethings/SimpSpector/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/simplethings/SimpSpector/downloads","issues_url":"https://api.github.com/repos/simplethings/SimpSpector/issues{/number}","pulls_url":"https://api.github.com/repos/simplethings/SimpSpector/pulls{/number}","milestones_url":"https://api.github.com/repos/simplethings/SimpSpector/milestones{/number}","notifications_url":"https://api.github.com/repos/simplethings/SimpSpector/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/simplethings/SimpSpector/labels{/name}","releases_url":"https://api.github.com/repos/simplethings/SimpSpector/releases{/id}","created_at":"2014-11-03T22:12:14Z","updated_at":"2014-12-08T09:07:08Z","pushed_at":"2014-12-08T07:56:20Z","git_url":"git://github.com/simplethings/SimpSpector.git","ssh_url":"git@github.com:simplethings/SimpSpector.git","clone_url":"https://github.com/simplethings/SimpSpector.git","svn_url":"https://github.com/simplethings/SimpSpector","homepage":"","size":1066,"stargazers_count":5,"watchers_count":5,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":15,"forks":1,"open_issues":15,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/simplethings/SimpSpector/pulls/38"},"html":{"href":"https://github.com/simplethings/SimpSpector/pull/38"},"issue":{"href":"https://api.github.com/repos/simplethings/SimpSpector/issues/38"},"comments":{"href":"https://api.github.com/repos/simplethings/SimpSpector/issues/38/comments"},"review_comments":{"href":"https://api.github.com/repos/simplethings/SimpSpector/pulls/38/comments"},"review_comment":{"href":"https://api.github.com/repos/simplethings/SimpSpector/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/simplethings/SimpSpector/pulls/38/commits"},"statuses":{"href":"https://api.github.com/repos/simplethings/SimpSpector/statuses/a3f23c21844d9b45844ea5f35d2ebf1073c713b6"}}}}