Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
Warn when using older .fossa.yml file (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
meghfossa authored Oct 8, 2021
1 parent e4216b6 commit e6e9b7d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/App/Docs.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module App.Docs (
userGuideUrl,
newIssueUrl,
fossaYmlDocUrl,
) where

import App.Version (versionNumber)
Expand All @@ -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"
19 changes: 17 additions & 2 deletions src/App/Fossa/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -103,16 +108,26 @@ 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
then pure Nothing
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
Expand Down
6 changes: 5 additions & 1 deletion test/App/DocsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -33,3 +33,7 @@ spec = do
describe "newIssueUrl" $
it "should be reachable" $
newIssueUrl `shouldRespondToGETWithHttpCode` 200

describe "fossaYmlDocUrl" $
it "should be reachable" $
fossaYmlDocUrl `shouldRespondToGETWithHttpCode` 200
9 changes: 9 additions & 0 deletions test/App/Fossa/Configuration/ConfigurationSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ 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

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" $
Expand All @@ -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
16 changes: 16 additions & 0 deletions test/App/Fossa/Configuration/testdata/ver2config.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e6e9b7d

Please sign in to comment.