Skip to content

Commit 2b7fafb

Browse files
joshsmithbegedin
authored andcommitted
Clean up GitHub Sync with some minor documentation and spec changes
1 parent 68ac336 commit 2b7fafb

5 files changed

Lines changed: 28 additions & 44 deletions

File tree

lib/code_corps/github/sync/comment/comment/changeset.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ defmodule CodeCorps.GitHub.Sync.Comment.Comment.Changeset do
1616
alias Ecto.Changeset
1717

1818
@create_attrs ~w(created_at markdown modified_at)a
19-
@update_attrs ~w(markdown modified_at)a
2019

2120
@doc ~S"""
2221
Constructs a changeset for creating a `CodeCorps.Comment` when syncing from a
@@ -39,6 +38,8 @@ defmodule CodeCorps.GitHub.Sync.Comment.Comment.Changeset do
3938
|> Changeset.validate_required([:markdown, :body])
4039
end
4140

41+
@update_attrs ~w(markdown modified_at)a
42+
4243
@doc ~S"""
4344
Constructs a changeset for updating a `CodeCorps.Comment` when syncing from a
4445
GitHub API Comment payload.

lib/code_corps/github/sync/comment/comment/comment.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ defmodule CodeCorps.GitHub.Sync.Comment.Comment do
6767
`CodeCorps.GithubRepo`.
6868
6969
For each `CodeCorps.GithubComment` record that relates to the
70-
`CodeCorps.GithubRepo` for a given`CodeCorps.GithubRepo`:
70+
`CodeCorps.GithubRepo` for a given `CodeCorps.GithubRepo`:
7171
7272
- Find the related `CodeCorps.Task` record
7373
- Create or update the related `CodeCorps.Comment` record
@@ -91,7 +91,7 @@ defmodule CodeCorps.GitHub.Sync.Comment.Comment do
9191
|> ResultAggregator.aggregate()
9292
end
9393

94-
# can this return a nil?
94+
# TODO: can this return a nil?
9595
@spec find_task(GithubComment.t(), GithubRepo.t()) :: Task.t()
9696
defp find_task(
9797
%GithubComment{github_issue: %GithubIssue{id: github_issue_id}},

lib/code_corps/github/sync/issue/github_issue/github_issue.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ defmodule CodeCorps.GitHub.Sync.Issue.GithubIssue do
2121
@type result :: {:ok, GithubIssue.t} | {:error, Changeset.t}
2222

2323
@doc ~S"""
24-
Creates or updates a `CodeCorps.GithubIssue` from a github issue API payload.
24+
Creates or updates a `CodeCorps.GithubIssue` from a GitHub issue API payload.
2525
26-
The created record is associated to the provided `CodeCorps.GithubRepo` and, optionaly,
27-
to a provided `CodeCorps.GithubPullRequest`.
26+
The created record is associated to the provided `CodeCorps.GithubRepo` and,
27+
optionally, to a provided `CodeCorps.GithubPullRequest`.
2828
29-
The created record is also associated with a matched `CodeCorps.GithubUser`, which is
30-
created if necessary.
29+
The created record is also associated with a matched `CodeCorps.GithubUser`,
30+
which is created if necessary.
3131
"""
3232
@spec create_or_update_issue(map, GithubRepo.t, GithubPullRequest.t | nil) :: result
3333
def create_or_update_issue(%{} = payload, %GithubRepo{} = github_repo, github_pull_request \\ nil) do

lib/code_corps/github/sync/issue/issue.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule CodeCorps.GitHub.Sync.Issue do
77
alias Ecto.Multi
88

99
@doc ~S"""
10-
Performs sync of a github issue payload related to a repo and a pull request.
10+
Performs sync of a GitHub issue payload related to a repo and a pull request.
1111
1212
Performs work identical to `sync/2`, with the adition of associating the
1313
resulting `CodeCorps.GithubIssue` with the specified `CodeCorps.GithubPullRequest`.

lib/code_corps/github/sync/sync.ex

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
defmodule 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
543526
end

0 commit comments

Comments
 (0)