Skip to content

Commit

Permalink
Fix API calls and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Sep 27, 2017
1 parent 3c0ad71 commit 5ef76cd
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 119 deletions.
33 changes: 26 additions & 7 deletions lib/code_corps/github/comment/comment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule CodeCorps.GitHub.Comment do
user:
%User{} = user} = comment) do

endpoint = task |> get_endpoint()
endpoint = comment |> create_endpoint_for()
attrs = comment |> GitHub.Adapters.Comment.to_github_comment

with opts when is_list(opts) <- opts_for(user, installation) do
Expand All @@ -35,7 +35,7 @@ defmodule CodeCorps.GitHub.Comment do
user: %User{} = user,
github_id: id} = comment) do

endpoint = "#{task |> get_endpoint()}/#{id}"
endpoint = comment |> update_endpoint_for()
attrs = comment |> GitHub.Adapters.Comment.to_github_comment

with opts when is_list(opts) <- opts_for(user, installation) do
Expand All @@ -45,11 +45,30 @@ defmodule CodeCorps.GitHub.Comment do
end
end

@spec get_endpoint(Task.t) :: String.t
defp get_endpoint(%Task{
github_repo: %GithubRepo{github_account_login: owner, name: repo}
}) do
"/repos/#{owner}/#{repo}/issues/comments"
@spec update_endpoint_for(Comment.t) :: String.t
defp update_endpoint_for(
%Comment{
github_id: id,
task: %Task{
github_repo: %GithubRepo{
github_account_login: owner, name: repo
}
}
}) do
"/repos/#{owner}/#{repo}/issues/comments/#{id}"
end

@spec create_endpoint_for(Comment.t) :: String.t
defp create_endpoint_for(
%Comment{
task: %Task{
github_issue_number: number,
github_repo: %GithubRepo{
github_account_login: owner, name: repo
},
}
}) do
"/repos/#{owner}/#{repo}/issues/#{number}/comments"
end

@spec opts_for(User.t, GithubAppInstallation.t) :: list
Expand Down
Loading

0 comments on commit 5ef76cd

Please sign in to comment.