Skip to content

Commit 3255b64

Browse files
authored
Merge pull request #1245 from code-corps/fix-sync-dialyzer-errors
Fix GitHub sync dialyzer errors and add some specs to pagination errors
2 parents f895eb9 + 052f514 commit 3255b64

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
defmodule CodeCorps.GitHub.API.Errors.PaginationError do
2-
alias CodeCorps.GitHub.{HTTPClientError, APIError}
2+
alias CodeCorps.GitHub.{APIError, HTTPClientError}
33

44
@type t :: %__MODULE__{
5-
message: String.t,
65
api_errors: list,
76
client_errors: list,
7+
message: String.t,
88
retrieved_pages: list
99
}
1010

1111
defstruct [
12-
message: "One or more pages failed to retrieve during a GitHub API Pagination Request",
13-
retrieved_pages: [],
12+
api_errors: [],
1413
client_errors: [],
15-
api_errors: []
14+
message: "One or more pages failed to retrieve when paginating GitHub API resources",
15+
retrieved_pages: []
1616
]
1717

18+
@spec new({list, list}) :: t
1819
def new({pages, errors}) do
1920
%__MODULE__{
20-
retrieved_pages: pages,
21+
api_errors: errors |> Enum.filter(&api_error?/1),
2122
client_errors: errors |> Enum.filter(&client_error?/1),
22-
api_errors: errors |> Enum.filter(&api_error?/1)
23+
retrieved_pages: pages
2324
}
2425
end
2526

26-
defp client_error?(%HTTPClientError{}), do: true
27-
defp client_error?(_), do: false
27+
@spec api_error?(APIError.t | any) :: boolean
2828
defp api_error?(%APIError{}), do: true
2929
defp api_error?(_), do: false
30+
31+
@spec client_error?(HTTPClientError.t | any) :: boolean
32+
defp client_error?(%HTTPClientError{}), do: true
33+
defp client_error?(_), do: false
3034
end

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ defmodule CodeCorps.GitHub.Sync.Issue.Task do
1111
}
1212
alias Ecto.Changeset
1313

14-
@type outcome :: {:ok, list(Task.t)} |
15-
{:error, {list(Task.t), list(Changeset.t)}}
14+
@type outcome :: {:ok, list(Task.t)}
15+
| {:error, {list(Task.t), list(Changeset.t)}}
1616

1717
@doc """
1818
When provided a `CodeCorps.GithubIssue` and a `CodeCorps.User`, for the
1919
`CodeCorps.Project` associated to that `CodeCorps.GithubRepo`, it creates or
2020
updates a `CodeCorps.Task`.
2121
"""
22-
@spec sync_github_issue(GithubIssue.t, User.t) :: {:ok, Task.t}
22+
@spec sync_github_issue(GithubIssue.t, User.t) :: {:ok, Task.t} | {:error, Changeset.t}
2323
def sync_github_issue(%GithubIssue{} = github_issue, %User{} = user) do
2424
%GithubIssue{
2525
github_repo: %GithubRepo{} = github_repo

lib/code_corps/github/sync/sync.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ defmodule CodeCorps.GitHub.Sync do
127127

128128
@spec sync_step(tuple, atom) :: tuple
129129
defp sync_step({:ok, _} = result, _step), do: result
130-
defp sync_step({:error, _ = error}, _step), do: {:error, error}
130+
defp sync_step({:error, _}, step), do: {:error, step}
131131

132132
@spec mark_repo(GithubRepo.t, String.t, map) :: {:ok, GithubRepo.t} | {:error, Changeset.t}
133133
defp mark_repo(%GithubRepo{} = repo, sync_state, params \\ %{}) do
@@ -158,7 +158,7 @@ defmodule CodeCorps.GitHub.Sync do
158158
- Creates or updates `Comment` records, and relates them to any related
159159
`GithubComment` and `User` records created previously
160160
"""
161-
@spec sync_repo(GithubRepo.t) :: {:ok, GithubRepo.t}
161+
@spec sync_repo(GithubRepo.t) :: {:ok, GithubRepo.t} | {:error, Changeset.t}
162162
def sync_repo(%GithubRepo{} = repo) do
163163
repo = preload_github_repo(repo)
164164
with {:ok, repo} <- repo |> mark_repo("fetching_pull_requests"),
@@ -185,6 +185,7 @@ defmodule CodeCorps.GitHub.Sync do
185185
do
186186
{:ok, repo}
187187
else
188+
{:error, %Changeset{} = changeset} -> {:error, changeset}
188189
{:error, :fetch_pull_requests} -> repo |> mark_repo("errored_fetching_pull_requests")
189190
{:error, :sync_pull_requests} -> repo |> mark_repo("errored_syncing_pull_requests")
190191
{:error, :fetch_issues} -> repo |> mark_repo("errored_fetching_issues")

0 commit comments

Comments
 (0)