diff --git a/Handler/Common.hs b/Handler/Common.hs index 4e584eb..d9538e9 100644 --- a/Handler/Common.hs +++ b/Handler/Common.hs @@ -7,6 +7,8 @@ import Import import Crypto.PasswordStore import Yesod.Auth.HashDB (defaultStrength) +import qualified Data.Text as T + -- These handlers embed files in the executable at compile time to avoid a -- runtime dependency, and for efficiency. @@ -67,3 +69,9 @@ checkIfCanEdit submissionId = do checkIfAdmin :: Maybe (Entity User) -> Bool checkIfAdmin (Just (Entity _ user)) = userIsAdmin user checkIfAdmin Nothing = False + +encodeSlash :: T.Text -> T.Text +encodeSlash = T.replace "/" "SLASH" + +decodeSlash :: T.Text -> T.Text +decodeSlash = T.replace "SLASH" "/" diff --git a/Handler/ShowChallenge.hs b/Handler/ShowChallenge.hs index 80ac76b..df53cde 100644 --- a/Handler/ShowChallenge.hs +++ b/Handler/ShowChallenge.hs @@ -186,6 +186,7 @@ getChallengeHowToR name = do (idToBeShown challenge maybeUser) isIDSet isSSHUploaded + (join $ userAltRepoScheme <$> entityVal <$> maybeUser) mToken) idToBeShown :: p -> Maybe (Entity User) -> Text @@ -205,11 +206,12 @@ defaultBranch :: IsString a => RepoScheme -> Maybe a defaultBranch SelfHosted = Just "master" defaultBranch Branches = Nothing -challengeHowTo :: (Text.Blaze.ToMarkup a1, Text.Blaze.ToMarkup a2) => Challenge -> AppSettings -> Repo -> a1 -> Bool -> Bool -> Maybe a2 -> WidgetFor App () -challengeHowTo challenge settings repo shownId isIDSet isSSHUploaded mToken = $(widgetFile "challenge-how-to") - where myBranch = case appRepoScheme settings of - SelfHosted -> "master" :: Text - _ -> "my-brilliant-branch" +challengeHowTo :: Challenge -> AppSettings -> Repo -> Text -> Bool -> Bool -> Maybe Text -> Maybe Text -> WidgetFor App () +challengeHowTo challenge settings repo shownId isIDSet isSSHUploaded mAltRepoScheme mToken = $(widgetFile "challenge-how-to") + where myBranch = "my-brilliant-branch" :: Text + urlToYourRepo = case mAltRepoScheme of + Just altRepoScheme -> encodeSlash (altRepoScheme <> (challengeName challenge)) + Nothing -> "URL_TO_YOUR_REPO" postArchiveR :: ChallengeId -> Handler Html postArchiveR challengeId = doSetArchive True challengeId @@ -280,11 +282,11 @@ postTriggerRemotelyR = do postTriggerRemotelySimpleR :: Text -> Text -> Text -> Text -> Handler TypedContent postTriggerRemotelySimpleR token challengeName url branch = - doTrigger token challengeName url (Just branch) Nothing + doTrigger token challengeName (decodeSlash url) (Just branch) Nothing getTriggerRemotelySimpleR :: Text -> Text -> Text -> Text -> Handler TypedContent getTriggerRemotelySimpleR token challengeName url branch = - doTrigger token challengeName url (Just branch) Nothing + doTrigger token challengeName (decodeSlash url) (Just branch) Nothing doTrigger :: Text -> Text -> Text -> Maybe Text -> Maybe Text -> Handler TypedContent doTrigger token challengeName url mBranch mGitAnnexRemote = do diff --git a/templates/challenge-how-to.hamlet b/templates/challenge-how-to.hamlet index f894f52..3726a4a 100644 --- a/templates/challenge-how-to.hamlet +++ b/templates/challenge-how-to.hamlet @@ -35,7 +35,7 @@ $case (appRepoScheme settings) $of SelfHosted - $if not isIDSet || not isSSHUploaded + $if (not isIDSet || not isSSHUploaded) && isNothing mAltRepoScheme

