forked from filipg/gonito
Sets are used instead of strings for tags
This commit is contained in:
parent
9d67e39a06
commit
37125b8326
@ -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),
|
||||
@ -91,6 +91,11 @@ combineExtractionOptions (Just otherOptions) options = ExtractionOptions {
|
||||
combineWithF fun = case fun options of
|
||||
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
|
||||
|
@ -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,
|
||||
|
@ -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"],
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit a71de45eacb63081b2b39db09c48ad3d848c2541
|
||||
Subproject commit 262f063bfbdb6417fbc4589ea6dfb60be773e6b1
|
Loading…
Reference in New Issue
Block a user