Skip to content

Commit c3e8a70

Browse files
committed
Cleanup responses across sync modules
1 parent 0b843b0 commit c3e8a70

File tree

10 files changed

+55
-54
lines changed

10 files changed

+55
-54
lines changed

lib/code_corps/github/event/installation/installation.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ defmodule CodeCorps.GitHub.Event.Installation do
66

77
@behaviour CodeCorps.GitHub.Event.Handler
88

9-
alias CodeCorps.{GitHub.Sync, GitHub.Event.Installation}
9+
alias CodeCorps.{
10+
GitHub.Sync,
11+
GitHub.Event.Installation
12+
}
1013

1114

1215
@doc """
@@ -17,6 +20,7 @@ defmodule CodeCorps.GitHub.Event.Installation do
1720
1821
`CodeCorps.GitHub.Sync.installation_event/1`
1922
"""
23+
@impl CodeCorps.GitHub.Event.Handler
2024
@spec handle(map) ::
2125
Sync.installation_event_outcome() | {:error, :unexpected_payload}
2226
def handle(payload) do

lib/code_corps/github/event/installation_repositories/installation_repositories.ex

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@ defmodule CodeCorps.GitHub.Event.InstallationRepositories do
1010

1111
alias CodeCorps.{
1212
GitHub.Sync,
13-
GithubRepo,
1413
GitHub.Event.InstallationRepositories
1514
}
1615

17-
@type outcome :: {:ok, list(GithubRepo.t())} |
18-
{:error, :unmatched_installation} |
19-
{:error, :unexpected_payload} |
20-
{:error, :validation_error_on_syncing_repos} |
21-
{:error, :unexpected_transaction_outcome}
22-
2316
@doc """
2417
Handles an "InstallationRepositories" GitHub Webhook event. The event could be
2518
of subtype "added" or "removed" and is handled differently based on that.
@@ -34,7 +27,10 @@ defmodule CodeCorps.GitHub.Event.InstallationRepositories do
3427
- if the GitHub payload for a repo is not matched with a record in our
3528
database, just skip deleting it
3629
"""
37-
@spec handle(map) :: outcome
30+
@impl CodeCorps.GitHub.Event.Handler
31+
@spec handle(map) ::
32+
Sync.installation_repositories_event_outcome() |
33+
{:error, :unexpected_payload}
3834
def handle(payload) do
3935
with {:ok, :valid} <- payload |> validate_payload() do
4036
Sync.installation_repositories_event(payload)

lib/code_corps/github/event/issue_comment/issue_comment.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ defmodule CodeCorps.GitHub.Event.IssueComment do
88
@behaviour CodeCorps.GitHub.Event.Handler
99

1010
alias CodeCorps.{
11-
GitHub,
11+
GitHub.Sync,
1212
GitHub.Event.IssueComment.Validator
1313
}
14-
alias GitHub.Sync
1514

1615
@doc ~S"""
1716
Handles the "IssueComment" GitHub webhook
@@ -23,7 +22,8 @@ defmodule CodeCorps.GitHub.Event.IssueComment do
2322
- sync the comment using `CodeCorps.GitHub.Sync.Comment`
2423
"""
2524
@impl CodeCorps.GitHub.Event.Handler
26-
@spec handle(map) :: {:ok, any} | {:error, atom}
25+
@spec handle(map) ::
26+
Sync.issue_comment_event_outcome() | {:error, :unexpected_payload}
2727
def handle(payload) do
2828
with {:ok, :valid} <- validate_payload(payload) do
2929
Sync.issue_comment_event(payload)

lib/code_corps/github/event/issues/issues.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ defmodule CodeCorps.GitHub.Event.Issues do
88
@behaviour CodeCorps.GitHub.Event.Handler
99

1010
alias CodeCorps.{
11-
GitHub,
11+
GitHub.Sync,
1212
GitHub.Event.Issues.Validator
1313
}
14-
alias GitHub.Sync
1514

1615
@doc ~S"""
1716
Handles the "Issues" GitHub webhook
@@ -23,7 +22,8 @@ defmodule CodeCorps.GitHub.Event.Issues do
2322
- sync the issue using `CodeCorps.GitHub.Sync.Issue`
2423
"""
2524
@impl CodeCorps.GitHub.Event.Handler
26-
@spec handle(map) :: {:ok, any} | {:error, atom}
25+
@spec handle(map) ::
26+
Sync.issue_event_outcome() | {:error, :unexpected_payload}
2727
def handle(payload) do
2828
with {:ok, :valid} <- validate_payload(payload) do
2929
Sync.issue_event(payload)

lib/code_corps/github/event/pull_request/pull_request.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ defmodule CodeCorps.GitHub.Event.PullRequest do
88
@behaviour CodeCorps.GitHub.Event.Handler
99

