From f1502c16e4d6d60a24ed7626e67a5896f9ca2f99 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Tue, 5 Jun 2018 07:46:42 +0200 Subject: [PATCH] start handling git-annex remote --- Handler/CreateChallenge.hs | 27 +++++++++++++++++---------- Handler/Shared.hs | 4 +++- config/models | 1 + messages/en.msg | 1 + 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Handler/CreateChallenge.hs b/Handler/CreateChallenge.hs index 931fbf6..db73cfe 100644 --- a/Handler/CreateChallenge.hs +++ b/Handler/CreateChallenge.hs @@ -39,25 +39,28 @@ postCreateChallengeR = do challengeData = case result of FormSuccess res -> Just res _ -> Nothing - Just (name, publicUrl, publicBranch, privateUrl, privateBranch) = challengeData + Just (name, publicUrl, publicBranch, publicGitAnnexRemote, + privateUrl, privateBranch, privateGitAnnexRemote) = challengeData userId <- requireAuthId user <- runDB $ get404 userId if userIsAdmin user then - runViewProgress $ doCreateChallenge name publicUrl publicBranch privateUrl privateBranch + runViewProgress $ doCreateChallenge name publicUrl publicBranch publicGitAnnexRemote privateUrl privateBranch privateGitAnnexRemote else runViewProgress $ (flip err) "MUST BE AN ADMIN TO CREATE A CHALLENGE" -doCreateChallenge :: Text -> Text -> Text -> Text -> Text -> Channel -> Handler () -doCreateChallenge name publicUrl publicBranch privateUrl privateBranch chan = do +doCreateChallenge :: Text -> Text -> Text -> Maybe Text -> Text -> Text -> Maybe Text -> Channel -> Handler () +doCreateChallenge name publicUrl publicBranch publicGitAnnexRemote privateUrl privateBranch privateGitAnnexRemote chan = do maybePublicRepoId <- cloneRepo (RepoCloningSpec { cloningSpecRepo = RepoSpec { repoSpecUrl = publicUrl, - repoSpecBranch = publicBranch }, + repoSpecBranch = publicBranch, + repoSpecGitAnnexRemote = publicGitAnnexRemote}, cloningSpecReferenceRepo = RepoSpec { repoSpecUrl = publicUrl, - repoSpecBranch = publicBranch}}) chan + repoSpecBranch = publicBranch, + repoSpecGitAnnexRemote = publicGitAnnexRemote}}) chan case maybePublicRepoId of Just publicRepoId -> do publicRepo <- runDB $ get404 publicRepoId @@ -65,10 +68,12 @@ doCreateChallenge name publicUrl publicBranch privateUrl privateBranch chan = do maybePrivateRepoId <- cloneRepo (RepoCloningSpec { cloningSpecRepo = RepoSpec { repoSpecUrl = privateUrl, - repoSpecBranch = privateBranch }, + repoSpecBranch = privateBranch, + repoSpecGitAnnexRemote = privateGitAnnexRemote}, cloningSpecReferenceRepo = RepoSpec { repoSpecUrl =(T.pack $ publicRepoDir), - repoSpecBranch = (repoBranch publicRepo)}}) chan + repoSpecBranch = (repoBranch publicRepo), + repoSpecGitAnnexRemote = (repoGitAnnexRemote publicRepo)}}) chan case maybePrivateRepoId of Just privateRepoId -> addChallenge name publicRepoId privateRepoId chan Nothing -> return () @@ -174,10 +179,12 @@ never = depth ==? 0 testDirFilter :: FindClause Bool testDirFilter = (fileType ==? Directory) &&? (SFF.fileName ~~? "dev-*" ||? SFF.fileName ~~? "test-*") -sampleForm :: Form (Text, Text, Text, Text, Text) -sampleForm = renderBootstrap3 BootstrapBasicForm $ (,,,,) +sampleForm :: Form (Text, Text, Text, Maybe Text, Text, Text, Maybe Text) +sampleForm = renderBootstrap3 BootstrapBasicForm $ (,,,,,,) <$> areq textField (fieldSettingsLabel MsgName) Nothing <*> areq textField (fieldSettingsLabel MsgPublicUrl) Nothing <*> areq textField (fieldSettingsLabel MsgBranch) Nothing + <*> aopt textField (fieldSettingsLabel MsgGitAnnexRemote) Nothing <*> areq textField (fieldSettingsLabel MsgPrivateUrl) Nothing <*> areq textField (fieldSettingsLabel MsgBranch) Nothing + <*> aopt textField (fieldSettingsLabel MsgGitAnnexRemote) Nothing diff --git a/Handler/Shared.hs b/Handler/Shared.hs index 09dbde4..904f01f 100644 --- a/Handler/Shared.hs +++ b/Handler/Shared.hs @@ -129,7 +129,8 @@ data RepoCloningSpec = RepoCloningSpec { data RepoSpec = RepoSpec { repoSpecUrl :: Text, - repoSpecBranch :: Text + repoSpecBranch :: Text, + repoSpecGitAnnexRemote :: Maybe Text } cloneRepo :: RepoCloningSpec -> Channel -> Handler (Maybe (Key Repo)) @@ -209,6 +210,7 @@ cloneRepo' repoCloningSpec chan = do repoId <- runDB $ insert $ Repo { repoUrl=url, repoBranch=repoSpecBranch $ cloningSpecRepo repoCloningSpec, + repoGitAnnexRemote=repoSpecGitAnnexRemote $ cloningSpecRepo repoCloningSpec, repoCurrentCommit=commitRaw, repoOwner=userId, repoReady=True, diff --git a/config/models b/config/models index 9da1e08..b7b267a 100644 --- a/config/models +++ b/config/models @@ -26,6 +26,7 @@ Repo owner UserId ready Bool default=False stamp UTCTime default=now() + gitAnnexRemote Text Maybe UniqueUrlBranch url branch deriving Show Challenge diff --git a/messages/en.msg b/messages/en.msg index d60b90c..3891e8e 100644 --- a/messages/en.msg +++ b/messages/en.msg @@ -58,3 +58,4 @@ User: User Manage: manage Presentation: presentation GonitoInClass: Gonito in class +GitAnnexRemote: git-annex remote (if needed)