@@ -10,10 +10,14 @@ defmodule AlgoraWeb.Admin.CampaignLive do
10
10
alias Algora.Admin
11
11
alias Algora.Mailer
12
12
alias Algora.Repo
13
+ alias Algora.Settings
14
+ alias Algora.Workspace
13
15
alias Algora.Workspace.Repository
14
16
alias AlgoraWeb.LocalStore
15
17
alias Swoosh.Email
16
18
19
+ require Logger
20
+
17
21
defmodule Campaign do
18
22
@ moduledoc false
19
23
use Ecto.Schema
@@ -182,7 +186,11 @@ defmodule AlgoraWeb.Admin.CampaignLive do
182
186
</ . button >
183
187
</ div >
184
188
< . 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
+ >
186
194
< . cell value = { row [ key ] } />
187
195
</: col >
188
196
<: action :let = { row } >
@@ -231,8 +239,8 @@ defmodule AlgoraWeb.Admin.CampaignLive do
231
239
defp assign_repo_names ( socket ) do
232
240
new_handles =
233
241
socket . assigns . csv_data
242
+ |> Enum . filter ( & ( & 1 [ "repo_url" ] == "" and & 1 [ "org_handle" ] != "" ) )
234
243
|> Enum . map ( & & 1 [ "org_handle" ] )
235
- |> Enum . reject ( & is_nil / 1 )
236
244
|> Enum . reject ( & Map . has_key? ( socket . assigns . repo_cache , & 1 ) )
237
245
|> Enum . uniq ( )
238
246
@@ -253,7 +261,7 @@ defmodule AlgoraWeb.Admin.CampaignLive do
253
261
)
254
262
255
263
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 ) )
257
265
{ org_handle , { repo , matches } }
258
266
else
259
267
{ org_handle , nil }
@@ -264,11 +272,30 @@ defmodule AlgoraWeb.Admin.CampaignLive do
264
272
265
273
csv_data =
266
274
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
270
297
271
- org_handle ->
298
+ or g_handle = row [ "org_handle" ] ->
272
299
case Map . get ( updated_cache , org_handle ) do
273
300
nil ->
274
301
row
@@ -281,6 +308,9 @@ defmodule AlgoraWeb.Admin.CampaignLive do
281
308
"matches" => Enum . map ( matches , & & 1 . user . handle )
282
309
} )
283
310
end
311
+
312
+ true ->
313
+ row
284
314
end
285
315
end )
286
316
0 commit comments