From c1f91752ddadb0946d740a8bac12bba18dd71f33 Mon Sep 17 00:00:00 2001 From: spatten Date: Wed, 11 Sep 2024 13:03:10 -0700 Subject: [PATCH] add copyrights to notice files --- src/Srclib/Types.hs | 4 ++++ test/App/Fossa/FirstPartyScanSpec.hs | 13 +++++++++++-- .../testdata/firstparty-with-notice/NOTICE.txt | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Srclib/Types.hs b/src/Srclib/Types.hs index e437f900d7..bf1fbaadb3 100644 --- a/src/Srclib/Types.hs +++ b/src/Srclib/Types.hs @@ -5,6 +5,7 @@ module Srclib.Types ( SourceUnit (..), SourceUnitBuild (..), SourceUnitDependency (..), + SourceUnitNoticeFile (..), AdditionalDepData (..), SourceUserDefDep (..), SourceRemoteDep (..), @@ -115,6 +116,7 @@ textToOriginPath = OriginPath . toString data SourceUnitNoticeFile = SourceUnitNoticeFile { sourceUnitNoticeFilePath :: Text , sourceUnitNoticeFileContents :: Text + , sourceUnitNoticeFileCopyrights :: Maybe (NonEmpty Text) } deriving (Eq, Ord, Show) @@ -123,6 +125,7 @@ instance ToJSON SourceUnitNoticeFile where object [ "path" .= sourceUnitNoticeFilePath , "contents" .= sourceUnitNoticeFileContents + , "copyrights" .= sourceUnitNoticeFileCopyrights ] instance FromJSON SourceUnitNoticeFile where @@ -130,6 +133,7 @@ instance FromJSON SourceUnitNoticeFile where SourceUnitNoticeFile <$> obj .: "path" <*> obj .: "contents" + <*> obj .:? "copyrights" data FullSourceUnit = FullSourceUnit { fullSourceUnitName :: Text diff --git a/test/App/Fossa/FirstPartyScanSpec.hs b/test/App/Fossa/FirstPartyScanSpec.hs index 91c5affc82..ae146eeeb4 100644 --- a/test/App/Fossa/FirstPartyScanSpec.hs +++ b/test/App/Fossa/FirstPartyScanSpec.hs @@ -9,11 +9,11 @@ import Control.Algebra (Has) import Control.Effect.FossaApiClient (FossaApiClientF (..)) import Data.List qualified as List import Data.List.NonEmpty qualified as NE -import Data.Maybe (isJust) +import Data.Maybe (fromMaybe, isJust) import Fossa.API.Types (Organization (..)) import Path (Dir, Path, Rel, mkRelDir, ()) import Path.IO (getCurrentDir) -import Srclib.Types (LicenseSourceUnit (..), LicenseUnit (licenseUnitData, licenseUnitName), LicenseUnitData (licenseUnitDataContents), licenseUnitType) +import Srclib.Types (LicenseSourceUnit (..), LicenseUnit (..), LicenseUnitData (licenseUnitDataContents), SourceUnitNoticeFile (..)) import Test.Effect (expectFatal', expectationFailure', it', shouldBe') import Test.Fixtures qualified as Fixtures import Test.Hspec (Spec, describe, runIO) @@ -113,6 +113,15 @@ spec = do let noticeUnit = NE.head units licenseUnitName noticeUnit `shouldBe'` "" licenseUnitType noticeUnit `shouldBe'` "NoticeFileMatches" + let noticeFiles = fromMaybe (NE.fromList []) (licenseUnitNoticeFiles noticeUnit) + length noticeFiles `shouldBe'` 1 + let noticeFile = NE.head noticeFiles + let copyrights = fromMaybe (NE.fromList []) (sourceUnitNoticeFileCopyrights noticeFile) + length copyrights `shouldBe'` 1 + let copyright = NE.head copyrights + copyright `shouldBe'` "2024 Frank Frankson" + sourceUnitNoticeFileContents noticeFile `shouldBe'` "This is a notice file that is copyright 2024 Frank Frankson\n" + sourceUnitNoticeFilePath noticeFile `shouldBe'` "NOTICE.txt" -- The default org defaults to not running first party scans but has first-party scans enabled expectGetOrganizationThatDefaultsToNoFirstPartyScans :: Has MockApi sig m => m () diff --git a/test/App/Fossa/VendoredDependency/testdata/firstparty-with-notice/NOTICE.txt b/test/App/Fossa/VendoredDependency/testdata/firstparty-with-notice/NOTICE.txt index 6c5d3ac8b7..53ebdc28c3 100644 --- a/test/App/Fossa/VendoredDependency/testdata/firstparty-with-notice/NOTICE.txt +++ b/test/App/Fossa/VendoredDependency/testdata/firstparty-with-notice/NOTICE.txt @@ -1 +1 @@ -This is a notice file +This is a notice file that is copyright 2024 Frank Frankson