@@ -10,10 +10,14 @@ defmodule AlgoraWeb.Admin.CampaignLive do
1010 alias Algora.Admin
1111 alias Algora.Mailer
1212 alias Algora.Repo
13+ alias Algora.Settings
14+ alias Algora.Workspace
1315 alias Algora.Workspace.Repository
1416 alias AlgoraWeb.LocalStore
1517 alias Swoosh.Email
1618
19+ require Logger
20+
1721 defmodule Campaign do
1822 @ moduledoc false
1923 use Ecto.Schema
@@ -182,7 +186,11 @@ defmodule AlgoraWeb.Admin.CampaignLive do
182186 </ . button >
183187 </ div >
184188 < . table id = "csv-data " rows = { @ csv_data } >
185- <: col :let = { row } :for = { key <- @ csv_columns } label = { key } >
189+ <: col
190+ :let = { row }
191+ :for = { key <- @ csv_columns |> Enum . filter ( & ( & 1 != "repo_url" ) ) }
192+ label = { key }
193+ >
186194 < . cell value = { row [ key ] } />
187195 </: col >
188196 <: action :let = { row } >
@@ -231,8 +239,8 @@ defmodule AlgoraWeb.Admin.CampaignLive do
231239 defp assign_repo_names ( socket ) do
232240 new_handles =
233241 socket . assigns . csv_data
242+ |> Enum . filter ( & ( & 1 [ "repo_url" ] == "" and & 1 [ "org_handle" ] != "" ) )
234243 |> Enum . map ( & & 1 [ "org_handle" ] )
235- |> Enum . reject ( & is_nil / 1 )
236244 |> Enum . reject ( & Map . has_key? ( socket . assigns . repo_cache , & 1 ) )
237245 |> Enum . uniq ( )
238246
@@ -253,7 +261,7 @@ defmodule AlgoraWeb.Admin.CampaignLive do
253261 )
254262
255263 if repo && repo . tech_stack != [ ] do
256- matches = Algora. Settings. get_tech_matches ( List . first ( repo . tech_stack ) )
264+ matches = Settings . get_tech_matches ( List . first ( repo . tech_stack ) )
257265 { org_handle , { repo , matches } }
258266 else
259267 { org_handle , nil }
@@ -264,11 +272,30 @@ defmodule AlgoraWeb.Admin.CampaignLive do
264272
265273 csv_data =
266274 Enum . map ( socket . assigns . csv_data , fn row ->
267- case row [ "org_handle" ] do
268- nil ->
269- row
275+ cond do
276+ is_binary ( row [ "repo_url" ] ) and row [ "repo_url" ] != "" ->
277+ repo_url = row [ "repo_url" ]
278+ [ owner , name ] = repo_url |> String . split ( "/" ) |> Enum . take ( - 2 )
279+
280+ token = Admin . token! ( )
281+
282+ with { :ok , repository } <- Workspace . ensure_repository ( token , owner , name ) ,
283+ { :ok , tech_stack } <- Workspace . ensure_repo_tech_stack ( token , repository ) do
284+ matches = if tech_stack == [ ] , do: [ ] , else: Settings . get_tech_matches ( List . first ( tech_stack ) )
285+
286+ Map . merge ( row , % {
287+ "repo_owner" => repository . user . provider_login ,
288+ "repo_name" => repository . name ,
289+ "tech_stack" => repository . tech_stack ,
290+ "matches" => Enum . map ( matches , & & 1 . user . handle )
291+ } )
292+ else
293+ error ->
294+ Logger . error ( "Failed to fetch repository #{ owner } /#{ name } : #{ inspect ( error ) } " )
295+ row
296+ end
270297
271- org_handle ->
298+ or g_handle = row [ "org_handle" ] ->
272299 case Map . get ( updated_cache , org_handle ) do
273300 nil ->
274301 row
@@ -281,6 +308,9 @@ defmodule AlgoraWeb.Admin.CampaignLive do
281308 "matches" => Enum . map ( matches , & & 1 . user . handle )
282309 } )
283310 end
311+
312+ true ->
313+ row
284314 end
285315 end )
286316
0 commit comments