Skip to content

Commit 979fb5a

Browse files
authored
Merge pull request #347 from phadej/issue-334
Fix #334: Introduce IssueNumber newtype
2 parents b8f999f + fbfcdd6 commit 979fb5a

File tree

13 files changed

+145
-100
lines changed

13 files changed

+145
-100
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
## Changes for next
22

3-
- Allow http-client-0.6
3+
## Changes for 0.21
44

5-
- Change to use `cryptohash-sha1` (before `cryptohash`)
5+
- Allow `http-client-0.6`
6+
- Change to use `cryptohash-sha1` (`cryptohash` was used before)
67

78
## Changes for 0.20
89

cabal.project

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
packages:
22
"."
33
samples
4+
5+
optimization: False
6+
tests: True

github.cabal

Lines changed: 83 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
name: github
2-
version: 0.20
3-
synopsis: Access to the GitHub API, v3.
1+
cabal-version: >=1.10
2+
name: github
3+
version: 0.21
4+
synopsis: Access to the GitHub API, v3.
5+
category: Network
46
description:
57
The GitHub API provides programmatic access to the full
68
GitHub Web site, from Issues to Gists to repos down to the underlying git data
@@ -17,52 +19,56 @@ description:
1719
> print possibleUser
1820
.
1921
For more of an overview please see the README: <https://github.com/phadej/github/blob/master/README.md>
20-
license: BSD3
21-
license-file: LICENSE
22-
author: Mike Burns, John Wiegley, Oleg Grenrus
23-
maintainer: Oleg Grenrus <oleg.grenrus@iki.fi>
24-
homepage: https://github.com/phadej/github
25-
copyright: Copyright 2012-2013 Mike Burns, Copyright 2013-2015 John Wiegley, Copyright 2016 Oleg Grenrus
26-
category: Network
27-
build-type: Simple
28-
tested-with: GHC==7.8.4, GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.3, GHC==8.6.1
29-
cabal-version: >=1.10
22+
23+
license: BSD3
24+
license-file: LICENSE
25+
author: Mike Burns, John Wiegley, Oleg Grenrus
26+
maintainer: Oleg Grenrus <oleg.grenrus@iki.fi>
27+
homepage: https://github.com/phadej/github
28+
build-type: Simple
29+
copyright:
30+
Copyright 2012-2013 Mike Burns, Copyright 2013-2015 John Wiegley, Copyright 2016-2019 Oleg Grenrus
31+
32+
tested-with:
33+
ghc ==7.8.4 || ==7.10.3 || ==8.0.2 || ==8.2.2 || ==8.4.3 || ==8.6.3
34+
3035
extra-source-files:
31-
README.md,
32-
CHANGELOG.md,
33-
fixtures/issue-search.json,
34-
fixtures/list-teams.json,
35-
fixtures/members-list.json,
36-
fixtures/pull-request-opened.json,
37-
fixtures/pull-request-review-requested.json,
38-
fixtures/user-organizations.json,
36+
README.md
37+
CHANGELOG.md
38+
fixtures/issue-search.json
39+
fixtures/list-teams.json
40+
fixtures/members-list.json
41+
fixtures/pull-request-opened.json
42+
fixtures/pull-request-review-requested.json
43+
fixtures/user-organizations.json
3944
fixtures/user.json
4045

4146
source-repository head
42-
type: git
47+
type: git
4348
location: git://github.com/phadej/github.git
4449

