Skip to content

Commit 405f186

Browse files
committed
Fix #301: Update EventType enumeration
1 parent 8af3374 commit 405f186

File tree

1 file changed

+58
-38
lines changed

1 file changed

+58
-38
lines changed

src/GitHub/Data/Issues.hs

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,35 @@ data IssueComment = IssueComment
7979
instance NFData IssueComment where rnf = genericRnf
8080
instance Binary IssueComment
8181

82+
-- | See <https://developer.github.com/v3/issues/events/#events-1>
8283
data EventType
83-
= Mentioned -- ^ The actor was @mentioned in an issue body.
84-
| Subscribed -- ^ The actor subscribed to receive notifications for an issue.
85-
| Unsubscribed -- ^ The issue was unsubscribed from by the actor.
86-
| Referenced -- ^ The issue was referenced from a commit message. The commit_id attribute is the commit SHA1 of where that happened.
87-
| Merged -- ^ The issue was merged by the actor. The commit_id attribute is the SHA1 of the HEAD commit that was merged.
88-
| Assigned -- ^ The issue was assigned to the actor.
89-
| Closed -- ^ The issue was closed by the actor. When the commit_id is present, it identifies the commit that closed the issue using “closes / fixes #NN” syntax.
90-
| Reopened -- ^ The issue was reopened by the actor.
91-
| ActorUnassigned -- ^ The issue was unassigned to the actor
92-
| Labeled -- ^ A label was added to the issue.
93-
| Unlabeled -- ^ A label was removed from the issue.
94-
| Milestoned -- ^ The issue was added to a milestone.
95-
| Demilestoned -- ^ The issue was removed from a milestone.
96-
| Renamed -- ^ The issue title was changed.
97-
| Locked -- ^ The issue was locked by the actor.
98-
| Unlocked -- ^ The issue was unlocked by the actor.
99-
| HeadRefDeleted -- ^ The pull request’s branch was deleted.
100-
| HeadRefRestored -- ^ The pull request’s branch was restored.
84+
= Mentioned -- ^ The actor was @mentioned in an issue body.
85+
| Subscribed -- ^ The actor subscribed to receive notifications for an issue.
86+
| Unsubscribed -- ^ The issue was unsubscribed from by the actor.
87+
| Referenced -- ^ The issue was referenced from a commit message. The commit_id attribute is the commit SHA1 of where that happened.
88+
| Merged -- ^ The issue was merged by the actor. The commit_id attribute is the SHA1 of the HEAD commit that was merged.
89+
| Assigned -- ^ The issue was assigned to the actor.
90+
| Closed -- ^ The issue was closed by the actor. When the commit_id is present, it identifies the commit that closed the issue using “closes / fixes #NN” syntax.
91+
| Reopened -- ^ The issue was reopened by the actor.
92+
| ActorUnassigned -- ^ The issue was unassigned to the actor
93+
| Labeled -- ^ A label was added to the issue.
94+
| Unlabeled -- ^ A label was removed from the issue.
95+
| Milestoned -- ^ The issue was added to a milestone.
96+
| Demilestoned -- ^ The issue was removed from a milestone.
97+
| Renamed -- ^ The issue title was changed.
98+
| Locked -- ^ The issue was locked by the actor.
99+
| Unlocked -- ^ The issue was unlocked by the actor.
100+
| HeadRefDeleted -- ^ The pull request’s branch was deleted.
101+
| HeadRefRestored -- ^ The pull request’s branch was restored.
102+
| ReviewRequested -- ^ The actor requested review from the subject on this pull request.
103+
| ReviewDismissed -- ^ The actor dismissed a review from the pull request.
104+
| ReviewRequestRemoved -- ^ The actor removed the review request for the subject on this pull request.
105+
| MarkedAsDuplicate -- ^ A user with write permissions marked an issue as a duplicate of another issue or a pull request as a duplicate of another pull request.
106+
| UnmarkedAsDuplicate -- ^ An issue that a user had previously marked as a duplicate of another issue is no longer considered a duplicate, or a pull request that a user had previously marked as a duplicate of another pull request is no longer considered a duplicate.
107+
| AddedToProject -- ^ The issue was added to a project board.
108+
| MovedColumnsInProject -- ^ The issue was moved between columns in a project board.
109+
| RemovedFromProject -- ^ The issue was removed from a project board.
110+
| ConvertedNoteToIssue -- ^ The issue was created by converting a note in a project board to an issue.
101111
deriving (Show, Data, Enum, Bounded, Typeable, Eq, Ord, Generic)
102112

