11defmodule CodeCorps.GitHub.Sync do
22 @ moduledoc """
3- Syncs events received from the GitHub API and also syncs entire GitHub
4- repositories.
3+ GitHub syncing functions for:
4+
5+ - events received from the GitHub API
6+ - entire GitHub repositories
57 """
68
79 alias CodeCorps . {
@@ -11,29 +13,12 @@ defmodule CodeCorps.GitHub.Sync do
1113 GitHub.Sync.Utils.Finder ,
1214 GitHub.Utils.ResultAggregator ,
1315 GithubAppInstallation ,
14- GithubPullRequest ,
1516 GithubRepo ,
1617 Repo ,
1718 Task
1819 }
19-
2020 alias Ecto . { Changeset , Multi }
2121
22- @ type outcome :: { :ok , list ( Comment . t ( ) ) }
23- | { :ok , GithubPullRequest . t ( ) }
24- | { :error , :repo_not_found , % { } }
25- | { :error , :fetching_issue }
26- | { :error , :fetching_pull_request }
27- | { :error , :multiple_comment_users_match }
28- | { :error , :validating_github_pull_request }
29- | { :error , :validating_github_comment }
30- | { :error , :validating_user }
31- | { :error , :validating_task }
32- | { :error , :validating_comment }
33- | { :error , :unexpected_transaction_outcome }
34-
35-
36-
3722 @ type issue_event_outcome ::
3823 { :ok , Task . t ( ) } |
3924 { :error , :repo_not_found , map } |
@@ -102,8 +87,6 @@ defmodule CodeCorps.GitHub.Sync do
10287 { :error , :fetching_pull_request , struct } |
10388 { :error , :validating_github_pull_request , Changeset . t ( ) }
10489
105-
106-
10790 @ doc ~S"""
10891 Syncs a GitHub IssueComment event.
10992
@@ -241,7 +224,7 @@ defmodule CodeCorps.GitHub.Sync do
241224 { :error , :repo , :unmatched_repository , _steps } ->
242225 { :error , :repo_not_found , % { } }
243226
244- { :error , :github_issue , % Ecto. Changeset{ } = changeset , _steps } ->
227+ { :error , :github_issue , % Changeset { } = changeset , _steps } ->
245228 { :error , :validating_github_issue , changeset }
246229
247230 { :error , :issue_user , % Changeset { } = changeset , _steps } ->
@@ -336,10 +319,10 @@ defmodule CodeCorps.GitHub.Sync do
336319 @ doc ~S"""
337320 Syncs a GitHub InstallationRepositories event.
338321
339- - For the "removed" action
340- - Deletes all `CodeCorps.GithubRepo` records matched with the payload
341- - For the "added" action
342- -
322+ - For the "removed" action:
323+ - Deletes all `CodeCorps.GithubRepo` records matched with the payload
324+ - For the "added" action:
325+ - Adds all `CodeCorps.GithubRepo` records matching data from the payload
343326
344327 [https://developer.github.com/v3/activity/events/types/#installationrepositoriesevent](https://developer.github.com/v3/activity/events/types/#installationrepositoriesevent)
345328 """
@@ -446,7 +429,7 @@ defmodule CodeCorps.GitHub.Sync do
446429 end
447430
448431 @ doc ~S"""
449- Syncs a `GithubRepo` with Code Corps .
432+ Syncs a `GithubRepo`.
450433
451434 Fetches and syncs records from the GitHub API for a given repository, marking
452435 progress of the sync state along the way.
@@ -508,6 +491,14 @@ defmodule CodeCorps.GitHub.Sync do
508491 end
509492 end
510493
494+ @ spec mark_repo ( GithubRepo . t ( ) , String . t ( ) , map ) ::
495+ { :ok , GithubRepo . t ( ) } | { :error , Changeset . t ( ) }
496+ defp mark_repo ( % GithubRepo { } = repo , sync_state , params \\ % { } ) do
497+ repo
498+ |> GithubRepo . update_sync_changeset ( params |> Map . put ( :sync_state , sync_state ) )
499+ |> Repo . update
500+ end
501+
511502 @ spec pair_issues_payloads_with_prs ( list , list ) :: list ( tuple )
512503 defp pair_issues_payloads_with_prs ( issue_payloads , pull_requests ) do
513504 issue_payloads |> Enum . map ( fn % { "number" => number } = issue_payload ->
@@ -532,12 +523,4 @@ defmodule CodeCorps.GitHub.Sync do
532523 @ spec sync_step ( tuple , atom ) :: tuple
533524 defp sync_step ( { :ok , _ } = result , _step ) , do: result
534525 defp sync_step ( { :error , _ } , step ) , do: { :error , step }
535-
536- @ spec mark_repo ( GithubRepo . t ( ) , String . t ( ) , map ) ::
537- { :ok , GithubRepo . t ( ) } | { :error , Changeset . t ( ) }
538- defp mark_repo ( % GithubRepo { } = repo , sync_state , params \\ % { } ) do
539- repo
540- |> GithubRepo . update_sync_changeset ( params |> Map . put ( :sync_state , sync_state ) )
541- |> Repo . update
542- end
543526end
0 commit comments