Skip to content

Commit 51a51d1

Browse files
committed
Parse state_reason (values: completed, not_planned, reopened)
Added `issueStateReason` to `Issue`.
1 parent 445c8de commit 51a51d1

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## Changes for 0.29
2+
3+
_2022-06-24, Andreas Abel, Midsommar edition_
4+
5+
- Add field `issueStateReason` of type `Maybe IssueStateReason` to `Issue`
6+
with possible values `completed`, `not_planned` and `reopened`.
7+
(PR [...]).
8+
9+
Tested with GHC 7.8 - 9.6.2
10+
111
## Changes for 0.28.0.1
212

313
_2022-07-23, Andreas Abel_

github.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
cabal-version: >=1.10
22
name: github
3-
version: 0.28.0.1
4-
x-revision: 2
3+
version: 0.29
54
synopsis: Access to the GitHub API, v3.
65
category: Network
76
description:
@@ -72,6 +71,7 @@ library
7271
DataKinds
7372
DeriveDataTypeable
7473
DeriveGeneric
74+
LambdaCase
7575
OverloadedStrings
7676
ScopedTypeVariables
7777
TypeOperators

samples/Issues/ShowRepoIssues.hs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1+
{-# LANGUAGE LambdaCase #-}
12
{-# LANGUAGE OverloadedStrings #-}
23

3-
import qualified GitHub as Github
4-
import Data.List (intercalate)
54
import Data.Foldable (toList)
5+
import Data.List (intercalate)
6+
import Data.Vector (Vector)
7+
8+
import qualified GitHub as Github
69

710
main :: IO ()
811
main = do
912
let filt = Github.stateClosed <> Github.optionsMentioned "mike-burns" <> Github.optionsAssignee "jyurek"
10-
possibleIssues <- Github.github' $ Github.issuesForRepoR "thoughtbot" "paperclip" filt Github.FetchAll
11-
case possibleIssues of
12-
Left err -> putStrLn $ "Error: " ++ show err
13-
Right issues ->
14-
putStrLn $ intercalate "\n\n" $ map formatIssue $ toList issues
13+
printIssues =<< do
14+
Github.github' $ Github.issuesForRepoR "thoughtbot" "paperclip" filt Github.FetchAll
15+
16+
printIssues =<< do
17+
Github.github' $ Github.issuesForRepoR "haskell-github" "playground" Github.stateClosed Github.FetchAll
18+
19+
printIssues :: Either Github.Error (Vector Github.Issue) -> IO ()
20+
printIssues = \case
21+
Left err ->
22+
putStrLn $ "Error: " ++ show err
23+
Right issues ->
24+
putStrLn $ intercalate "\n\n" $ map formatIssue $ toList issues
1525

1626
formatIssue :: Github.Issue -> String
1727
formatIssue issue = concat
@@ -23,6 +33,7 @@ formatIssue issue = concat
2333

2434
, "It is currently "
2535
, show $ Github.issueState issue
36+
, maybe "" (\ r -> " with reason " ++ show r) $ Github.issueStateReason issue
2637
, " with "
2738
, show $ Github.issueComments issue
2839
, " comments.\n\n"

src/GitHub/Data/Issues.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import GitHub.Data.Definitions
99
import GitHub.Data.Id (Id)
1010
import GitHub.Data.Milestone (Milestone)
1111
import GitHub.Data.Name (Name)
12-
import GitHub.Data.Options (IssueState)
12+
import GitHub.Data.Options (IssueState, IssueStateReason)
1313
import GitHub.Data.PullRequests
1414
import GitHub.Data.URL (URL)
1515
import GitHub.Internal.Prelude
@@ -36,6 +36,7 @@ data Issue = Issue
3636
, issueId :: !(Id Issue)
3737
, issueComments :: !Int
3838
, issueMilestone :: !(Maybe Milestone)
39+
, issueStateReason :: !(Maybe IssueStateReason)
3940
}
4041
deriving (Show, Data, Typeable, Eq, Ord, Generic)
4142

@@ -203,6 +204,7 @@ instance FromJSON Issue where
203204
<*> o .: "id"
204205
<*> o .: "comments"
205206
<*> o .:? "milestone"
207+
<*> o .:? "state_reason"
206208

207209
instance ToJSON NewIssue where
208210
toJSON (NewIssue t b a m ls) = object $ filter notNull

src/GitHub/Data/Options.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module GitHub.Data.Options (
5050
optionsAssignee,
5151
-- * Data
5252
IssueState (..),
53+
IssueStateReason (..),
5354
MergeableState (..),
5455
-- * Internal
5556
HasState,
@@ -94,6 +95,30 @@ instance FromJSON IssueState where
9495
instance NFData IssueState where rnf = genericRnf
9596
instance Binary IssueState
9697

98+
-- | 'GitHub.Data.Issues.Issue' state reason
99+
data IssueStateReason
100+
= StateReasonCompleted
101+
| StateReasonNotPlanned
102+
| StateReasonReopened
103+
deriving
104+
(Eq, Ord, Show, Enum, Bounded, Generic, Typeable, Data)
105+
106+
instance ToJSON IssueStateReason where
107+
toJSON = String . \case
108+
StateReasonCompleted -> "completed"
109+
StateReasonNotPlanned -> "not_planned"
110+
StateReasonReopened -> "reopened"
111+
112+
instance FromJSON IssueStateReason where
113+
parseJSON = withText "IssueStateReason" $ \t -> case T.toLower t of
114+
"completed" -> pure StateReasonCompleted
115+
"not_planned" -> pure StateReasonNotPlanned
116+
"reopened" -> pure StateReasonReopened
117+
_ -> fail $ "Unknown IssueStateReason: " <> T.unpack t
118+
119+
instance NFData IssueStateReason where rnf = genericRnf
120+
instance Binary IssueStateReason
121+
97122
-- | 'GitHub.Data.PullRequests.PullRequest' mergeable_state
98123
data MergeableState
99124
= StateUnknown

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy