From 2458583af5e3ffe96cdacdae6cf58179e530e389 Mon Sep 17 00:00:00 2001 From: Jessica Black Date: Fri, 3 May 2024 13:19:22 -0700 Subject: [PATCH] Fix: Treat issue summary targets optional (#1422) --- Changelog.md | 1 + src/App/Fossa/Lernie/Types.hs | 6 +- src/App/Fossa/ManualDeps.hs | 12 +- src/App/Types.hs | 6 +- .../FossaApiClient/Internal/FossaAPIV1.hs | 6 +- src/Effect/Exec.hs | 6 +- src/Fossa/API/Types.hs | 168 ++++++------------ src/Strategy/Conda/CondaEnvCreate.hs | 3 +- test/Fossa/API/TypesSpec.hs | 2 +- 9 files changed, 67 insertions(+), 143 deletions(-) diff --git a/Changelog.md b/Changelog.md index 33c57dee93..1fa2fd6b31 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,7 @@ # FOSSA CLI Changelog ## v3.9.16 +- Treat `targets` field in the issue summary loaded from Core as optional during `fossa test` and `fossa report` ([#1422](https://github.com/fossas/fossa-cli/pull/1422)). - Adds support for SwiftPM v3 files ([#1424](https://github.com/fossas/fossa-cli/pull/1424)). Future SwiftPM file formats will be accepted automatically if they remain backwards compatible with the current parser. - Updates parallel embedded binary extractions to be more properly isolated ([#1425](https://github.com/fossas/fossa-cli/pull/1425)). diff --git a/src/App/Fossa/Lernie/Types.hs b/src/App/Fossa/Lernie/Types.hs index 1744087ee3..bf0dfea461 100644 --- a/src/App/Fossa/Lernie/Types.hs +++ b/src/App/Fossa/Lernie/Types.hs @@ -66,10 +66,8 @@ instance ToJSON GrepEntry where instance FromJSON GrepEntry where parseJSON = withObject "GrepEntry" $ \obj -> GrepEntry - <$> obj - .: "matchCriteria" - <*> obj - .: "name" + <$> obj .: "matchCriteria" + <*> obj .: "name" data LernieConfig = LernieConfig { rootDir :: Path Abs Dir diff --git a/src/App/Fossa/ManualDeps.hs b/src/App/Fossa/ManualDeps.hs index 20ed6d9c99..3479b519f5 100644 --- a/src/App/Fossa/ManualDeps.hs +++ b/src/App/Fossa/ManualDeps.hs @@ -513,8 +513,7 @@ instance FromJSON CustomDependency where <$> (obj `neText` "name") <*> (unTextLike <$> obj `neText` "version") <*> (obj `neText` "license") - <*> obj - .:? "metadata" + <*> obj .:? "metadata" <* forbidMembers "custom dependencies" ["type", "path", "url"] obj instance FromJSON RemoteDependency where @@ -523,8 +522,7 @@ instance FromJSON RemoteDependency where <$> (obj `neText` "name") <*> (unTextLike <$> obj `neText` "version") <*> (obj `neText` "url") - <*> obj - .:? "metadata" + <*> obj .:? "metadata" <* forbidMembers "remote dependencies" ["license", "path", "type"] obj validateRemoteDep :: (Has Diagnostics sig m) => RemoteDependency -> Organization -> m RemoteDependency @@ -582,10 +580,8 @@ instance ToDiagnostic RemoteDepLengthIsGtThanAllowed where instance FromJSON DependencyMetadata where parseJSON = withObject "metadata" $ \obj -> DependencyMetadata - <$> obj - .:? "description" - <*> obj - .:? "homepage" + <$> obj .:? "description" + <*> obj .:? "homepage" <* forbidMembers "metadata" ["url"] obj -- Parse supported dependency types into their respective type or return Nothing. diff --git a/src/App/Types.hs b/src/App/Types.hs index bc73551490..4c13fcc955 100644 --- a/src/App/Types.hs +++ b/src/App/Types.hs @@ -74,10 +74,8 @@ instance ToJSON ReleaseGroupMetadata where instance FromJSON ReleaseGroupMetadata where parseJSON = withObject "ReleaseGroupMetadata" $ \obj -> ReleaseGroupMetadata - <$> obj - .: "name" - <*> obj - .: "release" + <$> obj .: "name" + <*> obj .: "release" data ProjectRevision = ProjectRevision { projectName :: Text diff --git a/src/Control/Carrier/FossaApiClient/Internal/FossaAPIV1.hs b/src/Control/Carrier/FossaApiClient/Internal/FossaAPIV1.hs index 862f937da6..574482748a 100644 --- a/src/Control/Carrier/FossaApiClient/Internal/FossaAPIV1.hs +++ b/src/Control/Carrier/FossaApiClient/Internal/FossaAPIV1.hs @@ -240,10 +240,8 @@ data FossaPublicFacingError = FossaPublicFacingError instance FromJSON FossaPublicFacingError where parseJSON = withObject "FossaPublicFacingError" $ \v -> FossaPublicFacingError - <$> v - .: "message" - <*> v - .: "uuid" + <$> v .: "message" + <*> v .: "uuid" newtype FossaReq m a = FossaReq {unFossaReq :: m a} deriving (Functor, Applicative, Monad, Algebra sig) diff --git a/src/Effect/Exec.hs b/src/Effect/Exec.hs index 7d4958bb57..b7baa1ff08 100644 --- a/src/Effect/Exec.hs +++ b/src/Effect/Exec.hs @@ -139,10 +139,8 @@ instance RecordableValue CmdFailure instance FromJSON CmdFailure where parseJSON = withObject "CmdFailure" $ \obj -> CmdFailure - <$> obj - .: "cmdFailureCmd" - <*> obj - .: "cmdFailureDir" + <$> obj .: "cmdFailureCmd" + <*> obj .: "cmdFailureDir" <*> (obj .: "cmdFailureExit" >>= fromRecordedValue) <*> (obj .: "cmdFailureStdout" >>= fromRecordedValue) <*> (obj .: "cmdFailureStderr" >>= fromRecordedValue) diff --git a/src/Fossa/API/Types.hs b/src/Fossa/API/Types.hs index 34153e4223..451090ce58 100644 --- a/src/Fossa/API/Types.hs +++ b/src/Fossa/API/Types.hs @@ -191,12 +191,9 @@ newtype BuildTask = BuildTask instance FromJSON Build where parseJSON = withObject "Build" $ \obj -> Build - <$> obj - .: "id" - <*> obj - .:? "error" - <*> obj - .: "task" + <$> obj .: "id" + <*> obj .:? "error" + <*> obj .: "task" instance FromJSON BuildTask where parseJSON = withObject "BuildTask" $ \obj -> @@ -225,7 +222,7 @@ data Issues = Issues data IssuesSummary = IssuesSummary { revision :: IssueSummaryRevision - , targets :: Maybe [IssueSummaryTarget] + , targets :: [IssueSummaryTarget] } deriving (Eq, Ord, Show) @@ -331,15 +328,10 @@ newtype IssueRule = IssueRule instance FromJSON Issues where parseJSON = withObject "Issues" $ \obj -> Issues - <$> obj - .: "count" - <*> obj - .:? "issues" - .!= [] - <*> obj - .: "status" - <*> obj - .:? "summary" + <$> obj .: "count" + <*> obj .:? "issues" .!= [] + <*> obj .: "status" + <*> obj .:? "summary" instance ToJSON Issues where toJSON Issues{..} = @@ -353,10 +345,8 @@ instance ToJSON Issues where instance FromJSON IssuesSummary where parseJSON = withObject "IssuesSummary" $ \obj -> IssuesSummary - <$> obj - .: "revision" - <*> obj - .: "targets" + <$> obj .: "revision" + <*> obj .:? "targets" .!= [] instance ToJSON IssuesSummary where toJSON IssuesSummary{..} = @@ -368,12 +358,9 @@ instance ToJSON IssuesSummary where instance FromJSON IssueSummaryRevision where parseJSON = withObject "IssueSummaryRevision" $ \obj -> IssueSummaryRevision - <$> obj - .: "projectTitle" - <*> obj - .: "projectRevision" - <*> obj - .:? "isPublic" + <$> obj .: "projectTitle" + <*> obj .: "projectRevision" + <*> obj .:? "isPublic" instance ToJSON IssueSummaryRevision where toJSON IssueSummaryRevision{..} = @@ -386,10 +373,8 @@ instance ToJSON IssueSummaryRevision where instance FromJSON IssueSummaryTarget where parseJSON = withObject "IssueSummaryTarget" $ \obj -> IssueSummaryTarget - <$> obj - .: "type" - <*> obj - .: "originPaths" + <$> obj .: "type" + <*> obj .: "originPaths" instance ToJSON IssueSummaryTarget where toJSON IssueSummaryTarget{..} = @@ -401,27 +386,16 @@ instance ToJSON IssueSummaryTarget where instance FromJSON Issue where parseJSON = withObject "Issue" $ \obj -> Issue - <$> obj - .: "id" - <*> obj - .:? "priorityString" - <*> obj - .: "resolved" - <*> obj - .:? "revisionId" - .!= "unknown project" - <*> obj - .: "type" - <*> obj - .:? "rule" - <*> obj - .:? "license" - <*> obj - .:? "issueDashURL" - <*> obj - .:? "cve" - <*> obj - .:? "fixedIn" + <$> obj .: "id" + <*> obj .:? "priorityString" + <*> obj .: "resolved" + <*> obj .:? "revisionId" .!= "unknown project" + <*> obj .: "type" + <*> obj .:? "rule" + <*> obj .:? "license" + <*> obj .:? "issueDashURL" + <*> obj .:? "cve" + <*> obj .:? "fixedIn" instance ToJSON Issue where toJSON Issue{..} = @@ -529,53 +503,22 @@ blankOrganization = instance FromJSON Organization where parseJSON = withObject "Organization" $ \obj -> Organization - <$> obj - .: "organizationId" - <*> obj - .:? "usesSAML" - .!= False - <*> obj - .:? "supportsCliLicenseScanning" - .!= False - <*> obj - .:? "supportsAnalyzedRevisionsQuery" - .!= False - <*> obj - .:? "defaultVendoredDependencyScanType" - .!= CLILicenseScan - <*> obj - .:? "supportsIssueDiffs" - .!= False - <*> obj - .:? "supportsNativeContainerScans" - .!= False - <*> obj - .:? "supportsDependenciesCachePolling" - .!= False - <*> obj - .:? "requireFullFileUploads" - .!= False - <*> obj - .:? "defaultToFirstPartyScans" - .!= False - <*> obj - .:? "supportsPathDependency" - .!= False - <*> obj - .:? "supportsFirstPartyScans" - .!= False - <*> obj - .:? "customLicenseScanConfigs" - .!= [] - <*> obj - .:? "supportsReachability" - .!= False - <*> obj - .:? "supportsPreflightChecks" - .!= False - <*> obj - .:? "subscription" - .!= Free + <$> obj .: "organizationId" + <*> obj .:? "usesSAML" .!= False + <*> obj .:? "supportsCliLicenseScanning" .!= False + <*> obj .:? "supportsAnalyzedRevisionsQuery" .!= False + <*> obj .:? "defaultVendoredDependencyScanType" .!= CLILicenseScan + <*> obj .:? "supportsIssueDiffs" .!= False + <*> obj .:? "supportsNativeContainerScans" .!= False + <*> obj .:? "supportsDependenciesCachePolling" .!= False + <*> obj .:? "requireFullFileUploads" .!= False + <*> obj .:? "defaultToFirstPartyScans" .!= False + <*> obj .:? "supportsPathDependency" .!= False + <*> obj .:? "supportsFirstPartyScans" .!= False + <*> obj .:? "customLicenseScanConfigs" .!= [] + <*> obj .:? "supportsReachability" .!= False + <*> obj .:? "supportsPreflightChecks" .!= False + <*> obj .:? "subscription" .!= Free data TokenType = Push @@ -588,8 +531,7 @@ newtype TokenTypeResponse = TokenTypeResponse {tokenType :: TokenType} instance FromJSON TokenTypeResponse where parseJSON = withObject "TokenTypeResponse" $ \obj -> TokenTypeResponse - <$> obj - .: "tokenType" + <$> obj .: "tokenType" instance FromJSON TokenType where parseJSON = withText "TokenType" $ \case @@ -650,12 +592,9 @@ data Project = Project instance FromJSON Project where parseJSON = withObject "Project" $ \obj -> Project - <$> obj - .: "id" - <*> obj - .: "title" - <*> obj - .: "isMonorepo" + <$> obj .: "id" + <*> obj .: "title" + <*> obj .: "isMonorepo" data UploadResponse = UploadResponse { uploadLocator :: Locator @@ -683,8 +622,7 @@ newtype RevisionDependencyCache = RevisionDependencyCache {status :: RevisionDep instance FromJSON RevisionDependencyCache where parseJSON = withObject "RevisionDependencyCache" $ \obj -> RevisionDependencyCache - <$> obj - .: "status" + <$> obj .: "status" instance FromJSON RevisionDependencyCacheStatus where parseJSON = withText "RevisionDependencyCacheStatus" $ \txt -> case Text.toUpper txt of @@ -739,14 +677,12 @@ renderedIssues issues = rendered , line ] - renderRevisionTargets :: Maybe [IssueSummaryTarget] -> Doc ann - renderRevisionTargets issueRevisionTargets = case issueRevisionTargets of - Nothing -> mempty - Just [] -> mempty - Just targets -> - vsep $ - ["Project Targets:"] - <> map (\target -> "- " <> renderedTarget target) (sort targets) + renderRevisionTargets :: [IssueSummaryTarget] -> Doc ann + renderRevisionTargets [] = mempty + renderRevisionTargets targets = + vsep $ + ["Project Targets:"] + <> map (\target -> "- " <> renderedTarget target) (sort targets) renderProjectVisibility :: Maybe Bool -> Doc ann renderProjectVisibility Nothing = "unknown" diff --git a/src/Strategy/Conda/CondaEnvCreate.hs b/src/Strategy/Conda/CondaEnvCreate.hs index 17ab28f388..5cc5f085a7 100644 --- a/src/Strategy/Conda/CondaEnvCreate.hs +++ b/src/Strategy/Conda/CondaEnvCreate.hs @@ -94,8 +94,7 @@ data CondaEnvDep = CondaEnvDep instance FromJSON CondaEnvCreateOut where parseJSON = withObject "CondaEnvOutput" $ \obj -> CondaEnvCreateOut - <$> obj - .: "dependencies" + <$> obj .: "dependencies" type Parser = Parsec Void Text diff --git a/test/Fossa/API/TypesSpec.hs b/test/Fossa/API/TypesSpec.hs index 7b64ee3caf..1f14d5f172 100644 --- a/test/Fossa/API/TypesSpec.hs +++ b/test/Fossa/API/TypesSpec.hs @@ -29,7 +29,7 @@ genIssueRevisionSummary :: Gen IssuesSummary genIssueRevisionSummary = IssuesSummary <$> genIssueRevision - <*> Gen.maybe (Gen.list (Range.linear 0 100) genIssueRevisionTargets) + <*> Gen.list (Range.linear 0 100) genIssueRevisionTargets genIssueRevision :: Gen IssueSummaryRevision genIssueRevision =