refactor cloning cntd.
This commit is contained in:
parent
61ca7e7839
commit
ae389aa144
@ -51,7 +51,7 @@ postCreateChallengeR = do
|
|||||||
|
|
||||||
doCreateChallenge :: Text -> Text -> Text -> Text -> Text -> Channel -> Handler ()
|
doCreateChallenge :: Text -> Text -> Text -> Text -> Text -> Channel -> Handler ()
|
||||||
doCreateChallenge name publicUrl publicBranch privateUrl privateBranch chan = do
|
doCreateChallenge name publicUrl publicBranch privateUrl privateBranch chan = do
|
||||||
maybePublicRepoId <- cloneRepo (RepoSpec {
|
maybePublicRepoId <- cloneRepo (RepoCloningSpec {
|
||||||
repoSpecUrl = publicUrl,
|
repoSpecUrl = publicUrl,
|
||||||
repoSpecBranch = publicBranch,
|
repoSpecBranch = publicBranch,
|
||||||
repoSpecReferenceUrl = publicUrl,
|
repoSpecReferenceUrl = publicUrl,
|
||||||
@ -60,7 +60,7 @@ doCreateChallenge name publicUrl publicBranch privateUrl privateBranch chan = do
|
|||||||
Just publicRepoId -> do
|
Just publicRepoId -> do
|
||||||
publicRepo <- runDB $ get404 publicRepoId
|
publicRepo <- runDB $ get404 publicRepoId
|
||||||
publicRepoDir <- getRepoDir publicRepoId
|
publicRepoDir <- getRepoDir publicRepoId
|
||||||
maybePrivateRepoId <- cloneRepo (RepoSpec {
|
maybePrivateRepoId <- cloneRepo (RepoCloningSpec {
|
||||||
repoSpecUrl = privateUrl,
|
repoSpecUrl = privateUrl,
|
||||||
repoSpecBranch = privateBranch,
|
repoSpecBranch = privateBranch,
|
||||||
repoSpecReferenceUrl =(T.pack $ publicRepoDir),
|
repoSpecReferenceUrl =(T.pack $ publicRepoDir),
|
||||||
|
@ -122,7 +122,7 @@ validGitProtocols = ["git", "http", "https", "ssh"]
|
|||||||
validGitProtocolsAsText :: Text
|
validGitProtocolsAsText :: Text
|
||||||
validGitProtocolsAsText = T.pack $ intercalate ", " $ map (++"://") validGitProtocols
|
validGitProtocolsAsText = T.pack $ intercalate ", " $ map (++"://") validGitProtocols
|
||||||
|
|
||||||
data RepoSpec = RepoSpec {
|
data RepoCloningSpec = RepoCloningSpec {
|
||||||
repoSpecUrl :: Text,
|
repoSpecUrl :: Text,
|
||||||
repoSpecBranch :: Text,
|
repoSpecBranch :: Text,
|
||||||
|
|
||||||
@ -130,8 +130,7 @@ data RepoSpec = RepoSpec {
|
|||||||
repoSpecReferenceBranch :: Text
|
repoSpecReferenceBranch :: Text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cloneRepo :: RepoCloningSpec -> Channel -> Handler (Maybe (Key Repo))
|
||||||
cloneRepo :: RepoSpec -> Channel -> Handler (Maybe (Key Repo))
|
|
||||||
cloneRepo repoSpec chan = do
|
cloneRepo repoSpec chan = do
|
||||||
let url = repoSpecUrl repoSpec
|
let url = repoSpecUrl repoSpec
|
||||||
let branch = repoSpecBranch repoSpec
|
let branch = repoSpecBranch repoSpec
|
||||||
@ -187,7 +186,7 @@ getLastCommitMessage repoDir chan = do
|
|||||||
ExitSuccess -> Just out
|
ExitSuccess -> Just out
|
||||||
ExitFailure _ -> Nothing
|
ExitFailure _ -> Nothing
|
||||||
|
|
||||||
cloneRepo' :: RepoSpec -> Channel -> Handler (Maybe (Key Repo))
|
cloneRepo' :: RepoCloningSpec -> Channel -> Handler (Maybe (Key Repo))
|
||||||
cloneRepo' repoSpec chan = do
|
cloneRepo' repoSpec chan = do
|
||||||
let url = repoSpecUrl repoSpec
|
let url = repoSpecUrl repoSpec
|
||||||
msg chan $ concat ["Preparing to clone repo ", url]
|
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]
|
err chan $ concat ["Wrong URL to a Git repo (note that one of the following protocols must be specified: ", validGitProtocolsAsText]
|
||||||
return Nothing
|
return Nothing
|
||||||
|
|
||||||
rawClone :: FilePath -> RepoSpec -> Channel -> Handler (ExitCode)
|
rawClone :: FilePath -> RepoCloningSpec -> Channel -> Handler (ExitCode)
|
||||||
rawClone tmpRepoDir repoSpec chan = do
|
rawClone tmpRepoDir repoSpec chan = do
|
||||||
let url = repoSpecUrl repoSpec
|
let url = repoSpecUrl repoSpec
|
||||||
let branch = repoSpecBranch repoSpec
|
let branch = repoSpecBranch repoSpec
|
||||||
|
@ -333,7 +333,7 @@ getSubmissionRepo challengeId url branch chan = do
|
|||||||
let repoId = challengePublicRepo challenge
|
let repoId = challengePublicRepo challenge
|
||||||
repo <- runDB $ get404 repoId
|
repo <- runDB $ get404 repoId
|
||||||
repoDir <- getRepoDir repoId
|
repoDir <- getRepoDir repoId
|
||||||
let repoSpec = RepoSpec {
|
let repoSpec = RepoCloningSpec {
|
||||||
repoSpecUrl = url,
|
repoSpecUrl = url,
|
||||||
repoSpecBranch = branch,
|
repoSpecBranch = branch,
|
||||||
repoSpecReferenceUrl = (T.pack repoDir),
|
repoSpecReferenceUrl = (T.pack repoDir),
|
||||||
|
Loading…
Reference in New Issue
Block a user