mirror of
https://github.com/nmattia/niv.git
synced 2024-11-07 22:36:53 +03:00
Merge pull request #94 from kubek2k/github-token-support
GITHUB_TOKEN env variable support for github fetcher
This commit is contained in:
commit
d65639549a
@ -13,9 +13,11 @@ import Data.Maybe
|
|||||||
import Data.String.QQ (s)
|
import Data.String.QQ (s)
|
||||||
import GHC.Exts (toList)
|
import GHC.Exts (toList)
|
||||||
import Niv.Update
|
import Niv.Update
|
||||||
|
import Data.Text.Encoding (encodeUtf8)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified GitHub as GH
|
import qualified GitHub as GH
|
||||||
import qualified GitHub.Data.Name as GH
|
import qualified GitHub.Data.Name as GH
|
||||||
|
import System.Environment (lookupEnv)
|
||||||
|
|
||||||
data GithubRepo = GithubRepo
|
data GithubRepo = GithubRepo
|
||||||
{ repoDescription :: Maybe T.Text
|
{ repoDescription :: Maybe T.Text
|
||||||
@ -24,13 +26,20 @@ data GithubRepo = GithubRepo
|
|||||||
}
|
}
|
||||||
|
|
||||||
githubRepo :: T.Text -> T.Text -> IO GithubRepo
|
githubRepo :: T.Text -> T.Text -> IO GithubRepo
|
||||||
githubRepo owner repo = fmap translate <$>
|
githubRepo owner repo = executeRequest >>= pickResponse >>= return . translate
|
||||||
GH.executeRequest' (GH.repositoryR (GH.N owner) (GH.N repo)) >>= \case
|
where
|
||||||
|
pickResponse :: Either GH.Error GH.Repo -> IO GH.Repo
|
||||||
|
pickResponse = \case
|
||||||
Left e -> do
|
Left e -> do
|
||||||
warnCouldNotFetchGitHubRepo e (owner, repo)
|
warnCouldNotFetchGitHubRepo e (owner, repo)
|
||||||
error (show e)
|
error (show e)
|
||||||
Right x -> pure x
|
Right x -> return x
|
||||||
where
|
resolveRequestExecutionFn = do
|
||||||
|
token <- fmap (GH.OAuth . encodeUtf8 . T.pack) <$> lookupEnv "GITHUB_TOKEN"
|
||||||
|
return $ maybe GH.executeRequest' GH.executeRequest token
|
||||||
|
executeRequest :: IO (Either GH.Error GH.Repo)
|
||||||
|
executeRequest = resolveRequestExecutionFn >>= \fn -> fn (GH.repositoryR (GH.N owner) (GH.N repo))
|
||||||
|
translate :: GH.Repo -> GithubRepo
|
||||||
translate r = GithubRepo
|
translate r = GithubRepo
|
||||||
{ repoDescription = GH.repoDescription r
|
{ repoDescription = GH.repoDescription r
|
||||||
, repoHomepage = GH.repoHomepage r
|
, repoHomepage = GH.repoHomepage r
|
||||||
|
@ -22,7 +22,7 @@ let
|
|||||||
# TODO: Remove this patch by adding an argument to the github
|
# TODO: Remove this patch by adding an argument to the github
|
||||||
# subcommand to support GitHub entreprise.
|
# subcommand to support GitHub entreprise.
|
||||||
prePatch = ''
|
prePatch = ''
|
||||||
sed "s|GH.executeRequest'|GH.executeRequest (GH.EnterpriseOAuth \"http://localhost:3333\" \"\")|" -i src/Niv/GitHub.hs
|
sed "s|GH.executeRequest'|(GH.executeRequest (GH.EnterpriseOAuth \"http://localhost:3333\" \"\"))|" -i src/Niv/GitHub.hs
|
||||||
sed "s|https://github.com|http://localhost:3333|" -i src/Niv/GitHub.hs
|
sed "s|https://github.com|http://localhost:3333|" -i src/Niv/GitHub.hs
|
||||||
'';
|
'';
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user