Skip to content

Commit bf84d4e

Browse files
authored
Merge pull request #1087 from code-corps/code-and-comment-cleanups-for-issue
Code and comment cleanups for Issues
2 parents 162e2bd + 2ce80e6 commit bf84d4e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

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

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
defmodule CodeCorps.GitHub.Event.Issues.IssueLinker do
22
@moduledoc ~S"""
3-
In charge of finding a issue to link with a Task when processing an Issues
4-
webhook.
3+
In charge of finding a `CodeCorps.GithubIssue` to link with a
4+
`CodeCorps.Issue` when processing an Issues webhook, or handling a
5+
`CodeCorpsWeb.TaskController` request.
56
67
The only entry point is `create_or_update_issue/1`.
78
"""
89

910
alias CodeCorps.{
11+
GitHub.Adapters,
1012
GithubIssue,
1113
GithubRepo,
1214
Repo
1315
}
1416

15-
alias CodeCorps.GitHub.Adapters.Issue, as: IssueAdapter
16-
17-
@typep linking_result :: {:ok, GithubIssue.t} |
18-
{:error, Ecto.Changeset.t}
17+
@typep linking_result :: {:ok, GithubIssue.t} | {:error, Ecto.Changeset.t}
1918

2019
@doc ~S"""
21-
Finds or creates a `GithubIssue` using the data in a GitHub Issue payload.
20+
Finds or creates a `CodeCorps.GithubIssue` using the data in a GitHub Issue
21+
payload.
2222
2323
The process is as follows:
24-
2524
- Search for the issue in our database with the payload data.
26-
- If we return a single `GithubIssue`, then the `GithubIssue` should be
27-
updated.
28-
- If there are no matching `GithubIssue` records, then a `GithubIssue`
29-
should be created.
25+
- If found, update it with payload data
26+
- If not found, create it from payload data
27+
28+
`CodeCorps.GitHub.AdaptersIssue.to_issue/1` is used to adapt the payload data.
3029
"""
3130
@spec create_or_update_issue(GithubRepo.t, map) :: linking_result
3231
def create_or_update_issue(%GithubRepo{} = github_repo, %{"id" => github_issue_id} = attrs) do
33-
params = IssueAdapter.to_issue(attrs)
32+
params = Adapters.Issue.to_issue(attrs)
3433

3534
case Repo.get_by(GithubIssue, github_id: github_issue_id) do
3635
nil -> create_issue(github_repo, params)
3736
%GithubIssue{} = issue -> update_issue(issue, params)
3837
end
3938
end
4039

40+
@spec create_issue(GithubRepo.t, map) :: linking_result
4141
defp create_issue(%GithubRepo{id: github_repo_id}, params) do
4242
params = Map.put(params, :github_repo_id, github_repo_id)
4343

@@ -46,6 +46,7 @@ defmodule CodeCorps.GitHub.Event.Issues.IssueLinker do
4646
|> Repo.insert
4747
end
4848

49+
@spec update_issue(GithubIssue.t, map) :: linking_result
4950
defp update_issue(%GithubIssue{} = github_issue, params) do
5051
github_issue
5152
|> GithubIssue.update_changeset(params)

0 commit comments

Comments
 (0)