packages feed

niv 0.2.17 → 0.2.18

raw patch · 4 files changed

+51/−15 lines, 4 files

Files

README.md view
@@ -69,12 +69,12 @@  | Name            | Note | | --------------- | ---- |-| GITHUB_TOKEN    | When set, the value is used to authenticate GitHub API requests. |-| GITHUB_HOST     | The GitHub host to use when fetching packages. Port may be appended here. |-| GITHUB_API_HOST | The host used when performing GitHub API requests. Use `GITHUB_API_PORT` for specifying the port. |-| GITHUB_API_PORT | The port used when performing GitHub API requests. Defaults to `443` for secure requests. Defaults to `80` for insecure requests. See also: `GITHUB_INSECURE`. |-| GITHUB_INSECURE | When set to anything but the empty string, requests are performed over `http` instead of `https`. |-| GITHUB_PATH     | The base path used when performing GitHub API requests. |+| GITHUB_TOKEN or NIV_GITHUB_TOKEN | When set, the value is used to authenticate GitHub API requests. |+| GITHUB_HOST or NIV_GITHUB_HOST | The GitHub host to use when fetching packages. Port may be appended here. |+| GITHUB_API_HOST or NIV_GITHUB_API_HOST | The host used when performing GitHub API requests. Use `GITHUB_API_PORT` for specifying the port. |+| GITHUB_API_PORT or NIV_GITHUB_API_PORT | The port used when performing GitHub API requests. Defaults to `443` for secure requests. Defaults to `80` for insecure requests. See also: `GITHUB_INSECURE`. |+| NIV_GITHUB_INSECURE | When set to anything but the empty string, requests are performed over `http` instead of `https`. |+| NIV_GITHUB_PATH     | The base path used when performing GitHub API requests. |  The next two sections cover [common use cases](#getting-started) and [full command description](#commands).@@ -216,7 +216,7 @@ ``` niv - dependency manager for Nix projects -version: 0.2.17+version: 0.2.18  Usage: niv [-s|--sources-file FILE] COMMAND 
niv.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 4857c6cf14357571406715c9ab94a54fbc920e9ae18dd7b647b8f25186023aaa+-- hash: f33a4bacf65fdd3b3ad1ee550d862cd5394d00eb4c7f2bf5c51890eb76124fbb  name:           niv-version:        0.2.17+version:        0.2.18 synopsis:       Easy dependency management for Nix projects description:    Easy dependency management for Nix projects. category:       Development
src/Niv/Cli.hs view
@@ -24,6 +24,7 @@ import Data.Version (showVersion) import Niv.Cmd import Niv.Git.Cmd+import Niv.GitHub.API (warnGitHubEnvVars) import Niv.GitHub.Cmd import Niv.Local.Cmd import Niv.Logger@@ -52,6 +53,7 @@  cli :: IO () cli = do+  warnGitHubEnvVars   (fsj, nio) <-     execParserPure' Opts.defaultPrefs opts <$> getArgs       >>= Opts.handleParseResult
src/Niv/GitHub/API.hs view
@@ -15,6 +15,7 @@ import qualified Data.Text.Encoding as T import Data.Text.Extended import qualified Network.HTTP.Simple as HTTP+import Niv.Logger import System.Environment (lookupEnv) import System.Exit (exitFailure) import System.IO.Unsafe (unsafePerformIO)@@ -80,7 +81,7 @@ defaultRequest :: [T.Text] -> IO HTTP.Request defaultRequest (map T.encodeUtf8 -> parts) = do   let path = T.encodeUtf8 githubPath <> BS8.intercalate "/" (parts)-  mtoken <- lookupEnv "GITHUB_TOKEN"+  mtoken <- lookupEnv' "GITHUB_TOKEN"   pure     $ ( flip (maybe id) mtoken $ \token ->           HTTP.addRequestHeader "authorization" ("token " <> BS8.pack token)@@ -134,33 +135,66 @@  |] +-- Some environment variables may have different meanings (see for instance+-- https://github.com/nmattia/niv/issues/280)+-- For ambiguous ones, we prepend NIV_.+--+warnGitHubEnvVars :: IO ()+warnGitHubEnvVars =+  mapM_+    warnEnvVar+    [ "GITHUB_INSECURE",+      "GITHUB_PATH"+    ]+  where+    warnEnvVar vn = lookupEnv (T.unpack vn) >>= \case+      Nothing -> pure ()+      Just {} -> do+        twarn $+          T.unwords+            [ "The environment variable",+              vn,+              "was renamed to",+              "NIV_" <> vn+            ]++-- | Like lookupEnv "foo" but also looks up "NIV_foo"+lookupEnv' :: String -> IO (Maybe String)+lookupEnv' vn = lookupEnv vn >>= \case+  Just x -> pure (Just x)+  Nothing -> lookupEnv ("NIV_" <> vn)+ githubHost :: T.Text githubHost = unsafePerformIO $ do-  lookupEnv "GITHUB_HOST" >>= \case+  lookupEnv' "GITHUB_HOST" >>= \case     Just (T.pack -> x) -> pure x     Nothing -> pure "github.com"  githubApiPort :: Int githubApiPort = unsafePerformIO $ do-  lookupEnv "GITHUB_API_PORT" >>= \case+  lookupEnv' "GITHUB_API_PORT" >>= \case     Just (readMaybe -> Just x) -> pure x     _ -> pure $ if githubSecure then 443 else 80  githubApiHost :: T.Text githubApiHost = unsafePerformIO $ do-  lookupEnv "GITHUB_API_HOST" >>= \case+  lookupEnv' "GITHUB_API_HOST" >>= \case     Just (T.pack -> x) -> pure x     Nothing -> pure "api.github.com" +-- For these two we prepend NIV_ to the variable name because the variable+-- names can have different meanings, see+-- https://github.com/nmattia/niv/issues/280+ githubSecure :: Bool githubSecure = unsafePerformIO $ do-  lookupEnv "GITHUB_INSECURE" >>= \case+  lookupEnv "NIV_GITHUB_INSECURE" >>= \case     Just "" -> pure True     Just _ -> pure False     Nothing -> pure True  githubPath :: T.Text githubPath = unsafePerformIO $ do-  lookupEnv "GITHUB_PATH" >>= \case+  lookupEnv "NIV_GITHUB_PATH" >>= \case     Just (T.pack -> x) -> pure $ fromMaybe x (T.stripSuffix "/" x) <> "/"     Nothing -> pure "/"