mirror of
https://github.com/nmattia/niv.git
synced 2024-09-19 11:27:40 +03:00
Drop 'nivForTest'
This commit is contained in:
parent
366d7476d7
commit
03016df47f
@ -80,7 +80,10 @@ data GithubRepo = GithubRepo
|
|||||||
githubRepo :: T.Text -> T.Text -> IO GithubRepo
|
githubRepo :: T.Text -> T.Text -> IO GithubRepo
|
||||||
githubRepo owner repo = do
|
githubRepo owner repo = do
|
||||||
request <- defaultRequest ["repos", owner, repo]
|
request <- defaultRequest ["repos", owner, repo]
|
||||||
resp <- HTTP.httpJSONEither request -- >>= \case
|
-- we don't use httpJSONEither because it adds an "Accept:
|
||||||
|
-- application/json" header that GitHub chokes on
|
||||||
|
resp0 <- HTTP.httpBS request
|
||||||
|
let resp = fmap Aeson.eitherDecodeStrict resp0
|
||||||
case (HTTP.getResponseStatusCode resp, HTTP.getResponseBody resp) of
|
case (HTTP.getResponseStatusCode resp, HTTP.getResponseBody resp) of
|
||||||
(200, Right (Aeson.Object m)) -> do
|
(200, Right (Aeson.Object m)) -> do
|
||||||
let lookupText k = case HMS.lookup k m of
|
let lookupText k = case HMS.lookup k m of
|
||||||
@ -95,12 +98,12 @@ githubRepo owner repo = do
|
|||||||
error $ "expected object, got " <> show v
|
error $ "expected object, got " <> show v
|
||||||
(200, Left e) -> do
|
(200, Left e) -> do
|
||||||
error $ "github didn't return JSON: " <> show e
|
error $ "github didn't return JSON: " <> show e
|
||||||
_ -> abortCouldNotFetchGitHubRepo (tshow resp) (owner, repo)
|
_ -> abortCouldNotFetchGitHubRepo (tshow (request,resp0)) (owner, repo)
|
||||||
|
|
||||||
-- | TODO: Error instead of T.Text?
|
-- | TODO: Error instead of T.Text?
|
||||||
abortCouldNotFetchGitHubRepo :: T.Text -> (T.Text, T.Text) -> IO a
|
abortCouldNotFetchGitHubRepo :: T.Text -> (T.Text, T.Text) -> IO a
|
||||||
abortCouldNotFetchGitHubRepo e (T.unpack -> owner, T.unpack -> repo) = do
|
abortCouldNotFetchGitHubRepo e (T.unpack -> owner, T.unpack -> repo) = do
|
||||||
putStrLn $ unlines [ line1, line2, line3 ]
|
putStrLn $ unlines [ line1, line2, T.unpack line3 ]
|
||||||
exitFailure
|
exitFailure
|
||||||
where
|
where
|
||||||
line1 = "WARNING: Could not read from GitHub repo: " <> owner <> "/" <> repo
|
line1 = "WARNING: Could not read from GitHub repo: " <> owner <> "/" <> repo
|
||||||
@ -118,7 +121,7 @@ If not, try re-adding it:
|
|||||||
|
|
||||||
Make sure the repository exists.
|
Make sure the repository exists.
|
||||||
|]
|
|]
|
||||||
line3 = unwords [ "(Error was:", show e, ")" ]
|
line3 = T.unwords [ "(Error was:", e, ")" ]
|
||||||
|
|
||||||
defaultRequest :: [T.Text] -> IO HTTP.Request
|
defaultRequest :: [T.Text] -> IO HTTP.Request
|
||||||
defaultRequest (map T.encodeUtf8 -> parts) = do
|
defaultRequest (map T.encodeUtf8 -> parts) = do
|
||||||
@ -129,6 +132,7 @@ defaultRequest (map T.encodeUtf8 -> parts) = do
|
|||||||
HTTP.addRequestHeader "authorization" ("token " <> BS8.pack token)
|
HTTP.addRequestHeader "authorization" ("token " <> BS8.pack token)
|
||||||
) $
|
) $
|
||||||
HTTP.setRequestPath path $
|
HTTP.setRequestPath path $
|
||||||
|
HTTP.addRequestHeader "user-agent" "niv" $
|
||||||
HTTP.addRequestHeader "accept" "application/vnd.github.v3+json" $
|
HTTP.addRequestHeader "accept" "application/vnd.github.v3+json" $
|
||||||
HTTP.setRequestSecure githubSecure $
|
HTTP.setRequestSecure githubSecure $
|
||||||
HTTP.setRequestHost (T.encodeUtf8 githubApiHost) $
|
HTTP.setRequestHost (T.encodeUtf8 githubApiHost) $
|
||||||
@ -185,7 +189,7 @@ githubApiPort :: Int
|
|||||||
githubApiPort = unsafePerformIO $ do
|
githubApiPort = unsafePerformIO $ do
|
||||||
lookupEnv "GITHUB_API_PORT" >>= \case
|
lookupEnv "GITHUB_API_PORT" >>= \case
|
||||||
Just (readMaybe -> Just x) -> pure x
|
Just (readMaybe -> Just x) -> pure x
|
||||||
_ -> pure 80
|
_ -> pure $ if githubSecure then 443 else 80
|
||||||
|
|
||||||
githubApiHost :: T.Text
|
githubApiHost :: T.Text
|
||||||
githubApiHost = unsafePerformIO $ do
|
githubApiHost = unsafePerformIO $ do
|
||||||
|
@ -18,15 +18,6 @@ let
|
|||||||
niv_HEAD = "a489b65a5c3a29983701069d1ce395b23d9bde64";
|
niv_HEAD = "a489b65a5c3a29983701069d1ce395b23d9bde64";
|
||||||
niv_HEAD- = "abc51449406ba3279c466b4d356b4ae8522ceb58";
|
niv_HEAD- = "abc51449406ba3279c466b4d356b4ae8522ceb58";
|
||||||
nixpkgs-channels_HEAD = "571b40d3f50466d3e91c1e609d372de96d782793";
|
nixpkgs-channels_HEAD = "571b40d3f50466d3e91c1e609d372de96d782793";
|
||||||
nivForTest = niv.overrideDerivation(old: {
|
|
||||||
# TODO: Remove this patch by adding an argument to the github
|
|
||||||
# subcommand to support GitHub entreprise.
|
|
||||||
prePatch = ''
|
|
||||||
sed 's|githubHost = "github.com"|githubHost = "localhost:3333"|' -i src/Niv/GitHub.hs
|
|
||||||
sed 's|githuApiHost = "github.com"|githuApiHost = "localhost:3333"|' -i src/Niv/GitHub.hs
|
|
||||||
sed 's|githubSecure = True|githubSecure = False|' -i src/Niv/GitHub.hs
|
|
||||||
'';
|
|
||||||
});
|
|
||||||
in pkgs.runCommand "test"
|
in pkgs.runCommand "test"
|
||||||
{ buildInputs =
|
{ buildInputs =
|
||||||
[ pkgs.haskellPackages.wai-app-static
|
[ pkgs.haskellPackages.wai-app-static
|
||||||
|
Loading…
Reference in New Issue
Block a user