45-
Library
46-
default-language: Haskell2010
47-
ghc-options: -Wall
48-
hs-source-dirs: src
50+
library
51+
default-language: Haskell2010
52+
ghc-options: -Wall
53+
hs-source-dirs: src
4954
default-extensions:
5055
DataKinds
5156
DeriveDataTypeable
5257
DeriveGeneric
5358
OverloadedStrings
5459
ScopedTypeVariables
60+
5561
other-extensions:
5662
CPP
5763
FlexibleContexts
5864
FlexibleInstances
5965
GADTs
6066
KindSignatures
67+
RecordWildCards
6168
StandaloneDeriving
62-
RecordWildCards
69+
6370
exposed-modules:
6471
GitHub
65-
GitHub.Internal.Prelude
6672
GitHub.Auth
6773
GitHub.Data
6874
GitHub.Data.Activities
@@ -111,8 +117,8 @@ Library
111117
GitHub.Endpoints.Organizations.Members
112118
GitHub.Endpoints.Organizations.Teams
113119
GitHub.Endpoints.PullRequests
114-
GitHub.Endpoints.PullRequests.Reviews
115120
GitHub.Endpoints.PullRequests.Comments
121+
GitHub.Endpoints.PullRequests.Reviews
116122
GitHub.Endpoints.RateLimit
117123
GitHub.Endpoints.Repos
118124
GitHub.Endpoints.Repos.Collaborators
@@ -129,50 +135,52 @@ Library
129135
GitHub.Endpoints.Users
130136
GitHub.Endpoints.Users.Emails
131137
GitHub.Endpoints.Users.Followers
138+
GitHub.Internal.Prelude
132139
GitHub.Request
133140

134141
-- Packages bundles with GHC, mtl and text are also here
135142
build-depends:
136-
base >=4.7 && <4.13,
137-
binary >=0.7.1.0 && <0.11,
138-
bytestring >=0.10.4.0 && <0.11,
139-
containers >=0.5.5.1 && <0.7,
140-
deepseq >=1.3.0.2 && <1.5,
141-
mtl (>=2.1.3.1 && <2.2) || (>=2.2.1 && <2.3),
142-
text >=1.2.0.6 && <1.3,
143-
time >=1.4 && <1.10,
144-
transformers >=0.3.0.0 && <0.6
143+
base >=4.7 && <4.13
144+
, binary >=0.7.1.0 && <0.11
145+
, bytestring >=0.10.4.0 && <0.11
146+
, containers >=0.5.5.1 && <0.7
147+
, deepseq >=1.3.0.2 && <1.5
148+
, mtl >=2.1.3.1 && <2.2 || >=2.2.1 && <2.3
149+
, text >=1.2.0.6 && <1.3
150+
, time >=1.4 && <1.10
151+
, transformers >=0.3.0.0 && <0.6
145152

146153
-- other packages
147154
build-depends:
148-
aeson >=1.4.0.0 && <1.5,
149-
base-compat >=0.10.4 && <0.11,
150-
base16-bytestring >=0.1.1.6 && <0.2,
151-
binary-orphans >=0.1.8.0 && <0.2,
152-
cryptohash-sha1 >=0.11.100.1 && <0.12,
153-
deepseq-generics >=0.2.0.0 && <0.3,
154-
exceptions >=0.10.0 && <0.11,
155-
hashable >=1.2.7.0 && <1.3,
156-
http-client >=0.5.12 && <0.7,
157-
http-client-tls >=0.3.5.3 && <0.4,
158-
http-link-header >=1.0.3.1 && <1.1,
159-
http-types >=0.12.1 && <0.13,
160-
iso8601-time >=0.1.5 && <0.2,
161-
network-uri >=2.6.1.0 && <2.7,
162-
semigroups >=0.18.5 && <0.19,
163-
transformers-compat >=0.6 && <0.7,
164-
unordered-containers >=0.2.9.0 && <0.3,
165-
vector >=0.12.0.1 && <0.13,
166-
vector-instances >=3.4 && <3.5,
167-
168-
tls >=1.4.1
155+
aeson >=1.4.0.0 && <1.5
156+
, base-compat >=0.10.4 && <0.11
157+
, base16-bytestring >=0.1.1.6 && <0.2
158+
, binary-orphans >=0.1.8.0 && <0.2
159+
, cryptohash-sha1 >=0.11.100.1 && <0.12
160+
, deepseq-generics >=0.2.0.0 && <0.3
161+
, exceptions >=0.10.0 && <0.11
162+
, hashable >=1.2.7.0 && <1.3
163+
, http-client >=0.5.12 && <0.7
164+
, http-client-tls >=0.3.5.3 && <0.4
165+
, http-link-header >=1.0.3.1 && <1.1
166+
, http-types >=0.12.1 && <0.13
167+
, iso8601-time >=0.1.5 && <0.2
168+
, network-uri >=2.6.1.0 && <2.7
169+
, semigroups >=0.18.5 && <0.19
170+
, tls >=1.4.1
171+
, transformers-compat >=0.6 && <0.7
172+
, unordered-containers >=0.2.9.0 && <0.3
173+
, vector >=0.12.0.1 && <0.13
174+
, vector-instances >=3.4 && <3.5
169175

