Skip to content

Commit

Permalink
add copyrights to notice files
Browse files Browse the repository at this point in the history
  • Loading branch information
spatten committed Sep 11, 2024
1 parent 47de453 commit c1f9175
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Srclib/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Srclib.Types (
SourceUnit (..),
SourceUnitBuild (..),
SourceUnitDependency (..),
SourceUnitNoticeFile (..),
AdditionalDepData (..),
SourceUserDefDep (..),
SourceRemoteDep (..),
Expand Down Expand Up @@ -115,6 +116,7 @@ textToOriginPath = OriginPath . toString
data SourceUnitNoticeFile = SourceUnitNoticeFile
{ sourceUnitNoticeFilePath :: Text
, sourceUnitNoticeFileContents :: Text
, sourceUnitNoticeFileCopyrights :: Maybe (NonEmpty Text)
}
deriving (Eq, Ord, Show)

Expand All @@ -123,13 +125,15 @@ instance ToJSON SourceUnitNoticeFile where
object
[ "path" .= sourceUnitNoticeFilePath
, "contents" .= sourceUnitNoticeFileContents
, "copyrights" .= sourceUnitNoticeFileCopyrights
]

instance FromJSON SourceUnitNoticeFile where
parseJSON = withObject "SourceUnitNoticeFile" $ \obj ->
SourceUnitNoticeFile
<$> obj .: "path"
<*> obj .: "contents"
<*> obj .:? "copyrights"

data FullSourceUnit = FullSourceUnit
{ fullSourceUnitName :: Text
Expand Down
13 changes: 11 additions & 2 deletions test/App/Fossa/FirstPartyScanSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ()
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This is a notice file
This is a notice file that is copyright 2024 Frank Frankson

0 comments on commit c1f9175

Please sign in to comment.