@@ -6,10 +6,12 @@ defmodule CodeCorps.GitHub.Adapters.Issue do
6
6
7
7
alias CodeCorps . {
8
8
Adapter.MapTransformer ,
9
- GithubIssue
9
+ GitHub.Adapters.Utils.BodyDecorator ,
10
+ GithubIssue ,
11
+ Task
10
12
}
11
13
12
- @ mapping [
14
+ @ issue_mapping [
13
15
{ :body , [ "body" ] } ,
14
16
{ :closed_at , [ "closed_at" ] } ,
15
17
{ :comments_url , [ "comments_url" ] } ,
@@ -27,25 +29,50 @@ defmodule CodeCorps.GitHub.Adapters.Issue do
27
29
]
28
30
29
31
@ doc ~S"""
30
- Converts a GitHub Issue payload into a set of attributes used to update or
31
- create a `GithubIssue` record.
32
+ Converts a GitHub Issue payload into a set of attributes used to create or
33
+ update a `GithubIssue` record.
32
34
"""
33
- @ spec from_api ( map ) :: map
34
- def from_api ( % { } = payload ) do
35
- payload |> MapTransformer . transform ( @ mapping )
35
+ @ spec to_issue ( map ) :: map
36
+ def to_issue ( % { } = payload ) do
37
+ payload |> MapTransformer . transform ( @ issue_mapping )
38
+ end
39
+
40
+ @ task_mapping [
41
+ { :created_at , [ "created_at" ] } ,
42
+ { :markdown , [ "body" ] } ,
43
+ { :modified_at , [ "updated_at" ] } ,
44
+ { :status , [ "state" ] } ,
45
+ { :title , [ "title" ] }
46
+ ]
47
+
48
+ @ doc ~S"""
49
+ Converts a GitHub Issue payload into a set of attributes used to create or
50
+ update a `Task` record.
51
+ """
52
+ @ spec to_task ( map ) :: map
53
+ def to_task ( % { } = payload ) do
54
+ payload |> MapTransformer . transform ( @ task_mapping )
36
55
end
37
56
38
57
@ autogenerated_github_keys ~w( closed_at comments_url created_at events_url html_url id labels_url number updated_at url)
39
58
40
59
@ doc ~S"""
41
- Converts a `GithubIssue` into a set of attributes used to update or create an
42
- associated GitHub Issue.
60
+ Converts a `GithubIssue` or `Task` into a set of attributes used to create or
61
+ update an associated GitHub Issue on the GitHub API .
43
62
"""
44
- @ spec to_api ( GithubIssue . t ) :: map
63
+ @ spec to_api ( GithubIssue . t | Task . t ) :: map
45
64
def to_api ( % GithubIssue { } = github_issue ) do
46
65
github_issue
47
66
|> Map . from_struct
48
- |> MapTransformer . transform_inverse ( @ mapping )
67
+ |> MapTransformer . transform_inverse ( @ issue_mapping )
68
+ |> Map . drop ( @ autogenerated_github_keys )
69
+ |> BodyDecorator . add_code_corps_header ( github_issue )
70
+ end
71
+ def to_api ( % Task { } = task ) do
72
+ task
73
+ |> Map . from_struct
74
+ |> MapTransformer . transform_inverse ( @ task_mapping )
49
75
|> Map . drop ( @ autogenerated_github_keys )
76
+ |> BodyDecorator . add_code_corps_header ( task )
50
77
end
51
78
end
0 commit comments