Skip to content

Commit

Permalink
Made it compile
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyakooo0 committed Jan 4, 2020
1 parent 1ac3261 commit 0bede85
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ cabal.project.local
cabal.project.local~
.ghc.environment.*
*.cabal

.stack-work
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ library:
- jwt >= 0.8.0
- mtl
- safe-exceptions
- tagged
- text
- time
- x509
Expand Down
8 changes: 4 additions & 4 deletions src/GitHub/App/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import qualified Data.ByteString.Lazy as LBS
import Data.Functor (($>))
import Data.Maybe (fromMaybe)
import Data.Semigroup ((<>))
import Data.Tagged
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Encoding (encodeUtf8)
Expand All @@ -37,8 +38,7 @@ import GitHub.Data.Apps (App)
import GitHub.Data.Definitions (Error (HTTPError))
import GitHub.Data.Id (Id, untagId)
import GitHub.Data.Installations (Installation)
import GitHub.Data.Request (StatusMap)
import GitHub.Request (parseResponse)
import GitHub.Request (StatusMap, parseResponseJSON)
import Network.HTTP.Client as HTTP
import qualified Network.HTTP.Client.Internal as HTTP
import qualified Network.HTTP.Types as HTTP
Expand Down Expand Up @@ -113,7 +113,7 @@ createAccessTokenR InstallationAuth{..} = do
{ iat = Just $ toJsonTime currentTime
, exp = Just $ toJsonTime expiryTime
}
jwt = encodeSigned (RSAPrivateKey iaAppPrivateKey) claims
jwt = encodeSigned (RSAPrivateKey iaAppPrivateKey) mempty claims

req <- HTTP.parseRequest . T.unpack $ url
pure req
Expand Down Expand Up @@ -148,7 +148,7 @@ obtainAccessToken mgr ia@InstallationAuth{..} = readMVar iaToken >>= \case
renew :: IO (Either Error Auth)
renew = bracketOnError (takeMVar iaToken) (putMVar iaToken) $ \_ -> do
req <- createAccessTokenR ia
result <- runExceptT $ httpLbs' req >>= parseResponse
result <- runExceptT $ httpLbs' req >>= parseResponseJSON
case result of
Right newToken -> putMVar iaToken (Just newToken) $> Right (itToken newToken)
Left err -> putMVar iaToken Nothing $> Left err
Expand Down
6 changes: 4 additions & 2 deletions src/GitHub/App/Request.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module GitHub.App.Request
, executeAppRequestWithMgr
) where

import Data.Aeson (FromJSON)
import GitHub.Data (Error (..))
import GitHub.Data.Request (Request)
import GitHub.Request (executeRequestWithMgr)
Expand All @@ -19,7 +20,7 @@ import Network.HTTP.Client.TLS (newTlsManager)
import GitHub.App.Auth (InstallationAuth, obtainAccessToken)


executeAppRequest :: InstallationAuth -> Request k a -> IO (Either Error a)
executeAppRequest :: FromJSON a => InstallationAuth -> Request k a -> IO (Either Error a)
executeAppRequest instAuth req = do
manager <- newTlsManager
x <- executeAppRequestWithMgr manager instAuth req
Expand All @@ -29,7 +30,8 @@ executeAppRequest instAuth req = do
pure x

executeAppRequestWithMgr
:: Manager
:: FromJSON a
=> Manager
-> InstallationAuth
-> Request k a
-> IO (Either Error a)
Expand Down
8 changes: 5 additions & 3 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
resolver: lts-11.5
resolver: lts-14.19

packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver
# using the same syntax as the packages field.
# (e.g., acme-missiles-0.3)
extra-deps:
- jwt-0.8.0
extra-deps:
- github-0.24
- binary-instances-1
# - jwt-0.8.0

0 comments on commit 0bede85

Please sign in to comment.