From 37125b8326fc63b36aac2399d973d8d1c55e8a1e Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Sat, 3 Nov 2018 17:25:49 +0100 Subject: [PATCH] Sets are used instead of strings for tags --- Gonito/ExtractMetadata.hs | 21 +++++++++++++-------- Handler/ShowChallenge.hs | 7 +++++-- test/Gonito/ExtractMetadataSpec.hs | 2 +- test/fake-git-repos/with-gonito-yaml | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Gonito/ExtractMetadata.hs b/Gonito/ExtractMetadata.hs index e542000..516d37d 100644 --- a/Gonito/ExtractMetadata.hs +++ b/Gonito/ExtractMetadata.hs @@ -30,7 +30,7 @@ import "Glob" System.FilePath.Glob as G data ExtractionOptions = ExtractionOptions { extractionOptionsDescription :: Maybe Text, - extractionOptionsTags :: Maybe Text, + extractionOptionsTags :: Maybe (S.Set Text), extractionOptionsGeneralParams :: Maybe (M.Map Text Text), extractionOptionsUnwantedParams :: Maybe [Text], extractionOptionsParamFiles :: Maybe [String], @@ -74,7 +74,7 @@ combineExtractionOptions :: Maybe ExtractionOptions -> ExtractionOptions -> Extr combineExtractionOptions Nothing options = options combineExtractionOptions (Just otherOptions) options = ExtractionOptions { extractionOptionsDescription = combineWithT extractionOptionsDescription, - extractionOptionsTags = combineWithT extractionOptionsTags, + extractionOptionsTags = combineWithS extractionOptionsTags, extractionOptionsGeneralParams = Just $ (fromMaybe M.empty $ extractionOptionsGeneralParams options) `M.union` (fromMaybe M.empty $ extractionOptionsGeneralParams otherOptions), @@ -86,11 +86,16 @@ combineExtractionOptions (Just otherOptions) options = ExtractionOptions { Just pfs -> Just pfs, extractionOptionsMLRunPath = combineWithF extractionOptionsMLRunPath } where combineWithT fun = case fun options of - Nothing -> fun otherOptions - Just v -> Just v + Nothing -> fun otherOptions + Just v -> Just v combineWithF fun = case fun options of - Nothing -> fun otherOptions - Just v -> Just v + Nothing -> fun otherOptions + Just v -> Just v + combineWithS fun = case fun options of + Nothing -> fun otherOptions + Just s1 -> case fun otherOptions of + Nothing -> Just s1 + Just s2 -> Just (s1 `S.union` s2) extractMetadataFromRepoDir :: FilePath -> ExtractionOptions -> IO GonitoMetadata extractMetadataFromRepoDir repoDir formExtractionOptions = do @@ -108,8 +113,8 @@ extractMetadataFromRepoDir repoDir formExtractionOptions = do Nothing -> "???" let commitTagsParsed = parseTags mCommitTags - let formTagsParsed = parseTags $ extractionOptionsTags extractionOptions - let tagsParsed = union commitTagsParsed formTagsParsed + let formTagsParsed = extractionOptionsTags extractionOptions + let tagsParsed = union commitTagsParsed $ fromMaybe S.empty formTagsParsed paramFiles <- case extractionOptionsParamFiles extractionOptions of Just paramFilesGlobs -> G.globDir (Import.map G.compile paramFilesGlobs) repoDir diff --git a/Handler/ShowChallenge.hs b/Handler/ShowChallenge.hs index e2c0312..e041333 100644 --- a/Handler/ShowChallenge.hs +++ b/Handler/ShowChallenge.hs @@ -20,7 +20,10 @@ import Handler.Tables import Handler.TagUtils import Handler.MakePublic -import Gonito.ExtractMetadata (ExtractionOptions(..), extractMetadataFromRepoDir, GonitoMetadata(..)) +import Gonito.ExtractMetadata (ExtractionOptions(..), + extractMetadataFromRepoDir, + GonitoMetadata(..), + parseTags) import qualified Text.Read as TR @@ -242,7 +245,7 @@ doCreateSubmission userId challengeId mDescription mTags repoSpec chan = do gonitoMetadata <- liftIO $ extractMetadataFromRepoDir repoDir (ExtractionOptions { extractionOptionsDescription = mDescription, - extractionOptionsTags = mTags, + extractionOptionsTags = Just $ parseTags mTags, extractionOptionsGeneralParams = Nothing, extractionOptionsUnwantedParams = Nothing, extractionOptionsParamFiles = Nothing, diff --git a/test/Gonito/ExtractMetadataSpec.hs b/test/Gonito/ExtractMetadataSpec.hs index 51f2c48..5d8ea2a 100644 --- a/test/Gonito/ExtractMetadataSpec.hs +++ b/test/Gonito/ExtractMetadataSpec.hs @@ -22,7 +22,7 @@ spec = do it "simple with some fields from the form" $ do extractMetadataFromRepoDir "test/fake-git-repos/simple/" def { extractionOptionsDescription = Just "Other solution", - extractionOptionsTags = Just "other-tag,baz" + extractionOptionsTags = Just $ S.fromList ["other-tag", "baz"] } `shouldReturn` GonitoMetadata { gonitoMetadataDescription = "Other solution", gonitoMetadataTags = S.fromList ["foo", "simple-solution", "baz", "other-tag"], diff --git a/test/fake-git-repos/with-gonito-yaml b/test/fake-git-repos/with-gonito-yaml index a71de45..262f063 160000 --- a/test/fake-git-repos/with-gonito-yaml +++ b/test/fake-git-repos/with-gonito-yaml @@ -1 +1 @@ -Subproject commit a71de45eacb63081b2b39db09c48ad3d848c2541 +Subproject commit 262f063bfbdb6417fbc4589ea6dfb60be773e6b1