From 7311a2a0123d7fdab7dada43abc1468413fb77df Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Sat, 5 Sep 2020 11:52:33 +0200 Subject: [PATCH] Minor refactor in cloning code --- Handler/Shared.hs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Handler/Shared.hs b/Handler/Shared.hs index 6d5399a..a2c484f 100644 --- a/Handler/Shared.hs +++ b/Handler/Shared.hs @@ -241,17 +241,22 @@ getPossiblyExistingRepo checkRepo userId challengeId repoSpec chan = do } cloneRepo' userId repoCloningSpec chan +cloneRepoToTempDir :: RepoCloningSpec -> Channel -> Handler (ExitCode, FilePath) +cloneRepoToTempDir repoCloningSpec chan = do + let url = repoSpecUrl $ cloningSpecRepo repoCloningSpec + msg chan $ concat ["Preparing to clone repo ", url] + msg chan "Cloning..." + r <- randomInt + arenaDir <- arena + let tmpRepoDir = arenaDir ("t" ++ show r) + exitCode <- rawClone tmpRepoDir repoCloningSpec chan + return (exitCode, tmpRepoDir) cloneRepo' :: UserId -> RepoCloningSpec -> Channel -> Handler (Maybe (Key Repo)) cloneRepo' userId repoCloningSpec chan = do - let url = repoSpecUrl $ cloningSpecRepo repoCloningSpec - msg chan $ concat ["Preparing to clone repo ", url] - msg chan "Cloning..." - r <- randomInt - arenaDir <- arena - let tmpRepoDir = arenaDir ("t" ++ show r) - exitCode <- rawClone tmpRepoDir repoCloningSpec chan - case exitCode of + let url = repoSpecUrl $ cloningSpecRepo repoCloningSpec + (exitCode, tmpRepoDir) <- cloneRepoToTempDir repoCloningSpec chan + case exitCode of ExitSuccess -> do maybeHeadCommit <- getHeadCommit tmpRepoDir chan case maybeHeadCommit of