Finish handling alternative repo schemes

This commit is contained in:
Filip Gralinski 2020-02-22 09:12:13 +01:00
parent 7560d3ca17
commit 5398783636
3 changed files with 40 additions and 27 deletions

View File

@ -7,6 +7,8 @@ import Import
import Crypto.PasswordStore import Crypto.PasswordStore
import Yesod.Auth.HashDB (defaultStrength) import Yesod.Auth.HashDB (defaultStrength)
import qualified Data.Text as T
-- These handlers embed files in the executable at compile time to avoid a -- These handlers embed files in the executable at compile time to avoid a
-- runtime dependency, and for efficiency. -- runtime dependency, and for efficiency.
@ -67,3 +69,9 @@ checkIfCanEdit submissionId = do
checkIfAdmin :: Maybe (Entity User) -> Bool checkIfAdmin :: Maybe (Entity User) -> Bool
checkIfAdmin (Just (Entity _ user)) = userIsAdmin user checkIfAdmin (Just (Entity _ user)) = userIsAdmin user
checkIfAdmin Nothing = False checkIfAdmin Nothing = False
encodeSlash :: T.Text -> T.Text
encodeSlash = T.replace "/" "SLASH"
decodeSlash :: T.Text -> T.Text
decodeSlash = T.replace "SLASH" "/"

View File

@ -186,6 +186,7 @@ getChallengeHowToR name = do
(idToBeShown challenge maybeUser) (idToBeShown challenge maybeUser)
isIDSet isIDSet
isSSHUploaded isSSHUploaded
(join $ userAltRepoScheme <$> entityVal <$> maybeUser)
mToken) mToken)
idToBeShown :: p -> Maybe (Entity User) -> Text idToBeShown :: p -> Maybe (Entity User) -> Text
@ -205,11 +206,12 @@ defaultBranch :: IsString a => RepoScheme -> Maybe a
defaultBranch SelfHosted = Just "master" defaultBranch SelfHosted = Just "master"
defaultBranch Branches = Nothing defaultBranch Branches = Nothing
challengeHowTo :: (Text.Blaze.ToMarkup a1, Text.Blaze.ToMarkup a2) => Challenge -> AppSettings -> Repo -> a1 -> Bool -> Bool -> Maybe a2 -> WidgetFor App () challengeHowTo :: Challenge -> AppSettings -> Repo -> Text -> Bool -> Bool -> Maybe Text -> Maybe Text -> WidgetFor App ()
challengeHowTo challenge settings repo shownId isIDSet isSSHUploaded mToken = $(widgetFile "challenge-how-to") challengeHowTo challenge settings repo shownId isIDSet isSSHUploaded mAltRepoScheme mToken = $(widgetFile "challenge-how-to")
where myBranch = case appRepoScheme settings of where myBranch = "my-brilliant-branch" :: Text
SelfHosted -> "master" :: Text urlToYourRepo = case mAltRepoScheme of
_ -> "my-brilliant-branch" Just altRepoScheme -> encodeSlash (altRepoScheme <> (challengeName challenge))
Nothing -> "URL_TO_YOUR_REPO"
postArchiveR :: ChallengeId -> Handler Html postArchiveR :: ChallengeId -> Handler Html
postArchiveR challengeId = doSetArchive True challengeId postArchiveR challengeId = doSetArchive True challengeId
@ -280,11 +282,11 @@ postTriggerRemotelyR = do
postTriggerRemotelySimpleR :: Text -> Text -> Text -> Text -> Handler TypedContent postTriggerRemotelySimpleR :: Text -> Text -> Text -> Text -> Handler TypedContent
postTriggerRemotelySimpleR token challengeName url branch = 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 :: Text -> Text -> Text -> Text -> Handler TypedContent
getTriggerRemotelySimpleR token challengeName url branch = 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 :: Text -> Text -> Text -> Maybe Text -> Maybe Text -> Handler TypedContent
doTrigger token challengeName url mBranch mGitAnnexRemote = do doTrigger token challengeName url mBranch mGitAnnexRemote = do

View File

