Skip to content

Commit edfcf57

Browse files
committed
feat: derive company domain from org email/website
1 parent 5087dcb commit edfcf57

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

lib/algora/accounts/schemas/user.ex

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,28 @@ defmodule Algora.Accounts.User do
318318
|> unique_constraint(:handle)
319319
end
320320

321+
def get_domain(%{"type" => type}) when type != "Organization", do: nil
322+
323+
def get_domain(%{"email" => email}) when is_binary(email) do
324+
domain = email |> String.split("@") |> List.last()
325+
326+
if not Algora.Crawler.blacklisted?(domain), do: domain
327+
end
328+
329+
def get_domain(%{"blog" => url}) when is_binary(url) do
330+
domain =
331+
with url when not is_nil(url) <- Algora.Util.normalize_url(url),
332+
%URI{host: host} when is_binary(host) and host != "" <- URI.parse(url) do
333+
host
334+
else
335+
_ -> nil
336+
end
337+
338+
if not Algora.Crawler.blacklisted?(domain), do: domain
339+
end
340+
341+
def get_domain(_meta), do: nil
342+
321343
def github_changeset(meta) do
322344
params = %{
323345
provider_id: to_string(meta["id"]),
@@ -328,7 +350,8 @@ defmodule Algora.Accounts.User do
328350
location: meta["location"],
329351
avatar_url: meta["avatar_url"],
330352
website_url: Algora.Util.normalize_url(meta["blog"]),
331-
github_url: meta["html_url"]
353+
github_url: meta["html_url"],
354+
domain: get_domain(meta)
332355
}
333356

334357
%User{provider: "github", provider_meta: meta}
@@ -343,7 +366,8 @@ defmodule Algora.Accounts.User do
343366
:location,
344367
:avatar_url,
345368
:website_url,
346-
:github_url
369+
:github_url,
370+
:domain
347371
]
348372
)
349373
|> generate_id()

0 commit comments

Comments
 (0)