103113
instance NFData EventType where rnf = genericRnf
@@ -116,7 +126,7 @@ data IssueEvent = IssueEvent
116126
deriving (Show, Data, Typeable, Eq, Ord, Generic)
117127

118128
instance NFData IssueEvent where rnf = genericRnf
119-
instance Binary IssueEvent
129+
instance Binary IssueEvent
120130

121131
instance FromJSON IssueEvent where
122132
parseJSON = withObject "Event" $ \o -> IssueEvent
@@ -129,25 +139,35 @@ instance FromJSON IssueEvent where
129139
<*> o .:? "issue"
130140

131141
instance FromJSON EventType where
132-
parseJSON (String "closed") = pure Closed
133-
parseJSON (String "reopened") = pure Reopened
134-
parseJSON (String "subscribed") = pure Subscribed
135-
parseJSON (String "merged") = pure Merged
136-
parseJSON (String "referenced") = pure Referenced
137-
parseJSON (String "mentioned") = pure Mentioned
138-
parseJSON (String "assigned") = pure Assigned
139-
parseJSON (String "unsubscribed") = pure Unsubscribed
140-
parseJSON (String "unassigned") = pure ActorUnassigned
141-
parseJSON (String "labeled") = pure Labeled
142-
parseJSON (String "unlabeled") = pure Unlabeled
143-
parseJSON (String "milestoned") = pure Milestoned
144-
parseJSON (String "demilestoned") = pure Demilestoned
145-
parseJSON (String "renamed") = pure Renamed
146-
parseJSON (String "locked") = pure Locked
147-
parseJSON (String "unlocked") = pure Unlocked
148-
parseJSON (String "head_ref_deleted") = pure HeadRefDeleted
149-
parseJSON (String "head_ref_restored") = pure HeadRefRestored
150-
parseJSON _ = fail "Could not build an EventType"
142+
parseJSON = withText "EventType" $ \t -> case t of
143+
"closed" -> pure Closed
144+
"reopened" -> pure Reopened
145+
"subscribed" -> pure Subscribed
146+
"merged" -> pure Merged
147+
"referenced" -> pure Referenced
148+
"mentioned" -> pure Mentioned
149+
"assigned" -> pure Assigned
150+
"unassigned" -> pure ActorUnassigned
151+
"labeled" -> pure Labeled
152+
"unlabeled" -> pure Unlabeled
153+
"milestoned" -> pure Milestoned
154+
"demilestoned" -> pure Demilestoned
155+
"renamed" -> pure Renamed
156+
"locked" -> pure Locked
157+
"unlocked" -> pure Unlocked
158+
"head_ref_deleted" -> pure HeadRefDeleted
159+
"head_ref_restored" -> pure HeadRefRestored
160+
"review_requested" -> pure ReviewRequested
161+
"review_dismissed" -> pure ReviewDismissed
162+
"review_request_removed" -> pure ReviewRequestRemoved
163+
"marked_as_duplicate" -> pure MarkedAsDuplicate
164+
"unmarked_as_duplicate" -> pure UnmarkedAsDuplicate
165+
"added_to_project" -> pure AddedToProject
166+
"moved_columns_in_project" -> pure MovedColumnsInProject
167+
"removed_from_project" -> pure RemovedFromProject
168+
"converted_note_to_issue" -> pure ConvertedNoteToIssue
169+
"unsubscribed" -> pure Unsubscribed -- not in api docs list
170+
_ -> fail $ "Unknown EventType " ++ show t
151171

152172
instance FromJSON IssueComment where
153173
parseJSON = withObject "IssueComment" $ \o -> IssueComment

0 commit comments

Comments
 (0)