1010
alias CodeCorps.{
11-
GitHub,
11+
GitHub.Sync,
1212
GitHub.Event.PullRequest.Validator
1313
}
14-
alias GitHub.Sync
1514

1615
@doc ~S"""
1716
Handles the "PullRequest" GitHub webhook
@@ -23,7 +22,8 @@ defmodule CodeCorps.GitHub.Event.PullRequest do
2322
- sync the pull request using `CodeCorps.GitHub.Sync.PullRequest`
2423
"""
2524
@impl CodeCorps.GitHub.Event.Handler
26-
@spec handle(map) :: {:ok, any} | {:error, atom}
25+
@spec handle(map) ::
26+
Sync.pull_request_event_outcome() | {:error, :unexpected_payload}
2727
def handle(payload) do
2828
with {:ok, :valid} <- validate_payload(payload) do
2929
Sync.pull_request_event(payload)

lib/code_corps/github/sync/sync.ex

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ defmodule CodeCorps.GitHub.Sync do
2121

2222
@type issue_event_outcome ::
2323
{:ok, Task.t()} |
24-
{:error, :repo_not_found, map} |
24+
{:error, :repo_not_found} |
2525
{:error, :validating_github_issue, Changeset.t()} |
2626
{:error, :validating_user, Changeset.t()} |
27-
{:error, :multiple_issue_users_match, map} |
27+
{:error, :multiple_issue_users_match} |
2828
{:error, :validating_task, Changeset.t()} |
2929
{:error, :unexpected_transaction_outcome, any}
3030

@@ -56,7 +56,7 @@ defmodule CodeCorps.GitHub.Sync do
5656
{:ok, %{task: task}} -> {:ok, task}
5757

5858
{:error, :repo, :unmatched_repository, _steps} ->
59-
{:error, :repo_not_found, %{}}
59+
{:error, :repo_not_found}
6060

6161
{:error, :github_issue, %Changeset{} = changeset, _steps} ->
6262
{:error, :validating_github_issue, changeset}
@@ -65,7 +65,7 @@ defmodule CodeCorps.GitHub.Sync do
6565
{:error, :validating_user, changeset}
6666

6767
{:error, :issue_user, :multiple_users, _steps} ->
68-
{:error, :multiple_issue_users_match, %{}}
68+
{:error, :multiple_issue_users_match}
6969

7070
{:error, :task, %Changeset{} = changeset, _steps} ->
7171
{:error, :validating_task, changeset}
@@ -79,14 +79,14 @@ defmodule CodeCorps.GitHub.Sync do
7979

8080
@type issue_comment_outcome ::
8181
{:ok, Comment.t()} |
82-
{:error, :repo_not_found, map} |
82+
{:error, :repo_not_found} |
8383
{:error, :validating_github_issue, Changeset.t()} |
8484
{:error, :validating_user, Changeset.t()} |
85-
{:error, :multiple_issue_users_match, map} |
85+
{:error, :multiple_issue_users_match} |
8686
{:error, :validating_task, Changeset.t()} |
8787
{:error, :validating_github_comment, Changeset.t()} |
8888
{:error, :validating_user, Changeset.t()} |
89-
{:error, :multiple_comment_users_match, map} |
89+
{:error, :multiple_comment_users_match} |
9090
{:error, :validating_comment, Changeset.t()} |
9191
{:error, :unexpected_transaction_outcome, any}
9292

@@ -95,6 +95,11 @@ defmodule CodeCorps.GitHub.Sync do
9595
{:error, :fetching_pull_request, struct} |
9696
{:error, :validating_github_pull_request, Changeset.t()}
9797

98+
@type issue_comment_event_outcome ::
99+
comment_deleted_outcome() |
100+
pull_request_comment_outcome() |
101+
issue_comment_outcome()
102+
98103
@doc ~S"""
99104
Syncs a GitHub IssueComment event.
100105
@@ -109,11 +114,7 @@ defmodule CodeCorps.GitHub.Sync do
109114
110115
[https://developer.github.com/v3/activity/events/types/#issuecommentevent](https://developer.github.com/v3/activity/events/types/#issuecommentevent)
111116
"""
112-
@spec issue_comment_event(map) ::
113-
comment_deleted_outcome() |
114-
pull_request_comment_outcome() |
115-
issue_comment_outcome()
116-
117+
@spec issue_comment_event(map) :: issue_comment_event_outcome()
117118
def issue_comment_event(
118119
%{"action" => "deleted", "comment" => %{"id" => github_id}}) do
119120

@@ -166,7 +167,7 @@ defmodule CodeCorps.GitHub.Sync do
166167
{:ok, %{comment: %Comment{} = comment}} -> {:ok, comment}
167168