170176
test-suite github-test
171-
default-language: Haskell2010
172-
type: exitcode-stdio-1.0
173-
hs-source-dirs: spec
174-
other-extensions:
175-
TemplateHaskell
177+
default-language: Haskell2010
178+
type: exitcode-stdio-1.0
179+
hs-source-dirs: spec
180+
main-is: Spec.hs
181+
ghc-options: -Wall
182+
build-tool-depends: hspec-discover:hspec-discover >=2.6.1 && <2.8
183+
other-extensions: TemplateHaskell
176184
other-modules:
177185
GitHub.ActivitySpec
178186
GitHub.CommitsSpec
@@ -186,15 +194,14 @@ test-suite github-test
186194
GitHub.ReposSpec
187195
GitHub.SearchSpec
188196
GitHub.UsersSpec
189-
main-is: Spec.hs
190-
ghc-options: -Wall
191-
build-tool-depends: hspec-discover:hspec-discover >=2.6.1 && <2.7
192-
build-depends: base,
193-
base-compat,
194-
aeson,
195-
bytestring,
196-
github,
197-
vector,
198-
unordered-containers,
199-
file-embed,
200-
hspec >= 2.6.1 && <2.7
197+
198+
build-depends:
199+
aeson
200+
, base
201+
, base-compat
202+
, bytestring
203+
, file-embed
204+
, github
205+
, hspec >=2.6.1 && <2.8
206+
, unordered-containers
207+
, vector

spec/GitHub/IssuesSpec.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import Data.Either.Compat (isRight)
1010
import Data.Foldable (for_)
1111
import Data.String (fromString)
1212
import System.Environment (lookupEnv)
13-
import Test.Hspec (Spec, describe, it, pendingWith, shouldSatisfy)
13+
import Test.Hspec
14+
(Spec, describe, expectationFailure, it, pendingWith, shouldSatisfy)
1415

1516
fromRightS :: Show a => Either a b -> b
1617
fromRightS (Right b) = b
@@ -28,11 +29,17 @@ spec = do
2829
describe "issuesForRepoR" $ do
2930
it "works" $ withAuth $ \auth -> for_ repos $ \(owner, repo) -> do
3031
cs <- GitHub.executeRequest auth $
31-
GitHub.issuesForRepoR owner repo mempty GitHub.FetchAll
32-
cs `shouldSatisfy` isRight
32+
GitHub.issuesForRepoR owner repo mempty GitHub.FetchAll
33+
case cs of
34+
Left e ->
35+
expectationFailure . show $ e
36+
Right cs' -> do
37+
for_ cs' $ \i -> do
38+
cms <- GitHub.executeRequest auth $
39+
GitHub.commentsR owner repo (GitHub.issueNumber i) 1
40+
cms `shouldSatisfy` isRight
3341
where
3442
repos =
3543
[ ("thoughtbot", "paperclip")
3644
, ("phadej", "github")
37-
, ("haskell", "cabal")
3845
]

spec/GitHub/PullRequestsSpec.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
module GitHub.PullRequestsSpec where
44

55
import qualified GitHub
6-
import GitHub.Data.Id (Id (Id))
76

87
import Prelude ()
98
import Prelude.Compat
@@ -55,7 +54,7 @@ spec = do
5554

5655
describe "checking if a pull request is merged" $ do
5756
it "works" $ withAuth $ \auth -> do
58-
b <- GitHub.executeRequest auth $ GitHub.isPullRequestMergedR "phadej" "github" (Id 14)
57+
b <- GitHub.executeRequest auth $ GitHub.isPullRequestMergedR "phadej" "github" (GitHub.IssueNumber 14)
5958
b `shouldSatisfy` isRight
6059
fromRightS b `shouldBe` True
6160

spec/GitHub/SearchSpec.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import Test.Hspec (Spec, describe, it, pendingWith, shouldBe)
1414

