@@ -14,6 +14,10 @@ defmodule Librecov.GithubService do
1414 handle_check_suite ( payload [ "action" ] , payload )
1515 end
1616
17+ def handle ( "installation" , payload ) do
18+ handle_installation ( payload [ "action" ] , payload )
19+ end
20+
1721 def handle ( event , _payload ) do
1822 Logger . debug ( "Unhandled event: #{ event } " )
1923 end
@@ -34,6 +38,17 @@ defmodule Librecov.GithubService do
3438 Logger . warn ( "Unhandled pr event: #{ event } " )
3539 end
3640
41+ def handle_installation ( "created" , payload ) do
42+ repos = payload [ "repositories" ] || [ ]
43+
44+ repos
45+ |> Enum . each ( & install / 1 )
46+ end
47+
48+ def handle_installation ( action , _payload ) do
49+ Logger . warn ( "Unhandled installation action: #{ action } " )
50+ end
51+
3752 defp install ( % { "id" => repo_id , "full_name" => name , "html_url" => base_url } ) do
3853 with { :ok , % Project { } } <-
3954 Repo . insert (
@@ -48,4 +63,7 @@ defmodule Librecov.GithubService do
4863 Logger . info ( "Installed Repo #{ name } " )
4964 end
5065 end
66+
67+ defp install ( % { "id" => _ , "full_name" => name } = data ) ,
68+ do: install ( % { data | "html_url" => "https://github.com/" <> name } )
5169end
0 commit comments