Skip to content

Commit 0bbfa92

Browse files
committed
case-insensitive parsing of NotificationReason
1 parent 3b7048a commit 0bbfa92

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
## Changes for 0.22
44

5-
[#370](https://github.com/phadej/github/pull/370)
65
- Type-class for various auth methods
76
[#365](https://github.com/phadej/github/pull/365)
87
- Throw on non-200 responses
98
[#350](https://github.com/phadej/github/pull/350)
109
- Add extension point for (preview) media types
10+
[#370](https://github.com/phadej/github/pull/370)
1111
- Add missing webhook event types
1212
[#359](https://github.com/phadej/github/pull/359)
13+
- Add invitation endpoint
14+
[#360](https://github.com/phadej/github/pull/360)
1315
- Add notifications endpoints
1416
[#324](https://github.com/phadej/github/pull/324)
17+
- Case insensitive enum parsing
18+
[#373](https://github.com/phadej/github/pull/373)
1519
- Update dependencies
1620
[#364](https://github.com/phadej/github/pull/364)
1721
[#368](https://github.com/phadej/github/pull/368)

src/GitHub/Data/Activities.hs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import GitHub.Internal.Prelude
1212

1313
import Prelude ()
1414

15+
import qualified Data.Text as T
16+
1517
data RepoStarred = RepoStarred
1618
{ repoStarredStarredAt :: !UTCTime
1719
, repoStarredRepo :: !Repo
@@ -65,18 +67,18 @@ instance NFData NotificationReason where rnf = genericRnf
6567
instance Binary NotificationReason
6668

6769
instance FromJSON NotificationReason where
68-
parseJSON = withText "NotificationReason" $ \t -> case t of
69-
"assign" -> pure AssignReason
70-
"author" -> pure AuthorReason
71-
"comment" -> pure CommentReason
72-
"invitation" -> pure InvitationReason
73-
"manual" -> pure ManualReason
74-
"mention" -> pure MentionReason
70+
parseJSON = withText "NotificationReason" $ \t -> case T.toLower t of
71+
"assign" -> pure AssignReason
72+
"author" -> pure AuthorReason
73+
"comment" -> pure CommentReason
74+
"invitation" -> pure InvitationReason
75+
"manual" -> pure ManualReason
76+
"mention" -> pure MentionReason
7577
"review_requested" -> pure ReviewRequestedReason
76-
"state_change" -> pure StateChangeReason
77-
"subscribed" -> pure SubscribedReason
78-
"team_mention" -> pure TeamMentionReason
79-
_ -> fail $ "Unknown NotificationReason " ++ show t
78+
"state_change" -> pure StateChangeReason
79+
"subscribed" -> pure SubscribedReason
80+
"team_mention" -> pure TeamMentionReason
81+
_ -> fail $ "Unknown NotificationReason " ++ show t
8082

8183
data Notification = Notification
8284
-- XXX: The notification id field type IS in fact string. Not sure why gh

0 commit comments

Comments
 (0)