@ -35,7 +35,7 @@
$case (appRepoScheme settings) $case (appRepoScheme settings)
$of SelfHosted $of SelfHosted
$if not isIDSet || not isSSHUploaded $if (not isIDSet || not isSSHUploaded) && isNothing mAltRepoScheme
<p>You need to <p>You need to
$if not isIDSet $if not isIDSet
\ set up your ID \ set up your ID
@ -45,6 +45,11 @@ $case (appRepoScheme settings)
\ upload your SSH public key \ upload your SSH public key
\ (see <a href="@{YourAccountR}">your account</a>) if you want to have a repo hosted on Gonito.net, then: \ (see <a href="@{YourAccountR}">your account</a>) if you want to have a repo hosted on Gonito.net, then:
$maybe altRepoScheme <- mAltRepoScheme
<p>(Depending on your setup, you might need to create the repo at your git server first.)
<pre>
git clone #{altRepoScheme}#{challengeName challenge}
$nothing
<pre> <pre>
git clone --single-branch #{appRepoHost settings}#{shownId}/#{challengeName challenge} git clone --single-branch #{appRepoHost settings}#{shownId}/#{challengeName challenge}
@ -57,14 +62,15 @@ $case (appRepoScheme settings)
<h4>Using an external repository <h4>Using an external repository
$maybe serverPubKey <- (appServerSSHPublicKey settings) $maybe serverPubKey <- (appServerSSHPublicKey settings)
$if isNothing mAltRepoScheme
<p>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: <p>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
<pre> <pre>
#{serverPubKey} #{serverPubKey}
$nothing $nothing
$if isNothing mAltRepoScheme
<p>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. <p>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.
<p>(And initiate it with #{appRepoHost settings}#{challengeName challenge}.)
$of Branches $of Branches
<p>Clone the repo: <p>Clone the repo:
@ -77,14 +83,9 @@ $case (appRepoScheme settings)
git annex initremote storage #{gitAnnexRemote} git annex initremote storage #{gitAnnexRemote}
git annex get --from storage git annex get --from storage
<p>Switch to some branch, let's say <tt>my-brilliant-solution</tt>:
<pre>
git checkout -b my-brilliant-solution
<h2>Work on your solution <h2>Work on your solution
<p>You need to generate your solution for the test set as <tt>test-A/out.tsv</tt>. You may also generate the solution for the dev set (<tt>dev-0/out.tsv</tt>). <p>You need to generate your solution for the test set as <tt>test-A/out.tsv</tt>. It is also recommended to generate the output for the dev set (<tt>dev-0/out.tsv</tt>).
<p>You can evaluate results for the dev set locally: <p>You can evaluate results for the dev set locally:
@ -98,7 +99,9 @@ $case (appRepoScheme settings)
<pre> <pre>
cd #{challengeName challenge} cd #{challengeName challenge}
git checkout -b #{myBranch} # switch to some other branch
git add foo.py build.sh # add your source codes 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) $if isJust (repoGitAnnexRemote repo)
<pre> <pre>
@ -117,12 +120,12 @@ $else
$case (appRepoScheme settings) $case (appRepoScheme settings)
$of SelfHosted $of SelfHosted
<pre> <pre>
git push origin master git push origin #{myBranch}
<h3>Repos hosted on Gonito.net <h3>Repos hosted on Gonito.net
<p>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. <p>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 $of Branches
<pre> <pre>
git push origin my-brilliant-solution:my-brilliant-solution git push origin #{myBranch}
<h3>External repos <h3>External repos
@ -130,10 +133,10 @@ $case (appRepoScheme settings)
$maybe token <- mToken $maybe token <- mToken
<p>Your webook is: <p>Your webook is:
<pre> <pre>
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}'
<p>or you can just use the following URL: <p>or you can just use the following URL:
<pre> <pre>
#{appRoot settings}/trigger-remotely-simple/#{token}/#{challengeName challenge}/URL_TO_YOUR_REPO/#{myBranch} #{appRoot settings}/trigger-remotely-simple/#{token}/#{challengeName challenge}/#{urlToYourRepo}/#{myBranch}
<h3>Manual submission <h3>Manual submission