Skip to content

Commit

Permalink
adds handling for requests so seed file works
Browse files Browse the repository at this point in the history
  • Loading branch information
ZooeyMiller committed Sep 7, 2017
1 parent 172d73e commit f0331d6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ erl_crash.dump

env.sh
cover
*.env
9 changes: 4 additions & 5 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ hook_endpoint = System.get_env "HOOK_ENDPOINT"
GithubApi.get_repos("dwyl")
|> Enum.map(fn repo ->
Task.async(fn ->
hook_task = Task.async(fn ->
Hook.create "dwyl/#{repo}", hook_endpoint
end)
# hook_task = Task.async(fn ->
# Hook.create "dwyl/#{repo}", hook_endpoint
# end)
issue_task = Task.async(fn ->
GithubApi.get_help_wanted_issues("dwyl/#{repo}")
end)

Task.await(hook_task, timeout)
# Task.await(hook_task, timeout)
Task.await(issue_task, timeout)
end)
end)
Expand All @@ -29,4 +29,3 @@ GithubApi.get_repos("dwyl")
|> Issue.changeset(issue)
|> Repo.insert!
end)

9 changes: 8 additions & 1 deletion test/github/github_api_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Tudo.GithubApiTest do
test "post!" do
actual = GithubApi.post! "/", %{key: "val"}
expected = %{"method" => "post", "key" => "val"}

assert actual == expected
end

Expand Down Expand Up @@ -89,4 +89,11 @@ defmodule Tudo.GithubApiTest do

assert actual == expected
end

test "decode!" do
actual = GithubApi.decode! ""
expected = %{}

assert actual == expected
end
end
9 changes: 6 additions & 3 deletions web/github/github_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ defmodule Tudo.GithubApi do
[connect_timeout: 1_000_000,
recv_timeout: 1_000_000,
timeout: 1_000_000])
|> Map.fetch!(:body)
|> Poison.decode!
end
|> Map.get(:body, "{}")
|> decode!
end

def decode!(""), do: decode! "{}"
def decode!(str), do: Poison.decode! str

@doc"""
Gets all repos for an org, takes an :org string
Expand Down

0 comments on commit f0331d6

Please sign in to comment.