Skip to content

Commit

Permalink
include projectId in --json output (#1464)
Browse files Browse the repository at this point in the history
  • Loading branch information
spatten authored Sep 3, 2024
1 parent f58402e commit b1b49c7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions docs/references/subcommands/analyze.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ The `--json` flag can be used to print project metadata after running `fossa ana
```sh
fossa analyze --json
```

```json
{"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"}}
{"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"}
```

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

Default filters are filters which `fossa-cli` applies by default. These filters,
provide sensible non-production target exclusion. As `fossa-cli` relies on manifest and lock files provided in the project's directory,
provide sensible non-production target exclusion. As `fossa-cli` relies on manifest and lock files provided in the project's directory,
default filters, intentionally skip `node_modules/` and such directories. If `fossa-cli` discovers and
analyzes project found in `node_modules/`: `fossa-cli` will not be able to infer
the dependency's scope (development or production) and may double count dependencies.
Expand Down
6 changes: 3 additions & 3 deletions src/App/Fossa/API/BuildLink.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Data.Text.Extra (showT)
import Fossa.API.Types (ApiOpts (..), Organization (..))
import Srclib.Types (Locator (..))
import Srclib.Types (Locator (..), projectId)
import Text.URI qualified as URI
import Text.URI.Builder (
PathComponent (PathComponent),
Expand All @@ -31,10 +31,10 @@ import Text.URI.Builder (
import Text.URI.QQ (uri)

fossaProjectUrlPath :: Locator -> ProjectRevision -> [PathComponent]
fossaProjectUrlPath Locator{..} ProjectRevision{..} = map PathComponent components
fossaProjectUrlPath loc@Locator{..} ProjectRevision{..} = map PathComponent components
where
components = ["projects", project, "refs", "branch", branch, revision]
project = locatorFetcher <> "+" <> locatorProject
project = projectId loc
revision = fromMaybe projectRevision locatorRevision
-- We default to master because core does, and we need a branch to allow us to
-- create links directly to builds. If this changes, then a core change should
Expand Down
2 changes: 2 additions & 0 deletions src/App/Fossa/Analyze/Upload.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import Srclib.Types (
Locator (..),
SourceUnit,
licenseUnitToFullSourceUnit,
projectId,
renderLocator,
sourceUnitToFullSourceUnit,
)
Expand Down Expand Up @@ -210,6 +211,7 @@ buildProjectSummary project locator projectUrl = do
pure $
Aeson.object
[ "project" .= locatorProject locator
, "projectId" .= projectId locator
, "revision" .= revision
, "branch" .= projectBranch project
, "url" .= projectUrl
Expand Down
6 changes: 6 additions & 0 deletions src/Srclib/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Srclib.Types (
renderLocator,
parseLocator,
pathToOriginPath,
projectId,
someBaseToOriginPath,
somePathToOriginPath,
emptyLicenseUnit,
Expand Down Expand Up @@ -410,6 +411,11 @@ renderLocator :: Locator -> Text
renderLocator Locator{..} =
locatorFetcher <> "+" <> locatorProject <> "$" <> fromMaybe "" locatorRevision

-- The projectId is the full locator of the project. E.g. custom+123/someProject (<fetcher>+<orgId>/<project-name>)
projectId :: Locator -> Text
projectId Locator{..} =
locatorFetcher <> "+" <> locatorProject

parseLocator :: Text -> Locator
parseLocator raw = Locator fetcher project (if Text.null revision then Nothing else Just revision)
where
Expand Down

0 comments on commit b1b49c7

Please sign in to comment.