diff --git a/Handler/CreateChallenge.hs b/Handler/CreateChallenge.hs index bdede88..c3eb83a 100644 --- a/Handler/CreateChallenge.hs +++ b/Handler/CreateChallenge.hs @@ -89,6 +89,18 @@ doCreateChallenge name publicUrl publicBranch publicGitAnnexRemote privateUrl pr Nothing -> return () Nothing -> return () +defaultMajorVersion :: Int +defaultMajorVersion = 1 + +defaultMinorVersion :: Int +defaultMinorVersion = 0 + +defaultPatchVersion :: Int +defaultPatchVersion = 0 + +defaultInitialDescription :: Text +defaultInitialDescription = "initial version" + addChallenge :: Text -> (Key Repo) -> (Key Repo) -> Channel -> Handler () addChallenge name publicRepoId privateRepoId chan = do msg chan "adding challenge..." @@ -111,7 +123,19 @@ addChallenge name publicRepoId privateRepoId chan = do else do return Nothing + privateRepo <- runDB $ get404 privateRepoId time <- liftIO getCurrentTime + + let commit=repoCurrentCommit $ privateRepo + + _ <- runDB $ insert $ Version { + versionCommit=commit, + versionMajor=defaultMajorVersion, + versionMinor=defaultMinorVersion, + versionPatch=defaultPatchVersion, + versionDescription=defaultInitialDescription, + versionStamp=time} + challengeId <- runDB $ insert $ Challenge { challengePublicRepo=publicRepoId, challengePrivateRepo=privateRepoId, @@ -121,8 +145,11 @@ addChallenge name publicRepoId privateRepoId chan = do challengeStamp=time, challengeImage=mImage, challengeStarred=False, - challengeArchived=Just False} + challengeArchived=Just False, + challengeVersion=Just commit} + updateTests challengeId chan + return () updateTests :: (Key Challenge) -> Channel -> Handler () diff --git a/Handler/ShowChallenge.hs b/Handler/ShowChallenge.hs index d0d1706..f4558b0 100644 --- a/Handler/ShowChallenge.hs +++ b/Handler/ShowChallenge.hs @@ -441,6 +441,7 @@ getScoreForOut mainTestId out = do getSubmission :: UserId -> Key Repo -> SHA1 -> Key Challenge -> Text -> Channel -> Handler (Key Submission) getSubmission userId repoId commit challengeId description chan = do + challenge <- runDB $ get404 challengeId maybeSubmission <- runDB $ getBy $ UniqueSubmissionRepoCommitChallenge repoId commit challengeId case maybeSubmission of Just (Entity submissionId _) -> do @@ -457,7 +458,8 @@ getSubmission userId repoId commit challengeId description chan = do submissionStamp=time, submissionSubmitter=userId, submissionIsPublic=False, - submissionIsHidden=False } + submissionIsHidden=False, + submissionVersion=challengeVersion challenge} getOuts :: Channel -> Key Submission -> M.Map Text Text -> Handler ([Out]) getOuts chan submissionId generalParams = do diff --git a/add-versions.sql b/add-versions.sql new file mode 100644 index 0000000..afe55fb --- /dev/null +++ b/add-versions.sql @@ -0,0 +1,6 @@ + +/*insert into version("commit", major, minor, patch, description) select R.current_commit, 1, 0, 0, 'taken over' from challenge C, repo R where C.private_repo = R.id ; + +update challenge set version = (select R.current_commit from repo R where private_repo = R.id);*/ + +update submission set version = (select R.current_commit from repo R, challenge C where C.private_repo = R.id and challenge = C.id); diff --git a/config/models b/config/models index 88ae1e5..2462ba0 100644 --- a/config/models +++ b/config/models @@ -40,6 +40,16 @@ Challenge image ByteString Maybe starred Bool archived Bool Maybe + version SHA1 Maybe +-- challenge version +Version + commit SHA1 + major Int + minor Int + patch Int + UniqueVersion commit major minor patch + description Text + stamp UTCTime default=now() Test challenge ChallengeId metric EvaluationScheme @@ -59,6 +69,8 @@ Submission submitter UserId isPublic Bool default=False isHidden Bool default=False + -- challenge version present when the submission was done + version SHA1 Maybe UniqueSubmissionRepoCommitChallenge repo commit challenge Variant submission SubmissionId