@@ -8,11 +8,14 @@ defmodule CodeCorps.GitHub.Event.IssueComment do
88
99 alias CodeCorps . {
1010 Comment ,
11+ GithubComment ,
1112 GithubRepo ,
1213 GitHub.Event.Common.RepoFinder ,
1314 GitHub.Event.Issues ,
15+ GitHub.Event.Issues.IssueLinker ,
1416 GitHub.Event.Issues.TaskSyncer ,
1517 GitHub.Event.IssueComment ,
18+ GitHub.Event.IssueComment.CommentLinker ,
1619 GitHub.Event.IssueComment.CommentSyncer ,
1720 GitHub.Event.IssueComment.CommentDeleter ,
1821 Repo
@@ -24,6 +27,7 @@ defmodule CodeCorps.GitHub.Event.IssueComment do
2427 { :error , :unexpected_payload } |
2528 { :error , :repository_not_found } |
2629 { :error , :validation_error_on_inserting_issue_for_task } |
30+ { :error , :validation_error_on_inserting_github_comment } |
2731 { :error , :validation_error_on_inserting_user_for_task } |
2832 { :error , :multiple_github_users_matched_same_cc_user_for_task } |
2933 { :error , :validation_error_on_inserting_user_for_comment } |
@@ -62,28 +66,40 @@ defmodule CodeCorps.GitHub.Event.IssueComment do
6266 end
6367
6468 @ spec operational_multi ( map ) :: Multi . t
65- defp operational_multi ( % { "action" => action , "issue" => issue_payload } = payload ) when action in ~w( created edited) do
69+ defp operational_multi ( % { "action" => action , "issue" => issue_payload , "comment" => comment_payload } = payload ) when action in ~w( created edited) do
6670 Multi . new
6771 |> Multi . run ( :repo , fn _ -> RepoFinder . find_repo ( payload ) end )
68- |> Multi . run ( :issue , fn % { repo: % GithubRepo { } = github_repo } -> github_repo |> Issues.IssueLinker . create_or_update_issue ( issue_payload ) end )
69- |> Multi . run ( :issue_user , fn % { issue: github_issue } -> github_issue |> Issues.UserLinker . find_or_create_user ( payload ) end )
72+ |> Multi . run ( :github_issue , fn % { repo: github_repo } -> github_repo |> link_issue ( payload ) end )
73+ |> Multi . run ( :github_comment , fn % { github_issue: github_issue } -> github_issue |> link_comment ( payload ) end )
74+ |> Multi . run ( :issue_user , fn % { github_issue: github_issue } -> github_issue |> Issues.UserLinker . find_or_create_user ( payload ) end )
7075 |> Multi . run ( :comment_user , fn _ -> IssueComment.UserLinker . find_or_create_user ( payload ) end )
71- |> Multi . run ( :tasks , fn % { issue : github_issue , issue_user: user } -> github_issue |> TaskSyncer . sync_all ( user , payload ) end )
72- |> Multi . run ( :comments , fn % { tasks: tasks , comment_user: user } -> CommentSyncer . sync_all ( tasks , user , payload ) end )
76+ |> Multi . run ( :tasks , fn % { github_issue : github_issue , issue_user: user } -> github_issue |> TaskSyncer . sync_all ( user , payload ) end )
77+ |> Multi . run ( :comments , fn % { github_comment: github_comment , tasks: tasks , comment_user: user } -> CommentSyncer . sync_all ( tasks , github_comment , user , payload ) end )
7378 end
7479 defp operational_multi ( % { "action" => "deleted" } = payload ) do
7580 Multi . new
7681 |> Multi . run ( :comments , fn _ -> CommentDeleter . delete_all ( payload ) end )
7782 end
7883 defp operational_multi ( % { } ) , do: Multi . new
7984
85+ @ spec link_issue ( GithubRepo . t , map ) :: { :ok , GithubIssue . t } | { :error , Ecto.Changeset . t }
86+ defp link_issue ( github_repo , % { "issue" => attrs } ) do
87+ IssueLinker . create_or_update_issue ( github_repo , attrs )
88+ end
89+
90+ @ spec link_comment ( GithubIssue . t , map ) :: { :ok , GithubComment . t } | { :error , Ecto.Changeset . t }
91+ defp link_comment ( github_issue , % { "comment" => attrs } ) do
92+ CommentLinker . create_or_update_comment ( github_issue , attrs )
93+ end
94+
8095 @ spec marshall_result ( tuple ) :: tuple
8196 defp marshall_result ( { :ok , % { comments: comments } } ) , do: { :ok , comments }
8297 defp marshall_result ( { :error , :payload , :invalid , _steps } ) , do: { :error , :unexpected_payload }
8398 defp marshall_result ( { :error , :action , :unexpected_action , _steps } ) , do: { :error , :unexpected_action }
8499 defp marshall_result ( { :error , :repo , :unmatched_project , _steps } ) , do: { :ok , [ ] }
85100 defp marshall_result ( { :error , :repo , :unmatched_repository , _steps } ) , do: { :error , :repository_not_found }
86- defp marshall_result ( { :error , :issue , % Ecto.Changeset { } , _steps } ) , do: { :error , :validation_error_on_inserting_issue_for_task }
101+ defp marshall_result ( { :error , :github_issue , % Ecto.Changeset { } , _steps } ) , do: { :error , :validation_error_on_inserting_issue_for_task }
102+ defp marshall_result ( { :error , :github_comment , % Ecto.Changeset { } , _steps } ) , do: { :error , :validation_error_on_inserting_github_comment }
87103 defp marshall_result ( { :error , :issue_user , % Ecto.Changeset { } , _steps } ) , do: { :error , :validation_error_on_inserting_user_for_task }
88104 defp marshall_result ( { :error , :issue_user , :multiple_users , _steps } ) , do: { :error , :multiple_github_users_matched_same_cc_user_for_task }
89105 defp marshall_result ( { :error , :comment_user , % Ecto.Changeset { } , _steps } ) , do: { :error , :validation_error_on_inserting_user_for_comment }
0 commit comments