Skip to content

Commit e631f83

Browse files
committed
Add status-reading endpoints
1 parent 7a72215 commit e631f83

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

src/GitHub/Data/Statuses.hs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
module GitHub.Data.Statuses where
66

77
import GitHub.Data.Definitions
8+
import GitHub.Data.Name (Name)
89
import GitHub.Data.Id (Id)
910
import GitHub.Data.URL (URL)
1011
import GitHub.Internal.Prelude
1112
import Prelude ()
1213

14+
import GitHub.Data.GitData (Commit)
15+
import GitHub.Data.Repos (RepoRef)
16+
17+
1318
data StatusState
1419
= StatusPending
1520
| StatusSuccess
@@ -33,6 +38,7 @@ instance ToJSON StatusState where
3338
toJSON StatusError = String "error"
3439
toJSON StatusFailure = String "failure"
3540

41+
3642
data Status = Status
3743
{ statusCreatedAt :: !UTCTime
3844
, statusUpdatedAt :: !UTCTime
@@ -42,7 +48,7 @@ data Status = Status
4248
, statusId :: !(Id Status)
4349
, statusUrl :: !URL
4450
, statusContext :: !(Maybe Text)
45-
, statusCreator :: !SimpleUser
51+
, statusCreator :: !(Maybe SimpleUser)
4652
}
4753
deriving (Show, Data, Typeable, Eq, Ord, Generic)
4854

@@ -56,7 +62,8 @@ instance FromJSON Status where
5662
<*> o .: "id"
5763
<*> o .: "url"
5864
<*> o .:? "context"
59-
<*> o .: "creator"
65+
<*> o .:? "creator"
66+
6067

6168
data NewStatus = NewStatus
6269
{ newStatusState :: !StatusState
@@ -79,3 +86,25 @@ instance ToJSON NewStatus where
7986
where
8087
notNull (_, Null) = False
8188
notNull (_, _) = True
89+
90+
91+
data CombinedStatus = CombinedStatus
92+
{ combinedStatusState :: !StatusState
93+
, combinedStatusSha :: !(Name Commit)
94+
, combinedStatusTotalCount :: !Int
95+
, combinedStatusStatuses :: !(Vector Status)
96+
, combinedStatusRepository :: !RepoRef
97+
, combinedStatusCommitUrl :: !URL
98+
, combinedStatusUrl :: !URL
99+
}
100+
deriving (Show, Data, Typeable, Eq, Ord, Generic)
101+
102+
instance FromJSON CombinedStatus where
103+
parseJSON = withObject "CombinedStatus" $ \o -> CombinedStatus
104+
<$> o .: "state"
105+
<*> o .: "sha"
106+
<*> o .: "total_count"
107+
<*> o .: "statuses"
108+
<*> o .: "repository"
109+
<*> o .: "commit_url"
110+
<*> o .: "url"

src/GitHub/Endpoints/Repos/Statuses.hs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
module GitHub.Endpoints.Repos.Statuses (
55
createStatus,
66
createStatusR,
7+
statusesFor,
8+
statusesForR,
9+
statusFor,
10+
statusForR,
711
module GitHub.Data
812
) where
913

@@ -14,10 +18,26 @@ import Prelude ()
1418

1519
createStatus :: Auth -> Name Owner -> Name Repo -> Name Commit -> NewStatus -> IO (Either Error Status)
1620
createStatus auth owner repo sha ns =
17-
executeRequest auth $ createStatusR owner repo sha ns
21+
executeRequest auth $ createStatusR owner repo sha ns
1822

1923
createStatusR :: Name Owner -> Name Repo -> Name Commit -> NewStatus -> Request 'RW Status
2024
createStatusR owner repo sha =
21-
command Post parts . encode
22-
where
23-
parts = ["repos", toPathPart owner, toPathPart repo, "statuses", toPathPart sha]
25+
command Post parts . encode
26+
where
27+
parts = ["repos", toPathPart owner, toPathPart repo, "statuses", toPathPart sha]
28+
29+
statusesFor :: Auth -> Name Owner -> Name Repo -> Name Commit -> IO (Either Error (Vector Status))
30+
statusesFor auth user repo sha =
31+
executeRequest auth $ statusesForR user repo sha FetchAll
32+
33+
statusesForR :: Name Owner -> Name Repo -> Name Commit -> FetchCount -> Request 'RW (Vector Status)
34+
statusesForR user repo sha =
35+
pagedQuery ["repos", toPathPart user, toPathPart repo, "commits", toPathPart sha, "statuses"] []
36+
37+
statusFor :: Auth -> Name Owner -> Name Repo -> Name Commit -> IO (Either Error CombinedStatus)
38+
statusFor auth user repo sha =
39+
executeRequest auth $ statusForR user repo sha
40+
41+
statusForR :: Name Owner -> Name Repo -> Name Commit -> Request 'RW CombinedStatus
42+
statusForR user repo sha =
43+
query ["repos", toPathPart user, toPathPart repo, "commits", toPathPart sha, "status"] []

0 commit comments

Comments
 (0)