{"action":"created","comment":{"url":"https://api.github.com/repos/inaka/erlang-github/pulls/comments/27998413","id":27998413,"diff_hunk":"@@ -42,96 +80,121 @@ event(Module, Cred, #{headers := Headers, body := Body}) ->\n %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n \n %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%%% Statuses\n+set_status(FullState, StatusCred, ToolName, Context, EventData) ->\n+  #{ <<\"repository\">> := Repository\n+   , <<\"pull_request\">> := #{<<\"head\">> := Head}\n+   } = EventData,\n+  Repo = binary_to_list(maps:get(<<\"full_name\">>, Repository)),\n+  Sha = binary_to_list(maps:get(<<\"sha\">>, Head)),\n+  Description = status_description(FullState, ToolName),\n+  State = normalize_state(FullState),\n+  lager:debug(\n+    \"[Github WH] About to set ~s status in ~s to ~p: ~p\",\n+    [Context, Repo, State, Description]),\n+  egithub:create_status(StatusCred, Repo, Sha, State, Description, Context).\n+\n+status_description(pending, ToolName) ->\n+  ToolName ++ \" is checking your pull request\";\n+status_description(success, ToolName) ->\n+  ToolName ++ \" is satisfied with your pull request\";\n+status_description(error, ToolName) ->\n+  IoData =\n+    io_lib:format(\n+      \"~s is not happy with your PR, warnings were emitted\",\n+      [ToolName]),\n+  binary_to_list(iolist_to_binary(IoData));\n+status_description({failure, Error}, ToolName) ->\n+  IoData =\n+    io_lib:format(\"~s failed while reviewing your PR: `~p`\", [ToolName, Error]),\n+  binary_to_list(iolist_to_binary(IoData)).\n+\n+normalize_state({State, _}) -> State;\n+normalize_state(State) -> State.\n+\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n %%% Events\n \n--spec event(atom(), egithub:credentials(), event(), map()) ->\n-        ok | {error, term()}.\n-event(Module, Cred, <<\"pull_request\">>,\n+handle_pull_request(Module, Cred,\n       #{<<\"number\">> := PR, <<\"repository\">> := Repository} = Data) ->\n   Repo = binary_to_list(maps:get(<<\"full_name\">>, Repository)),\n   {ok, GithubFiles} = egithub:pull_req_files(Cred, Repo, PR),\n   case Module:handle_pull_request(Cred, Data, GithubFiles) of\n+    {ok, []} -> clean;\n     {ok, Messages} ->\n-          {ok, LineComments} = egithub:pull_req_comments(Cred, Repo, PR),\n-          {ok, IssueComments} = egithub:issue_comments(Cred, Repo, PR),\n-          Comments = LineComments ++ IssueComments,\n-          write_comments(Cred, Repo, PR, Comments, Messages);\n-      {error, Reason} ->\n-          {error, Reason}\n-  end;\n-event(_Config, _Cred, <<\"ping\">>, _Data) ->\n-  ok;\n-event(_Config, _Cred, Event, _Data) ->\n-  {error, io_lib:format(\"Nothing to do for event: ~p.~n\", [Event])}.\n+      {ok, LineComments} = egithub:pull_req_comments(Cred, Repo, PR),\n+      {ok, IssueComments} = egithub:issue_comments(Cred, Repo, PR),\n+      Comments = LineComments ++ IssueComments,\n+      write_comments(Cred, Repo, PR, Comments, Messages),\n+      with_warnings;\n+    {error, Reason} -> {error, Reason}\n+  end.\n \n %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n %%% Helper functions\n \n %% @doc Comment files that failed rules.\n+-spec write_comments(\n+    etighub:credentials(), string(), map(), [map()], [message()]) -> ok.\n write_comments(Cred, Repo, PR, Comments, Messages) ->\n-    lager:debug(\n-      \"[Github WH] About to write ~p messages (there are already ~p comments)\",\n-      [length(Messages), length(Comments)]),\n-    Fun =\n-        fun\n-            (#{text := Text,\n-               position := 0\n-              }) ->\n-                write_issue_comment(Cred, Repo, PR, Text, Comments);\n-            (#{commit_id := CommitId,\n-               path      := Path,\n-               position  := Position,\n-               text      := Text\n-              }) ->\n-                write_line_comment(Cred, Repo, PR, CommitId,\n-                                   Path, Position, Text, Comments)\n-        end,\n-    lists:foreach(Fun, Messages).\n+  lager:debug(\n+    \"[Github WH] About to write ~p messages (there are already ~p comments)\",\n+    [length(Messages), length(Comments)]),\n+  Fun =\n+    fun (#{text := Text, position := 0}) ->\n+          write_issue_comment(Cred, Repo, PR, Text, Comments);\n+        (#{commit_id := CommitId,\n+           path      := Path,\n+           position  := Position,\n+           text      := Text\n+          }) ->\n+          write_line_comment(Cred, Repo, PR, CommitId,\n+                             Path, Position, Text, Comments)\n+    end,\n+  lists:foreach(Fun, Messages).\n \n write_issue_comment(Cred, Repo, PR, Text, Comments) ->","path":"src/egithub_webhook.erl","position":167,"original_position":167,"commit_id":"49682eef61f99aac01bdcc2208d0cecda6331183","original_commit_id":"49682eef61f99aac01bdcc2208d0cecda6331183","user":{"login":"gadgetci","id":10134338,"avatar_url":"https://avatars.githubusercontent.com/u/10134338?v=3","gravatar_id":"","url":"https://api.github.com/users/gadgetci","html_url":"https://github.com/gadgetci","followers_url":"https://api.github.com/users/gadgetci/followers","following_url":"https://api.github.com/users/gadgetci/following{/other_user}","gists_url":"https://api.github.com/users/gadgetci/gists{/gist_id}","starred_url":"https://api.github.com/users/gadgetci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gadgetci/subscriptions","organizations_url":"https://api.github.com/users/gadgetci/orgs","repos_url":"https://api.github.com/users/gadgetci/repos","events_url":"https://api.github.com/users/gadgetci/events{/privacy}","received_events_url":"https://api.github.com/users/gadgetci/received_events","type":"User","site_admin":false},"body":"According to **Xref**:\n> `egithub_webhook:write_issue_comment/5` calls undefined function `lager:do_log/9`","created_at":"2015-04-08T18:26:21Z","updated_at":"2015-04-08T18:26:21Z","html_url":"https://github.com/inaka/erlang-github/pull/38#discussion_r27998413","pull_request_url":"https://api.github.com/repos/inaka/erlang-github/pulls/38","_links":{"self":{"href":"https://api.github.com/repos/inaka/erlang-github/pulls/comments/27998413"},"html":{"href":"https://github.com/inaka/erlang-github/pull/38#discussion_r27998413"},"pull_request":{"href":"https://api.github.com/repos/inaka/erlang-github/pulls/38"}}},"pull_request":{"url":"https://api.github.com/repos/inaka/erlang-github/pulls/38","id":32881417,"html_url":"https://github.com/inaka/erlang-github/pull/38","diff_url":"https://github.com/inaka/erlang-github/pull/38.diff","patch_url":"https://github.com/inaka/erlang-github/pull/38.patch","issue_url":"https://api.github.com/repos/inaka/erlang-github/issues/38","number":38,"state":"open","locked":false,"title":"Add status support to egithub_webhook","user":{"login":"elbrujohalcon","id":93657,"avatar_url":"https://avatars.githubusercontent.com/u/93657?v=3","gravatar_id":"","url":"https://api.github.com/users/elbrujohalcon","html_url":"https://github.com/elbrujohalcon","followers_url":"https://api.github.com/users/elbrujohalcon/followers","following_url":"https://api.github.com/users/elbrujohalcon/following{/other_user}","gists_url":"https://api.github.com/users/elbrujohalcon/gists{/gist_id}","starred_url":"https://api.github.com/users/elbrujohalcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elbrujohalcon/subscriptions","organizations_url":"https://api.github.com/users/elbrujohalcon/orgs","repos_url":"https://api.github.com/users/elbrujohalcon/repos","events_url":"https://api.github.com/users/elbrujohalcon/events{/privacy}","received_events_url":"https://api.github.com/users/elbrujohalcon/received_events","type":"User","site_admin":false},"body":"So that, using the github status API, it can report statuses in github PRs.","created_at":"2015-04-08T17:10:48Z","updated_at":"2015-04-08T18:26:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bdb881cfa273a48f977e0af3603802b70cbb5254","assignee":{"login":"elbrujohalcon","id":93657,"avatar_url":"https://avatars.githubusercontent.com/u/93657?v=3","gravatar_id":"","url":"https://api.github.com/users/elbrujohalcon","html_url":"https://github.com/elbrujohalcon","followers_url":"https://api.github.com/users/elbrujohalcon/followers","following_url":"https://api.github.com/users/elbrujohalcon/following{/other_user}","gists_url":"https://api.github.com/users/elbrujohalcon/gists{/gist_id}","starred_url":"https://api.github.com/users/elbrujohalcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elbrujohalcon/subscriptions","organizations_url":"https://api.github.com/users/elbrujohalcon/orgs","repos_url":"https://api.github.com/users/elbrujohalcon/repos","events_url":"https://api.github.com/users/elbrujohalcon/events{/privacy}","received_events_url":"https://api.github.com/users/elbrujohalcon/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/inaka/erlang-github/pulls/38/commits","review_comments_url":"https://api.github.com/repos/inaka/erlang-github/pulls/38/comments","review_comment_url":"https://api.github.com/repos/inaka/erlang-github/pulls/comments{/number}","comments_url":"https://api.github.com/repos/inaka/erlang-github/issues/38/comments","statuses_url":"https://api.github.com/repos/inaka/erlang-github/statuses/49682eef61f99aac01bdcc2208d0cecda6331183","head":{"label":"inaka:elbrujohalcon.38.add_status_support_to_egithub_","ref":"elbrujohalcon.38.add_status_support_to_egithub_","sha":"49682eef61f99aac01bdcc2208d0cecda6331183","user":{"login":"inaka","id":867053,"avatar_url":"https://avatars.githubusercontent.com/u/867053?v=3","gravatar_id":"","url":"https://api.github.com/users/inaka","html_url":"https://github.com/inaka","followers_url":"https://api.github.com/users/inaka/followers","following_url":"https://api.github.com/users/inaka/following{/other_user}","gists_url":"https://api.github.com/users/inaka/gists{/gist_id}","starred_url":"https://api.github.com/users/inaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inaka/subscriptions","organizations_url":"https://api.github.com/users/inaka/orgs","repos_url":"https://api.github.com/users/inaka/repos","events_url":"https://api.github.com/users/inaka/events{/privacy}","received_events_url":"https://api.github.com/users/inaka/received_events","type":"Organization","site_admin":false},"repo":{"id":22843216,"name":"erlang-github","full_name":"inaka/erlang-github","owner":{"login":"inaka","id":867053,"avatar_url":"https://avatars.githubusercontent.com/u/867053?v=3","gravatar_id":"","url":"https://api.github.com/users/inaka","html_url":"https://github.com/inaka","followers_url":"https://api.github.com/users/inaka/followers","following_url":"https://api.github.com/users/inaka/following{/other_user}","gists_url":"https://api.github.com/users/inaka/gists{/gist_id}","starred_url":"https://api.github.com/users/inaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inaka/subscriptions","organizations_url":"https://api.github.com/users/inaka/orgs","repos_url":"https://api.github.com/users/inaka/repos","events_url":"https://api.github.com/users/inaka/events{/privacy}","received_events_url":"https://api.github.com/users/inaka/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/inaka/erlang-github","description":"Github API client","fork":false,"url":"https://api.github.com/repos/inaka/erlang-github","forks_url":"https://api.github.com/repos/inaka/erlang-github/forks","keys_url":"https://api.github.com/repos/inaka/erlang-github/keys{/key_id}","collaborators_url":"https://api.github.com/repos/inaka/erlang-github/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/inaka/erlang-github/teams","hooks_url":"https://api.github.com/repos/inaka/erlang-github/hooks","issue_events_url":"https://api.github.com/repos/inaka/erlang-github/issues/events{/number}","events_url":"https://api.github.com/repos/inaka/erlang-github/events","assignees_url":"https://api.github.com/repos/inaka/erlang-github/assignees{/user}","branches_url":"https://api.github.com/repos/inaka/erlang-github/branches{/branch}","tags_url":"https://api.github.com/repos/inaka/erlang-github/tags","blobs_url":"https://api.github.com/repos/inaka/erlang-github/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/inaka/erlang-github/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/inaka/erlang-github/git/refs{/sha}","trees_url":"https://api.github.com/repos/inaka/erlang-github/git/trees{/sha}","statuses_url":"https://api.github.com/repos/inaka/erlang-github/statuses/{sha}","languages_url":"https://api.github.com/repos/inaka/erlang-github/languages","stargazers_url":"https://api.github.com/repos/inaka/erlang-github/stargazers","contributors_url":"https://api.github.com/repos/inaka/erlang-github/contributors","subscribers_url":"https://api.github.com/repos/inaka/erlang-github/subscribers","subscription_url":"https://api.github.com/repos/inaka/erlang-github/subscription","commits_url":"https://api.github.com/repos/inaka/erlang-github/commits{/sha}","git_commits_url":"https://api.github.com/repos/inaka/erlang-github/git/commits{/sha}","comments_url":"https://api.github.com/repos/inaka/erlang-github/comments{/number}","issue_comment_url":"https://api.github.com/repos/inaka/erlang-github/issues/comments{/number}","contents_url":"https://api.github.com/repos/inaka/erlang-github/contents/{+path}","compare_url":"https://api.github.com/repos/inaka/erlang-github/compare/{base}...{head}","merges_url":"https://api.github.com/repos/inaka/erlang-github/merges","archive_url":"https://api.github.com/repos/inaka/erlang-github/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/inaka/erlang-github/downloads","issues_url":"https://api.github.com/repos/inaka/erlang-github/issues{/number}","pulls_url":"https://api.github.com/repos/inaka/erlang-github/pulls{/number}","milestones_url":"https://api.github.com/repos/inaka/erlang-github/milestones{/number}","notifications_url":"https://api.github.com/repos/inaka/erlang-github/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/inaka/erlang-github/labels{/name}","releases_url":"https://api.github.com/repos/inaka/erlang-github/releases{/id}","created_at":"2014-08-11T15:05:15Z","updated_at":"2015-03-30T19:35:36Z","pushed_at":"2015-04-08T18:25:55Z","git_url":"git://github.com/inaka/erlang-github.git","ssh_url":"git@github.com:inaka/erlang-github.git","clone_url":"https://github.com/inaka/erlang-github.git","svn_url":"https://github.com/inaka/erlang-github","homepage":null,"size":525,"stargazers_count":5,"watchers_count":5,"language":"Erlang","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":5,"default_branch":"master"}},"base":{"label":"inaka:master","ref":"master","sha":"5916b117c9bb0133d3adeaceb1ed4f4fbee813ed","user":{"login":"inaka","id":867053,"avatar_url":"https://avatars.githubusercontent.com/u/867053?v=3","gravatar_id":"","url":"https://api.github.com/users/inaka","html_url":"https://github.com/inaka","followers_url":"https://api.github.com/users/inaka/followers","following_url":"https://api.github.com/users/inaka/following{/other_user}","gists_url":"https://api.github.com/users/inaka/gists{/gist_id}","starred_url":"https://api.github.com/users/inaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inaka/subscriptions","organizations_url":"https://api.github.com/users/inaka/orgs","repos_url":"https://api.github.com/users/inaka/repos","events_url":"https://api.github.com/users/inaka/events{/privacy}","received_events_url":"https://api.github.com/users/inaka/received_events","type":"Organization","site_admin":false},"repo":{"id":22843216,"name":"erlang-github","full_name":"inaka/erlang-github","owner":{"login":"inaka","id":867053,"avatar_url":"https://avatars.githubusercontent.com/u/867053?v=3","gravatar_id":"","url":"https://api.github.com/users/inaka","html_url":"https://github.com/inaka","followers_url":"https://api.github.com/users/inaka/followers","following_url":"https://api.github.com/users/inaka/following{/other_user}","gists_url":"https://api.github.com/users/inaka/gists{/gist_id}","starred_url":"https://api.github.com/users/inaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inaka/subscriptions","organizations_url":"https://api.github.com/users/inaka/orgs","repos_url":"https://api.github.com/users/inaka/repos","events_url":"https://api.github.com/users/inaka/events{/privacy}","received_events_url":"https://api.github.com/users/inaka/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/inaka/erlang-github","description":"Github API client","fork":false,"url":"https://api.github.com/repos/inaka/erlang-github","forks_url":"https://api.github.com/repos/inaka/erlang-github/forks","keys_url":"https://api.github.com/repos/inaka/erlang-github/keys{/key_id}","collaborators_url":"https://api.github.com/repos/inaka/erlang-github/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/inaka/erlang-github/teams","hooks_url":"https://api.github.com/repos/inaka/erlang-github/hooks","issue_events_url":"https://api.github.com/repos/inaka/erlang-github/issues/events{/number}","events_url":"https://api.github.com/repos/inaka/erlang-github/events","assignees_url":"https://api.github.com/repos/inaka/erlang-github/assignees{/user}","branches_url":"https://api.github.com/repos/inaka/erlang-github/branches{/branch}","tags_url":"https://api.github.com/repos/inaka/erlang-github/tags","blobs_url":"https://api.github.com/repos/inaka/erlang-github/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/inaka/erlang-github/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/inaka/erlang-github/git/refs{/sha}","trees_url":"https://api.github.com/repos/inaka/erlang-github/git/trees{/sha}","statuses_url":"https://api.github.com/repos/inaka/erlang-github/statuses/{sha}","languages_url":"https://api.github.com/repos/inaka/erlang-github/languages","stargazers_url":"https://api.github.com/repos/inaka/erlang-github/stargazers","contributors_url":"https://api.github.com/repos/inaka/erlang-github/contributors","subscribers_url":"https://api.github.com/repos/inaka/erlang-github/subscribers","subscription_url":"https://api.github.com/repos/inaka/erlang-github/subscription","commits_url":"https://api.github.com/repos/inaka/erlang-github/commits{/sha}","git_commits_url":"https://api.github.com/repos/inaka/erlang-github/git/commits{/sha}","comments_url":"https://api.github.com/repos/inaka/erlang-github/comments{/number}","issue_comment_url":"https://api.github.com/repos/inaka/erlang-github/issues/comments{/number}","contents_url":"https://api.github.com/repos/inaka/erlang-github/contents/{+path}","compare_url":"https://api.github.com/repos/inaka/erlang-github/compare/{base}...{head}","merges_url":"https://api.github.com/repos/inaka/erlang-github/merges","archive_url":"https://api.github.com/repos/inaka/erlang-github/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/inaka/erlang-github/downloads","issues_url":"https://api.github.com/repos/inaka/erlang-github/issues{/number}","pulls_url":"https://api.github.com/repos/inaka/erlang-github/pulls{/number}","milestones_url":"https://api.github.com/repos/inaka/erlang-github/milestones{/number}","notifications_url":"https://api.github.com/repos/inaka/erlang-github/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/inaka/erlang-github/labels{/name}","releases_url":"https://api.github.com/repos/inaka/erlang-github/releases{/id}","created_at":"2014-08-11T15:05:15Z","updated_at":"2015-03-30T19:35:36Z","pushed_at":"2015-04-08T18:25:55Z","git_url":"git://github.com/inaka/erlang-github.git","ssh_url":"git@github.com:inaka/erlang-github.git","clone_url":"https://github.com/inaka/erlang-github.git","svn_url":"https://github.com/inaka/erlang-github","homepage":null,"size":525,"stargazers_count":5,"watchers_count":5,"language":"Erlang","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/inaka/erlang-github/pulls/38"},"html":{"href":"https://github.com/inaka/erlang-github/pull/38"},"issue":{"href":"https://api.github.com/repos/inaka/erlang-github/issues/38"},"comments":{"href":"https://api.github.com/repos/inaka/erlang-github/issues/38/comments"},"review_comments":{"href":"https://api.github.com/repos/inaka/erlang-github/pulls/38/comments"},"review_comment":{"href":"https://api.github.com/repos/inaka/erlang-github/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/inaka/erlang-github/pulls/38/commits"},"statuses":{"href":"https://api.github.com/repos/inaka/erlang-github/statuses/49682eef61f99aac01bdcc2208d0cecda6331183"}}}}