You need to $if not isIDSet \ set up your ID @@ -45,10 +45,15 @@ $case (appRepoScheme settings) \ upload your SSH public key \ (see your account) if you want to have a repo hosted on Gonito.net, then: -

-    git clone --single-branch #{appRepoHost settings}#{shownId}/#{challengeName challenge}
+  $maybe altRepoScheme <- mAltRepoScheme
+    

(Depending on your setup, you might need to create the repo at your git server first.) +

+      git clone #{altRepoScheme}#{challengeName challenge}
+  $nothing
+    
+      git clone --single-branch #{appRepoHost settings}#{shownId}/#{challengeName challenge}
 
-  

(Warning about empty repository is expected, don't worry about it.) +

(Warning about empty repository is expected, don't worry about it.)

     cd #{challengeName challenge}
@@ -57,13 +62,14 @@ $case (appRepoScheme settings)
   

Using an external repository $maybe serverPubKey <- (appServerSSHPublicKey settings) -

Alternatively, you can use any other Git repo, e.g. GitLab, GitHub or your own repo, make sure Gonito.net has access to your repo, either by making it public or giving read access to the SSH public key: -

-      #{serverPubKey}
+    $if isNothing mAltRepoScheme
+      

Alternatively, you can use any other Git repo, e.g. GitLab, GitHub or your own repo, make sure Gonito.net has access to your repo, either by making it public or giving read access to the SSH public key: + $else +

+        #{serverPubKey}
   $nothing
-    

Alternatively, you can use any other Git repo, e.g. GitLab, GitHub or your own repo, make sure Gonito.net has access to your repo. - -

(And initiate it with #{appRepoHost settings}#{challengeName challenge}.) + $if isNothing mAltRepoScheme +

Alternatively, you can use any other Git repo, e.g. GitLab, GitHub or your own repo, make sure Gonito.net has access to your repo. $of Branches

Clone the repo: @@ -77,14 +83,9 @@ $case (appRepoScheme settings) git annex initremote storage #{gitAnnexRemote} git annex get --from storage -

Switch to some branch, let's say my-brilliant-solution: - -

-      git checkout -b my-brilliant-solution
-
 

Work on your solution -

You need to generate your solution for the test set as test-A/out.tsv. You may also generate the solution for the dev set (dev-0/out.tsv). +

You need to generate your solution for the test set as test-A/out.tsv. It is also recommended to generate the output for the dev set (dev-0/out.tsv).

You can evaluate results for the dev set locally: @@ -98,7 +99,9 @@ $case (appRepoScheme settings)

   cd #{challengeName challenge}
+  git checkout -b #{myBranch}  # switch to some other branch
   git add foo.py build.sh # add your source codes
+  git add gonito.yaml # it's a good practice to add metadata file, see below
 
 $if isJust (repoGitAnnexRemote repo)
   
@@ -117,12 +120,12 @@ $else
 $case (appRepoScheme settings)
   $of SelfHosted
     
-      git push origin master
+      git push origin #{myBranch}
     

Repos hosted on Gonito.net

If you use a repo hosted here, a submission and evaluation is triggered automatically. You'll see the evaluation results in your console while pushing. $of Branches

-      git push origin my-brilliant-solution:my-brilliant-solution
+      git push origin #{myBranch}
 
 

External repos @@ -130,10 +133,10 @@ $case (appRepoScheme settings) $maybe token <- mToken

Your webook is:

-     wget --timeout=0 --quiet -O - '#{appRoot settings}/trigger-remotely' --post-data 'token=#{token}&branch=#{myBranch}&challenge=#{challengeName challenge}&url=URL_TO_YOUR_REPO'
+     wget --timeout=0 --quiet -O - '#{appRoot settings}/trigger-remotely' --post-data 'token=#{token}&branch=#{myBranch}&challenge=#{challengeName challenge}&url=#{urlToYourRepo}'
    

or you can just use the following URL:

-     #{appRoot settings}/trigger-remotely-simple/#{token}/#{challengeName challenge}/URL_TO_YOUR_REPO/#{myBranch}
+     #{appRoot settings}/trigger-remotely-simple/#{token}/#{challengeName challenge}/#{urlToYourRepo}/#{myBranch}
 
 

Manual submission