diff --git a/src/App/Docs.hs b/src/App/Docs.hs index 984f66a35..6dabe2696 100644 --- a/src/App/Docs.hs +++ b/src/App/Docs.hs @@ -1,6 +1,7 @@ module App.Docs ( userGuideUrl, newIssueUrl, + fossaYmlDocUrl, ) where import App.Version (versionNumber) @@ -9,11 +10,14 @@ import Data.Text (Text) sourceCodeUrl :: Text sourceCodeUrl = "https://github.com/fossas/spectrometer" +guidePathOf :: Text -> Text -> Text +guidePathOf revision repoRelUrl = sourceCodeUrl <> "/blob/" <> revision <> repoRelUrl + userGuideUrl :: Text -userGuideUrl = guidePathOf $ maybe "master" ("v" <>) versionNumber - where - guidePathOf :: Text -> Text - guidePathOf revision = sourceCodeUrl <> "/blob/" <> revision <> "/docs/userguide.md" +userGuideUrl = guidePathOf (maybe "master" ("v" <>) versionNumber) "/docs/userguide.md" + +fossaYmlDocUrl :: Text +fossaYmlDocUrl = guidePathOf (maybe "master" ("v" <>) versionNumber) "/docs/reference/fossa_yml.md" newIssueUrl :: Text newIssueUrl = sourceCodeUrl <> "/issues/new" diff --git a/src/App/Fossa/Configuration.hs b/src/App/Fossa/Configuration.hs index fe75ae571..1a0f58e84 100644 --- a/src/App/Fossa/Configuration.hs +++ b/src/App/Fossa/Configuration.hs @@ -12,10 +12,15 @@ module App.Fossa.Configuration ( ConfigPaths (..), ) where +import App.Docs (fossaYmlDocUrl) import App.Types import Control.Carrier.Diagnostics qualified as Diag +import Control.Effect.Lift (Lift) import Data.Aeson (FromJSON (parseJSON), withObject, (.!=), (.:), (.:?)) +import Data.Functor (($>)) import Data.Text (Text) +import Data.Text.Prettyprint.Doc (Doc, Pretty (pretty), vsep) +import Effect.Logger (Severity (SevWarn), logWarn, withDefaultLogger) import Effect.ReadFS import Path import Path.IO (getCurrentDir) @@ -103,7 +108,7 @@ instance FromJSON ConfigPaths where defaultFile :: Path Rel File defaultFile = $(mkRelFile ".fossa.yml") -readConfigFile :: (Has ReadFS sig m, Has Diag.Diagnostics sig m) => Path Abs File -> m (Maybe ConfigFile) +readConfigFile :: (Has (Lift IO) sig m, Has ReadFS sig m, Has Diag.Diagnostics sig m) => Path Abs File -> m (Maybe ConfigFile) readConfigFile file = do exists <- doesFileExist file if not exists @@ -111,8 +116,18 @@ readConfigFile file = do else do readConfig <- readContentsYaml @ConfigFile file if configVersion readConfig < 3 - then pure Nothing + then withDefaultLogger SevWarn (logWarn $ warnMsgForOlderConfig (configVersion readConfig)) $> Nothing else pure $ Just readConfig + where + warnMsgForOlderConfig :: Int -> Doc ann + warnMsgForOlderConfig foundVersion = + vsep + [ "" + , "Incompatible [.fossa.yml] found! Expecting `version: 3`; found `version: " <> pretty foundVersion <> "`" + , "Documentation for the new config file format can be found here:" + , " " <> pretty fossaYmlDocUrl + , "" + ] readConfigFileIO :: IO (Maybe ConfigFile) readConfigFileIO = do diff --git a/test/App/DocsSpec.hs b/test/App/DocsSpec.hs index f635a1706..65d392a7b 100644 --- a/test/App/DocsSpec.hs +++ b/test/App/DocsSpec.hs @@ -2,7 +2,7 @@ module App.DocsSpec ( spec, ) where -import App.Docs (newIssueUrl, userGuideUrl) +import App.Docs (fossaYmlDocUrl, newIssueUrl, userGuideUrl) import Data.Maybe (fromJust) import Data.Text (Text) import Network.HTTP.Req ( @@ -33,3 +33,7 @@ spec = do describe "newIssueUrl" $ it "should be reachable" $ newIssueUrl `shouldRespondToGETWithHttpCode` 200 + + describe "fossaYmlDocUrl" $ + it "should be reachable" $ + fossaYmlDocUrl `shouldRespondToGETWithHttpCode` 200 diff --git a/test/App/Fossa/Configuration/ConfigurationSpec.hs b/test/App/Fossa/Configuration/ConfigurationSpec.hs index bb39fa03a..cb0a0138a 100644 --- a/test/App/Fossa/Configuration/ConfigurationSpec.hs +++ b/test/App/Fossa/Configuration/ConfigurationSpec.hs @@ -78,6 +78,9 @@ badFile = $(mkRelFile "test/App/Fossa/Configuration/testdata/invalidconfig.yml") missingFile :: Path Rel File missingFile = $(mkRelFile "test/App/Fossa/Configuration/testdata/missingfile.yml") +ver2configFile :: Path Rel File +ver2configFile = $(mkRelFile "test/App/Fossa/Configuration/testdata/ver2config.yml") + spec :: T.Spec spec = do dir <- T.runIO getCurrentDir @@ -85,6 +88,7 @@ spec = do config <- T.runIO . Diag.runDiagnostics $ runReadFSIO $ readConfigFile (dir testFile) badConfig <- T.runIO . Diag.runDiagnostics $ runReadFSIO $ readConfigFile (dir badFile) missingConfig <- T.runIO . Diag.runDiagnostics $ runReadFSIO $ readConfigFile (dir missingFile) + ver2Config <- T.runIO . Diag.runDiagnostics $ runReadFSIO $ readConfigFile (dir ver2configFile) T.describe "config file parser" $ do T.it "parses a full configuration file correctly" $ @@ -103,3 +107,8 @@ spec = do case missingConfig of Left _ -> T.expectationFailure "should have failed parsing" Right result -> result `T.shouldBe` Nothing + + T.it "returns Nothing for incompatible file" $ + case ver2Config of + Left err -> T.expectationFailure ("failed to parse config file" <> show (Diag.renderFailureBundle err)) + Right result -> result `T.shouldBe` Nothing diff --git a/test/App/Fossa/Configuration/testdata/ver2config.yml b/test/App/Fossa/Configuration/testdata/ver2config.yml new file mode 100644 index 000000000..8f75b911e --- /dev/null +++ b/test/App/Fossa/Configuration/testdata/ver2config.yml @@ -0,0 +1,16 @@ + + +# Generated by FOSSA CLI (https://github.com/fossas/fossa-cli) +# Visit https://fossa.com to learn more + +version: 2 +cli: + server: https://app.fossa.com + fetcher: custom + project: https://github.com/fossas/fossa-cli +analyze: + modules: + - name: github.com/fossas/fossa-cli/cmd/fossa + type: go + target: github.com/fossas/fossa-cli/cmd/fossa + path: cmd/fossa \ No newline at end of file