168169
{:error, :repo, :unmatched_repository, _steps} ->
169-
{:error, :repo_not_found, %{}}
170+
{:error, :repo_not_found}
170171

171172
{:error, :fetch_pull_request, error, _steps} ->
172173
{:error, :fetching_pull_request, error}
@@ -181,7 +182,7 @@ defmodule CodeCorps.GitHub.Sync do
181182
{:error, :validating_user, changeset}
182183

183184
{:error, :issue_user, :multiple_users, _steps} ->
184-
{:error, :multiple_issue_users_match, %{}}
185+
{:error, :multiple_issue_users_match}
185186

186187
{:error, :task, %Changeset{} = changeset, _steps} ->
187188
{:error, :validating_task, changeset}
@@ -193,7 +194,7 @@ defmodule CodeCorps.GitHub.Sync do
193194
{:error, :validating_user, changeset}
194195

195196
{:error, :comment_user, :multiple_users, _steps} ->
196-
{:error, :multiple_comment_users_match, %{}}
197+
{:error, :multiple_comment_users_match}
197198

198199
{:error, :comment, %Changeset{} = changeset, _steps} ->
199200
{:error, :validating_comment, changeset}
@@ -230,7 +231,7 @@ defmodule CodeCorps.GitHub.Sync do
230231
{:ok, %{comment: %Comment{} = comment}} -> {:ok, comment}
231232

232233
{:error, :repo, :unmatched_repository, _steps} ->
233-
{:error, :repo_not_found, %{}}
234+
{:error, :repo_not_found}
234235

235236
{:error, :github_issue, %Changeset{} = changeset, _steps} ->
236237
{:error, :validating_github_issue, changeset}
@@ -239,7 +240,7 @@ defmodule CodeCorps.GitHub.Sync do
239240
{:error, :validating_user, changeset}
240241

241242
{:error, :issue_user, :multiple_users, _steps} ->
242-
{:error, :multiple_issue_users_match, %{}}
243+
{:error, :multiple_issue_users_match}
243244

244245
{:error, :task, %Changeset{} = changeset, _steps} ->
245246
{:error, :validating_task, changeset}
@@ -251,7 +252,7 @@ defmodule CodeCorps.GitHub.Sync do
251252
{:error, :validating_user, changeset}
252253

253254
{:error, :comment_user, :multiple_users, _steps} ->
254-
{:error, :multiple_comment_users_match, %{}}
255+
{:error, :multiple_comment_users_match}
255256

256257
{:error, :comment, %Changeset{} = changeset, _steps} ->
257258
{:error, :validating_comment, changeset}
@@ -264,12 +265,12 @@ defmodule CodeCorps.GitHub.Sync do
264265
@type installation_event_outcome() ::
265266
{:ok, GithubAppInstallation.t()} |
266267
{:error, :validation_error_on_syncing_installation, Changeset.t()} |
267-
{:error, :multiple_unprocessed_installations_found, map} |
268+
{:error, :multiple_unprocessed_installations_found} |
268269
{:error, :github_api_error_on_syncing_repos, struct} |
269270
{:error, :validation_error_on_deleting_removed_repos, {list, list}} |
270271
{:error, :validation_error_on_syncing_existing_repos, {list, list}} |
271272
{:error, :validation_error_on_marking_installation_processed, Changeset.t()} |
272-
{:error, :unexpected_transaction_outcome, map}
273+
{:error, :unexpected_transaction_outcome, any}
273274

274275
@doc ~S"""
275276
Handles a GitHub installation event.
@@ -299,7 +300,7 @@ defmodule CodeCorps.GitHub.Sync do
299300
{:error, :validation_error_on_syncing_installation, changeset}
300301

301302
{:error, :installation, :multiple_unprocessed_installations_found, _steps} ->
302-
{:error, :multiple_unprocessed_installations_found, %{}}
303+
{:error, :multiple_unprocessed_installations_found}
303304

304305
{:error, :repos, {:api_error, error}, _steps} ->
305306
{:error, :github_api_error_on_syncing_repos, error}
@@ -313,16 +314,16 @@ defmodule CodeCorps.GitHub.Sync do
313314
{:error, :repos, {:mark_processed, %Changeset{} = changeset}, _steps} ->
314315
{:error, :validation_error_on_marking_installation_processed, changeset}
315316

316-
{:error, _errored_step, _error_response, _steps} ->
317-
{:error, :unexpected_transaction_outcome, %{}}
317+
{:error, _errored_step, error_response, _steps} ->
318+
{:error, :unexpected_transaction_outcome, error_response}
318319
end
319320
end
320321

321322
@type installation_repositories_event_outcome ::
322323
{:ok, list(GithubRepo.t())} |
323-
{:error, :unmatched_installation, map} |
324+
{:error, :unmatched_installation} |
324325
{:error, :validation_error_on_syncing_repos, Changeset.t()} |
325-
{:error, :unexpected_transaction_outcome, map}
326+
{:error, :unexpected_transaction_outcome, any}
326327

327328
@doc ~S"""
328329
Syncs a GitHub InstallationRepositories event.
@@ -350,7 +351,7 @@ defmodule CodeCorps.GitHub.Sync do
350351
{:ok, %{repos: repos}} -> {:ok, repos}
351352

