1
1
# Script for populating the database. You can run it as:
2
2
#
3
- # mix ecto.seed <your-github-id >
3
+ # mix ecto.seed <your-github-login >
4
4
5
5
import Algora.Factory
6
6
@@ -11,10 +11,10 @@ require Logger
11
11
12
12
Application . put_env ( :algora , :stripe_client , Algora.Support.StripeMock )
13
13
14
- github_id =
14
+ { :ok , github_user } =
15
15
case System . argv ( ) do
16
- [ github_id ] -> github_id
17
- _ -> "123456789"
16
+ [ github_handle ] -> Algora.Github . get_user_by_username ( nil , github_handle )
17
+ _ -> { :ok , nil }
18
18
end
19
19
20
20
pied_piper = upsert! ( :organization , [ :email ] )
@@ -23,7 +23,25 @@ erich =
23
23
upsert! (
24
24
:user ,
25
25
[ :provider , :provider_id ] ,
26
- % { provider_id: github_id , last_context: pied_piper . handle , is_admin: true }
26
+ % { last_context: pied_piper . handle , is_admin: true }
27
+ |> Map . merge (
28
+ if ( github_user ,
29
+ do: % {
30
+ provider: "github" ,
31
+ provider_login: github_user [ "login" ] ,
32
+ provider_id: to_string ( github_user [ "id" ] ) ,
33
+ handle: github_user [ "login" ] ,
34
+ display_name: github_user [ "name" ] ,
35
+ avatar_url: github_user [ "avatar_url" ] ,
36
+ website_url: github_user [ "blog" ] ,
37
+ twitter_url: "https://x.com/" <> github_user [ "twitter_username" ] ,
38
+ location: github_user [ "location" ] ,
39
+ bio: github_user [ "bio" ]
40
+ } ,
41
+ else: % { }
42
+ )
43
+ )
44
+ |> Map . merge ( if ( github_user && github_user [ "email" ] , do: % { email: github_user [ "email" ] } , else: % { } ) )
27
45
)
28
46
29
47
upsert! (
0 commit comments