Skip to content

Commit b1b49c7

Browse files
authored
include projectId in --json output (#1464)
1 parent f58402e commit b1b49c7

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

docs/references/subcommands/analyze.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ The `--json` flag can be used to print project metadata after running `fossa ana
5757
```sh
5858
fossa analyze --json
5959
```
60+
6061
```json
61-
{"project":{"name":"custom@new-project","branch":"master","revision":"123","url":"https://app.fossa.com/projects/custom+<org-id>/new-project/refs/branch/master/123","id":"custom+<org-id>/new-project$123"}}
62+
{"branch":"master", "id":"custom+<org-id>/new-project$123", "project":"<org-id>/new-project", "projectId":"custom+<org-id>/new-project", "revision":"123", "url":"https://app.fossa.com/projects/custom%2b+<org-id>$2fnew-project/refs/branch/master/123"}
6263
```
6364

6465
### Running a specific fossa-deps file
@@ -181,7 +182,7 @@ Note that the `MY_RG` release group must already exist, as well as `MY_RELEASE_V
181182
#### What are the default filters?
182183

183184
Default filters are filters which `fossa-cli` applies by default. These filters,
184-
provide sensible non-production target exclusion. As `fossa-cli` relies on manifest and lock files provided in the project's directory,
185+
provide sensible non-production target exclusion. As `fossa-cli` relies on manifest and lock files provided in the project's directory,
185186
default filters, intentionally skip `node_modules/` and such directories. If `fossa-cli` discovers and
186187
analyzes project found in `node_modules/`: `fossa-cli` will not be able to infer
187188
the dependency's scope (development or production) and may double count dependencies.

src/App/Fossa/API/BuildLink.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Data.Maybe (fromMaybe)
1818
import Data.Text (Text)
1919
import Data.Text.Extra (showT)
2020
import Fossa.API.Types (ApiOpts (..), Organization (..))
21-
import Srclib.Types (Locator (..))
21+
import Srclib.Types (Locator (..), projectId)
2222
import Text.URI qualified as URI
2323
import Text.URI.Builder (
2424
PathComponent (PathComponent),
@@ -31,10 +31,10 @@ import Text.URI.Builder (
3131
import Text.URI.QQ (uri)
3232

3333
fossaProjectUrlPath :: Locator -> ProjectRevision -> [PathComponent]
34-
fossaProjectUrlPath Locator{..} ProjectRevision{..} = map PathComponent components
34+
fossaProjectUrlPath loc@Locator{..} ProjectRevision{..} = map PathComponent components
3535
where
3636
components = ["projects", project, "refs", "branch", branch, revision]
37-
project = locatorFetcher <> "+" <> locatorProject
37+
project = projectId loc
3838
revision = fromMaybe projectRevision locatorRevision
3939
-- We default to master because core does, and we need a branch to allow us to
4040
-- create links directly to builds. If this changes, then a core change should

src/App/Fossa/Analyze/Upload.hs

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import Srclib.Types (
7070
Locator (..),
7171
SourceUnit,
7272
licenseUnitToFullSourceUnit,
73+
projectId,
7374
renderLocator,
7475
sourceUnitToFullSourceUnit,
7576
)
@@ -210,6 +211,7 @@ buildProjectSummary project locator projectUrl = do
210211
pure $
211212
Aeson.object
212213
[ "project" .= locatorProject locator
214+
, "projectId" .= projectId locator
213215
, "revision" .= revision
214216
, "branch" .= projectBranch project
215217
, "url" .= projectUrl

src/Srclib/Types.hs

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Srclib.Types (
2020
renderLocator,
2121
parseLocator,
2222
pathToOriginPath,
23+
projectId,
2324
someBaseToOriginPath,
2425
somePathToOriginPath,
2526
emptyLicenseUnit,
@@ -410,6 +411,11 @@ renderLocator :: Locator -> Text
410411
renderLocator Locator{..} =
411412
locatorFetcher <> "+" <> locatorProject <> "$" <> fromMaybe "" locatorRevision
412413

414+
-- The projectId is the full locator of the project. E.g. custom+123/someProject (<fetcher>+<orgId>/<project-name>)
415+
projectId :: Locator -> Text
416+
projectId Locator{..} =
417+
locatorFetcher <> "+" <> locatorProject
418+
413419
parseLocator :: Text -> Locator
414420
parseLocator raw = Locator fetcher project (if Text.null revision then Nothing else Just revision)
415421
where

0 commit comments

Comments
 (0)