352353
{:error, :installation, :unmatched_installation, _steps} ->
353-
{:error, :unmatched_installation, %{}}
354+
{:error, :unmatched_installation}
354355

355356
{:error, :repos, {_repos, _changesets}, _steps} ->
356357
{:error, :validation_error_on_syncing_repos, %{}}
@@ -362,14 +363,14 @@ defmodule CodeCorps.GitHub.Sync do
362363

363364
@type pull_request_event_outcome ::
364365
{:ok, map} |
365-
{:error, :repo_not_found, map} |
366+
{:error, :repo_not_found} |
366367
{:error, :fetching_issue, struct} |
367368
{:error, :validating_github_pull_request, Changeset.t()} |
368369
{:error, :validating_github_issue, Changeset.t()} |
369370
{:error, :validating_user, Changeset.t()} |
370-
{:error, :multiple_issue_users_match, %{}} |
371+
{:error, :multiple_issue_users_match} |
371372
{:error, :validating_task, Changeset.t()} |
372-
{:error, :unexpected_transaction_outcome, map}
373+
{:error, :unexpected_transaction_outcome, any}
373374

374375
@doc ~S"""
375376
Syncs a GitHub PullRequest event.
@@ -411,7 +412,7 @@ defmodule CodeCorps.GitHub.Sync do
411412
{:ok, %{github_pull_request: _, github_issue: _} = result} -> {:ok, result}
412413

413414
{:error, :repo, :unmatched_repository, _steps} ->
414-
{:error, :repo_not_found, %{}}
415+
{:error, :repo_not_found}
415416

416417
{:error, :fetch_issue, error, _steps} ->
417418
{:error, :fetching_issue, error}
@@ -426,7 +427,7 @@ defmodule CodeCorps.GitHub.Sync do
426427
{:error, :validating_user, changeset}
427428

428429
{:error, :issue_user, :multiple_users, _steps} ->
429-
{:error, :multiple_issue_users_match, %{}}
430+
{:error, :multiple_issue_users_match}
430431

431432
{:error, :task, %Changeset{} = changeset, _steps} ->
432433
{:error, :validating_task, changeset}

test/lib/code_corps/github/event/installation_repositories/installation_repositories_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ defmodule CodeCorps.GitHub.Event.InstallationRepositoriesTest do
112112
end
113113

114114
test "marks event as errored if no installation" do
115-
assert {:error, :unmatched_installation, %{}} == InstallationRepositories.handle(@payload)
115+
assert {:error, :unmatched_installation} == InstallationRepositories.handle(@payload)
116116
end
117117
end
118118

@@ -168,7 +168,7 @@ defmodule CodeCorps.GitHub.Event.InstallationRepositoriesTest do
168168
end
169169

170170
test "marks event as errored if no installation" do
171-
assert {:error, :unmatched_installation, %{}} == InstallationRepositories.handle(@payload)
171+
assert {:error, :unmatched_installation} == InstallationRepositories.handle(@payload)
172172
end
173173
end
174174
end

test/lib/code_corps/github/event/issue_comment/issue_comment_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule CodeCorps.GitHub.Event.IssueCommentTest do
3535
end
3636

3737
test "returns error if unmatched repository" do
38-
assert IssueComment.handle(@payload) == {:error, :repo_not_found, %{}}
38+
assert IssueComment.handle(@payload) == {:error, :repo_not_found}
3939
refute Repo.one(User)
4040
end
4141

test/lib/code_corps/github/event/issues/issues_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule CodeCorps.GitHub.Event.IssuesTest do
3535
end
3636

3737
test "returns error if unmatched repository" do
38-
assert Issues.handle(@payload) == {:error, :repo_not_found, %{}}
38+
assert Issues.handle(@payload) == {:error, :repo_not_found}
3939
refute Repo.one(User)
4040
end
4141

test/lib/code_corps/github/event/pull_request/pull_request_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ defmodule CodeCorps.GitHub.Event.PullRequestTest do
3636
end
3737

3838
test "returns error if unmatched repository" do
39-
assert PullRequest.handle(@payload) == {:error, :repo_not_found, %{}}
39+
assert PullRequest.handle(@payload) == {:error, :repo_not_found}
4040
refute Repo.one(User)
4141
end
4242

0 commit comments

Comments
 (0)