Skip to content

Commit d28a98f

Browse files
authored
Ane 1808 suppress reachability notice (#1440)
* Don't summarize reachability analysis if it isn't enabled for the org. * Skip reachability analysis entirely if the org doesn't support it. * Fix specs. * Remove extraneous check. * spec fixes. * Update comment. * Changelog entry.
1 parent 8371ab7 commit d28a98f

File tree

8 files changed

+43
-15
lines changed

8 files changed

+43
-15
lines changed

Changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# FOSSA CLI Changelog
22

3+
## Unreleased
4+
5+
- Reachability: For organizations that don't have reachability turned on suppress messages about it. ([#1440](https://github.com/fossas/fossa-cli/pull/1440))
6+
37
## 3.9.22
48
- Fixes release group flags for `fossa analyze` and `fossa container analyze` ([#1439](https://github.com/fossas/fossa-cli/pull/1439))
59

src/App/Fossa/Analyze.hs

+9-4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ import Effect.Logger (
120120
)
121121
import Effect.ReadFS (ReadFS)
122122
import Errata (Errata (..))
123+
import Fossa.API.Types (Organization (Organization, orgSupportsReachability))
123124
import Path (Abs, Dir, Path, toFilePath)
124125
import Path.IO (makeRelative)
125126
import Prettyprinter (
@@ -302,9 +303,10 @@ analyze cfg = Diag.context "fossa-analyze" $ do
302303
pure Nothing
303304
else Diag.context "fossa-deps" . runStickyLogger SevInfo $ analyzeFossaDepsFile basedir customFossaDepsFile maybeApiOpts vendoredDepsOptions
304305

305-
_ <- case destination of
306-
OutputStdout -> pure ()
307-
UploadScan apiOpts metadata -> runFossaApiClient apiOpts $ preflightChecks $ AnalyzeChecks revision metadata
306+
orgInfo <- case destination of
307+
OutputStdout -> pure Nothing
308+
UploadScan apiOpts metadata ->
309+
fmap Just . runFossaApiClient apiOpts . preflightChecks $ AnalyzeChecks revision metadata
308310

309311
-- additional source units are built outside the standard strategy flow, because they either
310312
-- require additional information (eg API credentials), or they return additional information (eg user deps).
@@ -406,7 +408,10 @@ analyze cfg = Diag.context "fossa-analyze" $ do
406408
(False, _) -> traverse (withPathDependencyNudge includeAll) filteredProjects
407409
logDebug $ "Filtered projects with path dependencies: " <> pretty (show filteredProjects')
408410

409-
reachabilityUnitsResult <- Diag.context "reachability analysis" . runReader (Config.reachabilityConfig cfg) $ analyzeForReachability projectScans
411+
reachabilityUnitsResult <-
412+
case orgInfo of
413+
(Just (Organization{orgSupportsReachability = False})) -> pure []
414+
_ -> Diag.context "reachability analysis" . runReader (Config.reachabilityConfig cfg) $ analyzeForReachability projectScans
410415
let reachabilityUnits = onlyFoundUnits reachabilityUnitsResult
411416

412417
let analysisResult = AnalysisScanResult projectScans vsiResults binarySearchResults manualSrcUnits dynamicLinkedResults maybeLernieResults reachabilityUnitsResult

src/App/Fossa/Analyze/ScanSummary.hs

+6-1
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,14 @@ summarize cfg endpointVersion (AnalysisScanResult dps vsi binary manualDeps dyna
217217
<> summarizeSrcUnit "fossa-deps file analysis" (Just getManualVendorDepsIdentifier) manualDeps
218218
<> summarizeSrcUnit "Keyword Search" (Just getLernieIdentifier) (lernieResultsKeywordSearches <$$> lernie)
219219
<> summarizeSrcUnit "Custom-License Search" (Just getLernieIdentifier) (lernieResultsCustomLicenses <$$> lernie)
220-
<> summarizeReachability "Reachability analysis" reachabilityAttempts
220+
<> reachabilitySummary
221221
<> [""]
222222
where
223+
reachabilitySummary =
224+
if null reachabilityAttempts
225+
then
226+
[]
227+
else summarizeReachability "Reachability analysis" reachabilityAttempts
223228
vsiResults = summarizeSrcUnit "vsi analysis" (Just (join . map vsiSourceUnits)) vsi
224229
projects = sort dps
225230
totalScanCount =

src/App/Fossa/Container/AnalyzeNative.hs

+5-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ analyze cfg = do
109109

110110
_ <- case scanDestination cfg of
111111
OutputStdout -> pure ()
112-
UploadScan apiOpts projectMetadata -> runFossaApiClient apiOpts $ preflightChecks $ AnalyzeChecks revision projectMetadata
112+
UploadScan apiOpts projectMetadata ->
113+
void
114+
. runFossaApiClient apiOpts
115+
. preflightChecks
116+
$ AnalyzeChecks revision projectMetadata
113117

114118
logInfo ("Using project name: `" <> pretty (projectName revision) <> "`")
115119
logInfo ("Using project revision: `" <> pretty (projectRevision revision) <> "`")

src/App/Fossa/Lernie/Analyze.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ analyzeWithLernieWithOrgInfo ::
9191
GrepOptions ->
9292
m (Maybe LernieResults)
9393
analyzeWithLernieWithOrgInfo rootDir grepOptions = do
94-
orgWideCustomLicenses <- orgCustomLicenseScanConfigs <$> getOrganization
95-
uploadKind <- orgFileUpload <$> getOrganization
94+
org <- getOrganization
95+
let orgWideCustomLicenses = orgCustomLicenseScanConfigs org
96+
uploadKind = orgFileUpload org
9697

9798
let options = grepOptions{customLicenseSearch = nub $ orgWideCustomLicenses <> customLicenseSearch grepOptions}
9899
analyzeWithLernieMain rootDir options uploadKind

src/App/Fossa/PreflightChecks.hs

+5-2
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,24 @@ data PreflightCommandChecks
4141
| ReportChecks
4242
| AssertUserDefinedBinariesChecks
4343

44+
-- | Returns the Organization fetched as part of the checks.
4445
guardWithPreflightChecks ::
4546
( Has Diagnostics sig m
4647
, Has (Lift IO) sig m
4748
) =>
4849
ApiOpts ->
4950
PreflightCommandChecks ->
50-
m ()
51+
m Organization
5152
guardWithPreflightChecks apiOpts cmd = ignoreDebug $ runFossaApiClient apiOpts $ preflightChecks cmd
5253

54+
-- | Returns the Organization fetched as part of the checks.
5355
preflightChecks ::
5456
( Has Diagnostics sig m
5557
, Has (Lift IO) sig m
5658
, Has FossaApiClient sig m
5759
) =>
5860
PreflightCommandChecks ->
59-
m ()
61+
m Organization
6062
preflightChecks cmd = context "preflight-checks" $ do
6163
-- Check for writing to temp dir
6264
tmpDir <- sendIO getTempDir
@@ -78,6 +80,7 @@ preflightChecks cmd = context "preflight-checks" $ do
7880
fullAccessTokenCheck tokenType
7981
premiumSubscriptionCheck org
8082
_ -> pure ()
83+
pure org
8184

8285
uploadBuildPermissionsCheck :: Has Diagnostics sig m => CustomBuildUploadPermissions -> m ()
8386
uploadBuildPermissionsCheck CustomBuildUploadPermissions{..} =

src/App/Fossa/SBOM/Analyze.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ analyze config = do
3737
let emptyMetadata = ProjectMetadata Nothing Nothing Nothing Nothing Nothing Nothing [] Nothing
3838
let apiOpts = sbomApiOpts config
3939
trackUsage SBOMAnalyzeUsage
40-
runFossaApiClient apiOpts . preflightChecks $ AnalyzeChecks (sbomRevision config) emptyMetadata
40+
void . runFossaApiClient apiOpts . preflightChecks $ AnalyzeChecks (sbomRevision config) emptyMetadata
4141
runFossaApiClient apiOpts . runStickyLogger (severity config) $ analyzeInternal config
4242

4343
analyzeInternal ::

test/App/Fossa/PreflightChecksSpec.hs

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import App.Fossa.PreflightChecks (PreflightCommandChecks (..), preflightChecks)
44
import Control.Algebra (Has)
55
import Control.Carrier.Debug (ignoreDebug)
66
import Control.Effect.FossaApiClient (FossaApiClientF (..))
7+
import Fossa.API.Types (
8+
Organization (orgSubscription, orgSupportsPreflightChecks),
9+
Subscription (Premium),
10+
)
711
import Test.Effect (expectFatal', it', shouldBe')
812
import Test.Fixtures qualified as Fixtures
913
import Test.Hspec (Spec)
@@ -38,12 +42,13 @@ spec = do
3842
it' "should pass all checks for test command" $ do
3943
expectOrganizationWithPreflightChecks
4044
res <- ignoreDebug $ preflightChecks TestChecks
41-
res `shouldBe'` ()
45+
res `shouldBe'` Fixtures.organizationWithPreflightChecks
4246
it' "should pass all check for report command" $ do
47+
let expected = Fixtures.organizationWithPreflightChecks{orgSubscription = Premium}
4348
expectOrganizationWithPremiumSubscription
4449
expectFullAccessToken
4550
res <- preflightChecks ReportChecks
46-
res `shouldBe'` ()
51+
res `shouldBe'` expected
4752
it' "should fail full access token check for report command" $ do
4853
expectOrganizationWithPremiumSubscription
4954
expectPushToken
@@ -56,11 +61,12 @@ spec = do
5661
expectOrganizationWithPreflightChecks
5762
(GetCustomBuildPermissons Fixtures.projectRevision Fixtures.projectMetadata) `returnsOnce` Fixtures.validCustomUploadPermissions
5863
res <- ignoreDebug $ preflightChecks analyzeChecks
59-
res `shouldBe'` ()
64+
res `shouldBe'` Fixtures.organizationWithPreflightChecks
6065
it' "should pass all checks while skipping permission checks for analyze command" $ do
66+
let expected = Fixtures.organizationWithPreflightChecks{orgSupportsPreflightChecks = False}
6167
expectOrganization
6268
res <- ignoreDebug $ preflightChecks analyzeChecks
63-
res `shouldBe'` ()
69+
res `shouldBe'` expected
6470
it' "should fail edit project check for analyze command" $ do
6571
expectOrganizationWithPreflightChecks
6672
(GetCustomBuildPermissons Fixtures.projectRevision Fixtures.projectMetadata) `returnsOnce` Fixtures.invalidEditProjectPermission

0 commit comments

Comments
 (0)