Skip to content

Commit

Permalink
Fix: Treat issue summary targets optional (#1422)
Browse files Browse the repository at this point in the history
  • Loading branch information
jssblck authored May 3, 2024
1 parent 87635a7 commit 2458583
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 143 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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)).
Expand Down
6 changes: 2 additions & 4 deletions src/App/Fossa/Lernie/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions src/App/Fossa/ManualDeps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions src/App/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/Control/Carrier/FossaApiClient/Internal/FossaAPIV1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions src/Effect/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
168 changes: 52 additions & 116 deletions src/Fossa/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -225,7 +222,7 @@ data Issues = Issues

data IssuesSummary = IssuesSummary
{ revision :: IssueSummaryRevision
, targets :: Maybe [IssueSummaryTarget]
, targets :: [IssueSummaryTarget]
}
deriving (Eq, Ord, Show)

Expand Down Expand Up @@ -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{..} =
Expand All @@ -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{..} =
Expand All @@ -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{..} =
Expand All @@ -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{..} =
Expand All @@ -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{..} =
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions src/Strategy/Conda/CondaEnvCreate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/Fossa/API/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 2458583

Please sign in to comment.