Skip to content

Commit

Permalink
fix failing test after refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jan 30, 2025
1 parent 4199fe5 commit 04ab098
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/app/star.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule App.Star do
# We have multiple repos over 1k stars
# Therefore issuing all these requests at once
# would instantly hit the 5k/h GitHub API Request Limit
App.User.get_user_from_api(user)
App.User.create_user_with_hex(user)

{:ok, star} = create(%{ user_id: user.id, repo_id: repo_id })

Expand Down
21 changes: 11 additions & 10 deletions lib/app/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,37 @@ defmodule App.User do
data = App.GitHub.user(user.login)
# Not super happy about this crude error handling ... feel free to refactor.
if Map.has_key?(data, :status) && data.status == "404" do
# IO.inspect(" - - - - - - - - - - - - - - - - - #{user.login}")
# dbg(user)
# IO.inspect(" - - - - - - - - - - - - - - - - - - - - - - - ")
{:ok, user} = dummy_data(user) |> create()

user
else
{:ok, user} =
create_user_with_hex(data)
end
end

def create_user_with_hex(data) do
{:ok, user} =
map_github_user_fields_to_table(data)
|> Map.put(:hex, App.Img.get_avatar_color(data.avatar_url))
|> create()

user
end
user
end

# tidy data before insertion
def map_github_user_fields_to_table(u) do
Map.merge(u, %{
avatar_url: String.split(u.avatar_url, "?") |> List.first,
company: clean_company(u.company),
company: clean_company(u),
})
end

def clean_company(company) do
def clean_company(u) do
# avoid `String.replace(nil, "@", "", [])` error
if company == nil do
if not Map.has_key?(u, :company) or u.company == nil do
""
else
String.replace(company, "@", "")
String.replace(u.company, "@", "")
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/app_web/live/app_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule AppWeb.AppLive do
App.Repository.get_org_repos(org)
# get all stargazers for a given repo
|> Enum.map(fn repo ->
# dbg(repo)
dbg(repo)
# App.Star.get_stargazers_for_repo(owner, repo)
repo
end)
Expand Down

0 comments on commit 04ab098

Please sign in to comment.