1515
import qualified Data.Vector as V
1616

17-
import GitHub.Data (Auth (..), Issue (..), IssueState (..), mkId)
17+
import GitHub.Data
18+
(Auth (..), Issue (..), IssueNumber (..), IssueState (..), mkId)
1819
import GitHub.Endpoints.Search (SearchResult (..), searchIssues')
1920

2021
fromRightS :: Show a => Either a b -> b
@@ -40,13 +41,13 @@ spec = do
4041

4142
let issue1 = issues V.! 0
4243
issueId issue1 `shouldBe` mkId (Proxy :: Proxy Issue) 123898390
43-
issueNumber issue1 `shouldBe` 130
44+
issueNumber issue1 `shouldBe` IssueNumber 130
4445
issueTitle issue1 `shouldBe` "Make test runner more robust"
4546
issueState issue1 `shouldBe` StateClosed
4647

4748
let issue2 = issues V.! 1
4849
issueId issue2 `shouldBe` mkId (Proxy :: Proxy Issue) 119694665
49-
issueNumber issue2 `shouldBe` 127
50+
issueNumber issue2 `shouldBe` IssueNumber 127
5051
issueTitle issue2 `shouldBe` "Decouple request creation from execution"
5152
issueState issue2 `shouldBe` StateOpen
5253

src/GitHub/Data.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ module GitHub.Data (
3030
mkRepoId,
3131
fromUserId,
3232
fromOrganizationId,
33+
-- * IssueNumber
34+
IssueNumber (..),
3335
-- * Module re-exports
3436
module GitHub.Auth,
3537
module GitHub.Data.Activities,

src/GitHub/Data/Definitions.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,28 @@ type QueryString = [(BS.ByteString, Maybe BS.ByteString)]
237237
-- | Count of elements
238238
type Count = Int
239239

240+
-------------------------------------------------------------------------------
241+
-- IssueNumber
242+
-------------------------------------------------------------------------------
243+
244+
newtype IssueNumber = IssueNumber Int
245+
deriving (Eq, Ord, Show, Generic, Typeable, Data)
246+
247+
unIssueNumber :: IssueNumber -> Int
248+
unIssueNumber (IssueNumber i) = i
249+
250+
instance Hashable IssueNumber
251+
instance Binary IssueNumber
252+
253+
instance NFData IssueNumber where
254+
rnf (IssueNumber s) = rnf s
255+
256+
instance FromJSON IssueNumber where
257+
parseJSON = fmap IssueNumber . parseJSON
258+
259+
instance ToJSON IssueNumber where
260+
toJSON = toJSON . unIssueNumber
261+
240262
-------------------------------------------------------------------------------
241263
-- IssueLabel
242264
-------------------------------------------------------------------------------

src/GitHub/Data/Issues.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ data Issue = Issue
2222
, issueHtmlUrl :: !(Maybe URL)
2323
, issueClosedBy :: !(Maybe SimpleUser)
2424
, issueLabels :: !(Vector IssueLabel)
25-
, issueNumber :: !Int
25+
, issueNumber :: !IssueNumber
2626
, issueAssignees :: !(Vector SimpleUser)
2727
, issueUser :: !SimpleUser
2828
, issueTitle :: !Text

src/GitHub/Data/Request.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module GitHub.Data.Request (
2727
Count,
2828
) where
2929

30-
import GitHub.Data.Definitions (Count, QueryString)
30+
import GitHub.Data.Definitions (Count, QueryString, IssueNumber, unIssueNumber)
3131
import GitHub.Data.Id (Id, untagId)
3232
import GitHub.Data.Name (Name, untagName)
3333
import GitHub.Internal.Prelude
@@ -53,6 +53,9 @@ instance IsPathPart (Name a) where
5353
instance IsPathPart (Id a) where
5454
toPathPart = T.pack . show . untagId
5555

56+
instance IsPathPart IssueNumber where
57+
toPathPart = T.pack . show . unIssueNumber
58+
5659
-- | Http method of requests with body.
5760
data CommandMethod a where
5861
Post :: CommandMethod a

0 commit comments

Comments
 (0)