Skip to content

Commit 33d7043

Browse files
committed
update seed script for convenience
1 parent 81f6d3a commit 33d7043

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

priv/repo/seeds.exs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Script for populating the database. You can run it as:
22
#
3-
# mix ecto.seed <your-github-id>
3+
# mix ecto.seed <your-github-login>
44

55
import Algora.Factory
66

@@ -11,10 +11,10 @@ require Logger
1111

1212
Application.put_env(:algora, :stripe_client, Algora.Support.StripeMock)
1313

14-
github_id =
14+
{:ok, github_user} =
1515
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}
1818
end
1919

2020
pied_piper = upsert!(:organization, [:email])
@@ -23,7 +23,25 @@ erich =
2323
upsert!(
2424
:user,
2525
[: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: %{}))
2745
)
2846

2947
upsert!(

0 commit comments

Comments
 (0)