Skip to content

Commit 6ae6af7

Browse files
committed
Some cleanups
1 parent dc27d81 commit 6ae6af7

File tree

5 files changed

+62
-48
lines changed

5 files changed

+62
-48
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## Changes for 0.19.1
2+
3+
- Add ratelimit endpoint
4+
[#315](https://github.com/phadej/github/pull/315/)
5+
- Add some deployment endoints
6+
[#330](https://github.com/phadej/github/pull/330/)
7+
- Add webhook installation events
8+
[#329](https://github.com/phadej/github/pull/330/)
9+
110
## Changes for 0.19
211

312
- Fix issue event type enumeration

CONTRIBUTING.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
Contributing
2-
------------
2+
============
33

4-
When adding a new public function
5-
=================================
4+
When adding a new endpoint
5+
--------------------------
66

7-
* Write a test (or sample) in the appropriate place in the samples/ directory.
8-
* Implement the function.
9-
* Submit a pull request.
7+
```haskell
8+
-- | The title, as in the GitHub API docs.
9+
-- <url to the docs>
10+
endpointR :: Request k EndpointResult
11+
endpointR = query ["endpoint"] []
12+
```
1013

11-
When modifying an existing data structure
12-
=========================================
14+
For example:
1315

14-
* Find all samples that use the data structure and make sure they run.
15-
* Modify the data structure.
16-
* Modify the samples as appropriate.
17-
* Make sure all relevant samples still run.
18-
* Submit a pull request.
16+
```haskell
17+
-- | Get your current rate limit status.
18+
-- <https://developer.github.com/v3/rate_limit/#get-your-current-rate-limit-status>
19+
rateLimitR :: Request k RateLimit
20+
rateLimitR = query ["rate_limit"] []
21+
```
1922

20-
Submitting a pull request
21-
=========================
23+
Also re-export endpoints from the top `GitHub` module. *Note:* only `R` variants, not `IO`.
2224

23-
* If your code is radically different from existing functionality, give
24-
some explanation for how it fits in this library.
25-
* Create a topic branch on your fork.
26-
* Rebase and squash your commits.
25+
Miscellaneous
26+
-------------
27+
28+
* **Don't** edit `CHANGELOG.md`, it will only conflict.
29+
* **Don't** edit package version.
30+
* The codebase is not uniform in style, don't make it worse.

src/GitHub.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,7 @@ module GitHub (
359359

360360
-- ** Rate Limit
361361
-- | See <https://developer.github.com/v3/rate_limit/>
362-
rateLimit,
363-
rateLimit',
362+
rateLimitR,
364363

365364
-- * Data definitions
366365
module GitHub.Data,

src/GitHub/Data/RateLimit.hs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{-# LANGUAGE RecordWildCards #-}
2-
31
-----------------------------------------------------------------------------
42
-- |
53
-- License : BSD-3-Clause
@@ -10,31 +8,36 @@ module GitHub.Data.RateLimit where
108
import GitHub.Internal.Prelude
119
import Prelude ()
1210

11+
data Limits = Limits
12+
{ limitsMax :: !Int
13+
, limitsRemaining :: !Int
14+
, limitsReset :: !Int -- TODO: change to proper type
15+
}
16+
deriving (Show, Data, Typeable, Eq, Ord, Generic)
17+
18+
instance NFData Limits where rnf = genericRnf
19+
instance Binary Limits
20+
21+
instance FromJSON Limits where
22+
parseJSON = withObject "Limits" $ \obj -> Limits
23+
<$> obj .: "limit"
24+
<*> obj .: "remaining"
25+
<*> obj .: "reset"
1326

1427
data RateLimit = RateLimit
15-
{ coreLimit :: !Int
16-
, coreRemaining :: !Int
17-
, coreReset :: !Int
18-
, searchLimit :: !Int
19-
, searchRemaining :: !Int
20-
, searchReset :: !Int
28+
{ rateLimitCore :: Limits
29+
, rateLimitSearch :: Limits
30+
, rateLimitGraphQL :: Limits
2131
}
2232
deriving (Show, Data, Typeable, Eq, Ord, Generic)
2333

2434
instance NFData RateLimit where rnf = genericRnf
2535
instance Binary RateLimit
2636

2737
instance FromJSON RateLimit where
28-
parseJSON = withObject "RateLimit" $ \o -> do
29-
resources <- o .: "resources"
30-
core <- resources .: "core"
31-
coreLimit <- core .: "limit"
32-
coreRemaining <- core .: "remaining"
33-
coreReset <- core .: "reset"
34-
35-
search <- resources .: "search"
36-
searchLimit <- search .: "limit"
37-
searchRemaining <- search .: "remaining"
38-
searchReset <- search .: "reset"
39-
40-
return RateLimit{..}
38+
parseJSON = withObject "RateLimit" $ \obj -> do
39+
resources <- obj .: "resources"
40+
RateLimit
41+
<$> resources .: "core"
42+
<*> resources .: "search"
43+
<*> resources .: "graphql"

src/GitHub/Endpoints/RateLimit.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
--
66
-- The Github RateLimit API, as described at
77
-- <http://developer.github.com/v3/rate_limit/>.
8-
module GitHub.Endpoints.RateLimit(
9-
rateLimit',
8+
module GitHub.Endpoints.RateLimit (
9+
rateLimitR,
1010
rateLimit,
11+
rateLimit',
1112
module GitHub.Data,
1213
) where
1314

@@ -16,19 +17,17 @@ import GitHub.Internal.Prelude
1617
import GitHub.Request
1718
import Prelude ()
1819

19-
import qualified Data.Text.Encoding as TE
20-
2120
-- | Get your current rate limit status (Note: Accessing this endpoint does not count against your rate limit.)
2221
-- With authentication.
2322
rateLimit' :: Maybe Auth -> IO (Either Error RateLimit)
2423
rateLimit' auth = executeRequestMaybe auth rateLimitR
2524

2625
-- | Get your current rate limit status (Note: Accessing this endpoint does not count against your rate limit.)
2726
-- Without authentication.
28-
--
29-
-- > searchRepos "q=a in%3Aname language%3Ahaskell created%3A>2013-10-01&per_page=100"
3027
rateLimit :: IO (Either Error RateLimit)
3128
rateLimit = rateLimit' Nothing
3229

30+
-- | Get your current rate limit status.
31+
-- <https://developer.github.com/v3/rate_limit/#get-your-current-rate-limit-status>
3332
rateLimitR :: Request k RateLimit
3433
rateLimitR = query ["rate_limit"] []

0 commit comments

Comments
 (0)