refactor cloning cntd.

This commit is contained in:
Filip Gralinski 2018-06-04 21:58:05 +02:00
parent 61ca7e7839
commit ae389aa144
3 changed files with 7 additions and 8 deletions

View File

@ -51,7 +51,7 @@ postCreateChallengeR = do
doCreateChallenge :: Text -> Text -> Text -> Text -> Text -> Channel -> Handler ()
doCreateChallenge name publicUrl publicBranch privateUrl privateBranch chan = do
maybePublicRepoId <- cloneRepo (RepoSpec {
maybePublicRepoId <- cloneRepo (RepoCloningSpec {
repoSpecUrl = publicUrl,
repoSpecBranch = publicBranch,
repoSpecReferenceUrl = publicUrl,
@ -60,7 +60,7 @@ doCreateChallenge name publicUrl publicBranch privateUrl privateBranch chan = do
Just publicRepoId -> do
publicRepo <- runDB $ get404 publicRepoId
publicRepoDir <- getRepoDir publicRepoId
maybePrivateRepoId <- cloneRepo (RepoSpec {
maybePrivateRepoId <- cloneRepo (RepoCloningSpec {
repoSpecUrl = privateUrl,
repoSpecBranch = privateBranch,
repoSpecReferenceUrl =(T.pack $ publicRepoDir),

View File

@ -122,7 +122,7 @@ validGitProtocols = ["git", "http", "https", "ssh"]
validGitProtocolsAsText :: Text
validGitProtocolsAsText = T.pack $ intercalate ", " $ map (++"://") validGitProtocols
data RepoSpec = RepoSpec {
data RepoCloningSpec = RepoCloningSpec {
repoSpecUrl :: Text,
repoSpecBranch :: Text,
@ -130,8 +130,7 @@ data RepoSpec = RepoSpec {
repoSpecReferenceBranch :: Text
}
cloneRepo :: RepoSpec -> Channel -> Handler (Maybe (Key Repo))
cloneRepo :: RepoCloningSpec -> Channel -> Handler (Maybe (Key Repo))
cloneRepo repoSpec chan = do
let url = repoSpecUrl repoSpec
let branch = repoSpecBranch repoSpec
@ -187,7 +186,7 @@ getLastCommitMessage repoDir chan = do
ExitSuccess -> Just out
ExitFailure _ -> Nothing
cloneRepo' :: RepoSpec -> Channel -> Handler (Maybe (Key Repo))
cloneRepo' :: RepoCloningSpec -> Channel -> Handler (Maybe (Key Repo))
cloneRepo' repoSpec chan = do
let url = repoSpecUrl repoSpec
msg chan $ concat ["Preparing to clone repo ", url]
@ -225,7 +224,7 @@ cloneRepo' repoSpec chan = do
err chan $ concat ["Wrong URL to a Git repo (note that one of the following protocols must be specified: ", validGitProtocolsAsText]
return Nothing
rawClone :: FilePath -> RepoSpec -> Channel -> Handler (ExitCode)
rawClone :: FilePath -> RepoCloningSpec -> Channel -> Handler (ExitCode)
rawClone tmpRepoDir repoSpec chan = do
let url = repoSpecUrl repoSpec
let branch = repoSpecBranch repoSpec

View File

@ -333,7 +333,7 @@ getSubmissionRepo challengeId url branch chan = do
let repoId = challengePublicRepo challenge
repo <- runDB $ get404 repoId
repoDir <- getRepoDir repoId
let repoSpec = RepoSpec {
let repoSpec = RepoCloningSpec {
repoSpecUrl = url,
repoSpecBranch = branch,
repoSpecReferenceUrl = (T.pack repoDir),