Skip to content

Commit df3cea1

Browse files
authored
Merge pull request #375 from phadej/pull-363-ssh-keys-endpoints
Pull 363 ssh keys endpoints
2 parents 1119ad4 + 33b093c commit df3cea1

18 files changed

+421
-18
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ matrix:
3434
env: GHCHEAD=true
3535
- compiler: ghc-8.6.5
3636
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.6.5","cabal-install-2.4"]}}
37-
- compiler: ghc-8.4.3
38-
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.4.3","cabal-install-2.4"]}}
37+
- compiler: ghc-8.4.4
38+
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.4.4","cabal-install-2.4"]}}
3939
- compiler: ghc-8.2.2
4040
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.2.2","cabal-install-2.4"]}}
4141
- compiler: ghc-8.0.2

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
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+
- Add ssh keys endpoints
18+
[#363](https://github.com/phadej/github/pull/365)
19+
- Case insensitive enum parsing
20+
[#373](https://github.com/phadej/github/pull/373)
1521
- Update dependencies
1622
[#364](https://github.com/phadej/github/pull/364)
1723
[#368](https://github.com/phadej/github/pull/368)

github.cabal

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ copyright:
3030
Copyright 2012-2013 Mike Burns, Copyright 2013-2015 John Wiegley, Copyright 2016-2019 Oleg Grenrus
3131

3232
tested-with:
33-
GHC ==7.8.4 || ==7.10.3 || ==8.0.2 || ==8.2.2 || ==8.4.3 || ==8.6.5 || ==8.8.1
33+
GHC ==7.8.4 || ==7.10.3 || ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.1
3434

3535
extra-source-files:
3636
README.md
@@ -87,6 +87,7 @@ library
8787
GitHub.Data.Milestone
8888
GitHub.Data.Name
8989
GitHub.Data.Options
90+
GitHub.Data.PublicSSHKeys
9091
GitHub.Data.PullRequests
9192
GitHub.Data.RateLimit
9293
GitHub.Data.Releases
@@ -132,10 +133,12 @@ library
132133
GitHub.Endpoints.Repos.Releases
133134
GitHub.Endpoints.Repos.Statuses
134135
GitHub.Endpoints.Repos.Webhooks
136+
GitHub.Endpoints.Repos.Invitations
135137
GitHub.Endpoints.Search
136138
GitHub.Endpoints.Users
137139
GitHub.Endpoints.Users.Emails
138140
GitHub.Endpoints.Users.Followers
141+
GitHub.Endpoints.Users.PublicSSHKeys
139142
GitHub.Internal.Prelude
140143
GitHub.Request
141144

@@ -193,6 +196,7 @@ test-suite github-test
193196
GitHub.IssuesSpec
194197
GitHub.OrganizationsSpec
195198
GitHub.PullRequestReviewsSpec
199+
GitHub.PublicSSHKeysSpec
196200
GitHub.PullRequestsSpec
197201
GitHub.RateLimitSpec
198202
GitHub.ReleasesSpec
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Main (main) where
3+
4+
import qualified GitHub.Data.PublicSSHKeys as PK
5+
import qualified GitHub.Endpoints.Users.PublicSSHKeys as PK
6+
import qualified GitHub.Auth as Auth
7+
import Data.Text (Text)
8+
9+
main :: IO ()
10+
main = do
11+
let auth = Auth.OAuth "auth_token"
12+
ePublicSSHKey <- PK.createUserPublicSSHKey' auth newPublicSSHKey
13+
case ePublicSSHKey of
14+
(Left err) -> putStrLn $ "Error: " ++ (show err)
15+
(Right publicSSHKey) -> putStrLn $ show publicSSHKey
16+
17+
newPublicSSHKey :: PK.NewPublicSSHKey
18+
newPublicSSHKey =
19+
PK.NewPublicSSHKey
20+
{ PK.newPublicSSHKeyKey = "test-key"
21+
, PK.newPublicSSHKeyTitle = "some-name-for-your-key"
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Main (main) where
3+
4+
import GitHub.Data.Id (Id (..))
5+
import qualified GitHub.Endpoints.Users.PublicSSHKeys as PK
6+
import qualified GitHub.Auth as Auth
7+
8+
main :: IO ()
9+
main = do
10+
let auth = Auth.OAuth "auth_token"
11+
ePublicSSHKey <- PK.deleteUserPublicSSHKey' auth (Id 18530161)
12+
case ePublicSSHKey of
13+
(Left err) -> putStrLn $ "Error: " ++ (show err)
14+
(Right _) -> putStrLn $ "Deleted public SSH key!"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Main (main) where
3+
4+
import qualified GitHub.Data.PublicSSHKeys as PK
5+
import qualified GitHub.Endpoints.Users.PublicSSHKeys as PK
6+
import qualified GitHub.Auth as Auth
7+
import Data.List (intercalate)
8+
import Data.Vector (toList)
9+
10+
main :: IO ()
11+
main = do
12+
-- Fetch the SSH public keys of another user
13+
ePublicSSHKeys <- PK.publicSSHKeysFor' "github_name"
14+
case ePublicSSHKeys of
15+
(Left err) -> putStrLn $ "Error: " ++ (show err)
16+
(Right publicSSHKeys) -> putStrLn $ intercalate "\n" $ map show (toList publicSSHKeys)
17+
18+
-- Fetch my SSH public keys
19+
let auth = Auth.OAuth "auth_token"
20+
eMyPublicSSHKeys <- PK.publicSSHKeys' auth
21+
case eMyPublicSSHKeys of
22+
(Left err) -> putStrLn $ "Error: " ++ (show err)
23+
(Right publicSSHKeys) -> putStrLn $ intercalate "\n" $ map show (toList publicSSHKeys)
24+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Main (main) where
3+
4+
import GitHub.Data.Id (Id (..))
5+
import qualified GitHub.Data.PublicSSHKeys as PK
6+
import qualified GitHub.Endpoints.Users.PublicSSHKeys as PK
7+
import qualified GitHub.Auth as Auth
8+
9+
main :: IO ()
10+
main = do
11+
let auth = Auth.OAuth "auth_token"
12+
ePublicSSHKey <- PK.publicSSHKey' auth (Id 18528451)
13+
case ePublicSSHKey of
14+
(Left err) -> putStrLn $ "Error: " ++ (show err)
15+
(Right publicSSHKey) -> putStrLn $ show publicSSHKey

samples/github-samples.cabal

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,56 @@ executable github-teaminfo-for
269269
, text
270270
, github-samples
271271
default-language: Haskell2010
272+
273+
executable github-create-public-ssh-key
274+
main-is: CreatePublicSSHKey.hs
275+
hs-source-dirs:
276+
Users/PublicSSHKeys
277+
ghc-options: -Wall
278+
build-depends:
279+
base
280+
, base-compat
281+
, github
282+
, text
283+
, github-samples
284+
default-language: Haskell2010
285+
286+
executable github-delete-public-ssh-key
287+
main-is: DeletePublicSSHKey.hs
288+
hs-source-dirs:
289+
Users/PublicSSHKeys
290+
ghc-options: -Wall
291+
build-depends:
292+
base
293+
, base-compat
294+
, github
295+
, text
296+
, github-samples
297+
default-language: Haskell2010
298+
299+
executable github-list-public-ssh-keys
300+
main-is: ListPublicSSHKeys.hs
301+
hs-source-dirs:
302+
Users/PublicSSHKeys
303+
ghc-options: -Wall
304+
build-depends:
305+
base
306+
, base-compat
307+
, github
308+
, text
309+
, github-samples
310+
, vector
311+
default-language: Haskell2010
312+
313+
executable github-get-public-ssh-key
314+
main-is: ShowPublicSSHKey.hs
315+
hs-source-dirs:
316+
Users/PublicSSHKeys
317+
ghc-options: -Wall
318+
build-depends:
319+
base
320+
, base-compat
321+
, github
322+
, text
323+
, github-samples
324+
default-language: Haskell2010

spec/GitHub/PublicSSHKeysSpec.hs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE TemplateHaskell #-}
3+
module GitHub.PublicSSHKeysSpec where
4+
5+
import GitHub
6+
(Auth (..), FetchCount (..), PublicSSHKey (..), executeRequest)
7+
import GitHub.Endpoints.Users.PublicSSHKeys
8+
(publicSSHKey', publicSSHKeys', publicSSHKeysForR)
9+
10+
import Data.Either.Compat (isRight)
11+
import Data.String (fromString)
12+
import System.Environment (lookupEnv)
13+
import Test.Hspec (Spec, describe, it, pendingWith, shouldSatisfy)
14+
15+
import qualified Data.Vector as V
16+
17+
fromRightS :: Show a => Either a b -> b
18+
fromRightS (Right b) = b
19+
fromRightS (Left a) = error $ "Expected a Right and got a Left" ++ show a
20+
21+
withAuth :: (Auth -> IO ()) -> IO ()
22+
withAuth action = do
23+
mtoken <- lookupEnv "GITHUB_TOKEN"
24+
case mtoken of
25+
Nothing -> pendingWith "no GITHUB_TOKEN"
26+
Just token -> action (OAuth $ fromString token)
27+
28+
spec :: Spec
29+
spec = do
30+
describe "publicSSHKeysFor'" $ do
31+
it "works" $ withAuth $ \auth -> do
32+
keys <- executeRequest auth $ publicSSHKeysForR "phadej" FetchAll
33+
V.length (fromRightS keys) `shouldSatisfy` (> 1)
34+
35+
describe "publicSSHKeys' and publicSSHKey'" $ do
36+
it "works" $ withAuth $ \auth -> do
37+
keys <- publicSSHKeys' auth
38+
V.length (fromRightS keys) `shouldSatisfy` (> 1)
39+
40+
key <- publicSSHKey' auth (publicSSHKeyId $ V.head (fromRightS keys))
41+
key `shouldSatisfy` isRight

src/GitHub.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,19 @@ module GitHub (
319319
latestReleaseR,
320320
releaseByTagNameR,
321321

322+
-- ** Invitations
323+
-- | See <https://developer.github.com/v3/repos/invitations/>
324+
-- Missing endpoints:
325+
326+
-- * Delete a repository invitation
327+
-- * Update a repository invitation
328+
-- * Decline a repository invitation
329+
330+
listInvitationsOnR,
331+
acceptInvitationFromR,
332+
listInvitationsForR,
333+
334+
322335
-- * Search
323336
-- | See <https://developer.github.com/v3/search/>
324337
--
@@ -408,6 +421,7 @@ import GitHub.Endpoints.Repos.Comments
408421
import GitHub.Endpoints.Repos.Commits
409422
import GitHub.Endpoints.Repos.Deployments
410423
import GitHub.Endpoints.Repos.Forks
424+
import GitHub.Endpoints.Repos.Invitations
411425
import GitHub.Endpoints.Repos.Releases
412426
import GitHub.Endpoints.Repos.Statuses
413427
import GitHub.Endpoints.Repos.Webhooks

0 commit comments

Comments
 (0)