Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
Output the real project ID and revision with --json (#339)
Browse files Browse the repository at this point in the history
* Output the real project ID and revision

* fmt

* update changelog
  • Loading branch information
Wesley Van Melle authored Aug 19, 2021
1 parent 809ec14 commit f18cfaf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
6 changes: 5 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Spectrometer Changelog

## v2.15.5

- Fixes an issue where `--json` would output the raw project ID, instead of a normalized ID ([#339](https://github.com/fossas/spectrometer/pull/339))

## v2.15.4

- Gradle: Search parent directories for gradlew and gradlew.bat ([#336](https://github.com/fossas/spectrometer/pull/336))
- Gradle: Search parent directories for gradlew and gradlew.bat ([#336](https://github.com/fossas/spectrometer/pull/336))

This release also adds a number of closed beta features around FOSSA C/C++ support.
For now this functionality is considered publicly undocumented, and is only used with support from FOSSA engineering.
Expand Down
31 changes: 19 additions & 12 deletions src/App/Fossa/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Control.Carrier.Output.IO
import Control.Carrier.StickyLogger (StickyLogger, logSticky', runStickyLogger)
import Control.Carrier.TaskPool
import Control.Concurrent
import Control.Effect.Diagnostics ((<||>))
import Control.Effect.Diagnostics (fromMaybeText, (<||>))
import Control.Effect.Exception (Lift, SomeException, throwIO, try)
import Control.Effect.Lift (sendIO)
import Control.Effect.Record (runRecord)
Expand Down Expand Up @@ -64,7 +64,7 @@ import Path (Abs, Dir, Path, fromAbsDir, toFilePath)
import Path.IO (makeRelative)
import Path.IO qualified as P
import Srclib.Converter qualified as Srclib
import Srclib.Types (Locator, SourceUnit, parseLocator)
import Srclib.Types (Locator (locatorProject, locatorRevision), SourceUnit, parseLocator)
import Strategy.Bundler qualified as Bundler
import Strategy.Cargo qualified as Cargo
import Strategy.Carthage qualified as Carthage
Expand Down Expand Up @@ -354,7 +354,11 @@ uploadSuccessfulAnalysis (BaseDir basedir) apiOpts metadata jsonOutput override
void . Diag.recover . runExecIO $ tryUploadContributors basedir apiOpts (uploadLocator uploadResult)

if fromFlag JsonOutput jsonOutput
then logStdout . decodeUtf8 . Aeson.encode $ buildProjectSummary revision (uploadLocator uploadResult) buildUrl
then do
summary <-
Diag.context "Analysis ran successfully, but the server returned invalid metadata" $
buildProjectSummary revision (uploadLocator uploadResult) buildUrl
logStdout . decodeUtf8 $ Aeson.encode summary
else pure ()

pure locator
Expand Down Expand Up @@ -438,15 +442,18 @@ tryUploadContributors baseDir apiOpts locator = do
uploadContributors apiOpts locator contributors

-- | Build project summary JSON to be output to stdout
buildProjectSummary :: ProjectRevision -> Text -> Text -> Aeson.Value
buildProjectSummary project projectLocator projectUrl =
Aeson.object
[ "project" .= projectName project
, "revision" .= projectRevision project
, "branch" .= projectBranch project
, "url" .= projectUrl
, "id" .= projectLocator
]
buildProjectSummary :: Has Diag.Diagnostics sig m => ProjectRevision -> Text -> Text -> m Aeson.Value
buildProjectSummary project projectLocator projectUrl = do
let locator = parseLocator projectLocator
revision <- fromMaybeText "Server returned an invalid project revision" $ locatorRevision locator
pure $
Aeson.object
[ "project" .= locatorProject locator
, "revision" .= revision
, "branch" .= projectBranch project
, "url" .= projectUrl
, "id" .= projectLocator
]

buildResult :: Maybe SourceUnit -> [ProjectResult] -> Aeson.Value
buildResult maybeSrcUnit projects =
Expand Down

0 comments on commit f18cfaf

Please sign in to comment.