on master help sign in
work on autodetecting private repos, not building
commit551cb89a1bd6ea6ce987e7071b2d3a0071af6f05 authorE Cardenas <card@obsidian.systems> dateThu 2 Jan 2020, 20:09 (7 years ago) parent528ef0b
1 file changed+14−8
lib/command/src/Obelisk/Command/Thunk.hs+14−8
lib/command/src/Obelisk/Command/Thunk.hs+14−8
@@ -188,6 +188,7 @@ getNixSha256ForUriUnpacked
188188 => GitUri
189189 -> m NixSha256
190190getNixSha256ForUriUnpacked uri =
191+ --FIXME: this should be curled instead, and then added to the nix store
191192 withExitFailMessage ("nix-prefetch-url: Failed to determine sha256 hash of URL " <> gitUriToText uri) $ do
192193 [hash] <- fmap T.lines $ readProcessAndLogOutput (Debug, Debug) $
193194 proc "nix-prefetch-url" ["--unpack", "--type", "sha256", T.unpack $ gitUriToText uri]
@@ -851,9 +852,9 @@ getLatestRev os = do
851852uriThunkPtr :: MonadObelisk m => GitUri -> Maybe Text -> Maybe Text -> m ThunkPtr
852853uriThunkPtr uri mbranch mcommit = do
853854 commit <- case mcommit of
854− Nothing -> gitGetCommitBranch uri mbranch >>= return . snd
855+ Nothing -> gitGetCommitBranch uri mbranch >>= return . snd --perhaps do io here instead of making uriToTHunkSource effectful ?
855856 (Just c) -> return c
856− (src, rev) <- case uriToThunkSource uri mbranch of
857+ (src, rev) <- uriToThunkSource uri mbranch >>= \case
857858 ThunkSource_GitHub s -> do
858859 rev <- runExceptT $ githubThunkRev s commit
859860 case rev of
@@ -862,6 +863,7 @@ uriThunkPtr uri mbranch mcommit = do
862863 putLog Warning "\
863864\Failed to fetch archive from GitHub. This is probably a private repo. \
864865\Falling back on normal fetchgit. Original failure:"
866+ --FIXME: right here is where we want to add the error handling
865867 errorToWarning e
866868 let s' = forgetGithub True s
867869 (,) (ThunkSource_Git s') <$> gitThunkRev s' commit
@@ -876,7 +878,7 @@ uriThunkPtr uri mbranch mcommit = do
876878-- If the thunk is a GitHub thunk and fails, we do *not* fall back like with
877879-- `uriThunkPtr`. Unlike a plain URL, a thunk src explicitly states which method
878880-- should be employed, and so we respect that.
879−uriToThunkSource :: GitUri -> Maybe Text -> ThunkSource
881+uriToThunkSource :: MonadObelisk m => GitUri -> Maybe Text -> m ThunkSource
880882uriToThunkSource (GitUri u)
881883 | Right uriAuth <- URI.uriAuthority u
882884 , Just scheme <- URI.unRText <$> URI.uriScheme u
@@ -889,7 +891,7 @@ uriToThunkSource (GitUri u)
889891 s -> s `L.elem` [ "git", "https", "http" ] -- "http:" just redirects to "https:"
890892 && URI.unRText (URI.authHost uriAuth) == "github.com"
891893 , Just (_, owner :| [repoish]) <- URI.uriPath u
892− = \mbranch -> ThunkSource_GitHub $ GitHubSource
894+ = \mbranch -> pure . ThunkSource_GitHub $ GitHubSource
893895 { _gitHubSource_owner = N $ URI.unRText owner
894896 , _gitHubSource_repo = N $ let
895897 repoish' = URI.unRText repoish
@@ -898,7 +900,7 @@ uriToThunkSource (GitUri u)
898900 , _gitHubSource_private = False -- TODO: Can we try something to infer this?
899901 }
900902
901− | otherwise = \mbranch -> ThunkSource_Git $ GitSource
903+ | otherwise = \mbranch -> pure . ThunkSource_Git $ GitSource
902904 { _gitSource_url = GitUri u
903905 , _gitSource_branch = N <$> mbranch
904906 , _gitSource_fetchSubmodules = False -- TODO: How do we determine if this should be true?
@@ -963,13 +965,17 @@ gitThunkRev s commit = do
963965--
964966-- If the branch name is passed in, it is returned exactly as-is. If it is not
965967-- passed it, the default branch of the repo is used instead.
966−gitGetCommitBranch
967− :: MonadObelisk m => GitUri -> Maybe Text -> m (Text, CommitId)
968+
969+gitGetCommitBranch --FIXME:definitely encode the check to see if repo exists here
970+ :: MonadObelisk m => GitUri -> Maybe Text -> m (Text, CommitId, Bool)
968971gitGetCommitBranch uri mbranch = withExitFailMessage ("Failure for git remote " <> uriMsg) $ do
969972 (_, bothMaps) <- gitLsRemote
970973 (T.unpack $ gitUriToText uri)
971974 (GitRef_Branch <$> mbranch)
972975 Nothing
976+ unAuthenticatedExitCode <-
977+ readCreateProcessWithExitCode . isolateGitProc . gitProcNoRepo $
978+ ["ls-remote", "--exit-code", "--symref", repository]
973979 branch <- case mbranch of
974980 Nothing -> withExitFailMessage "Failed to find default branch" $ do
975981 b <- rethrowE $ gitLookupDefaultBranch bothMaps
@@ -980,7 +986,7 @@ gitGetCommitBranch uri mbranch = withExitFailMessage ("Failure for git remote "
980986 putLog Informational $ "Latest commit in branch " <> branch
981987 <> " from remote repo " <> uriMsg
982988 <> " is " <> commit
983− pure (branch, commit)
989+ pure (branch, commit )-- , exitCode == ExitSuccess)
984990 where
985991 rethrowE = either failWith pure
986992 uriMsg = gitUriToText uri