From 101542ae8b5e48bfeb75f8d37a1126364b6d7fb6 Mon Sep 17 00:00:00 2001 From: spatten Date: Fri, 30 Aug 2024 13:23:14 -0700 Subject: [PATCH 1/6] include projectId in --json output --- src/App/Fossa/Analyze/Upload.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/App/Fossa/Analyze/Upload.hs b/src/App/Fossa/Analyze/Upload.hs index fec50ecebd..7c07494317 100644 --- a/src/App/Fossa/Analyze/Upload.hs +++ b/src/App/Fossa/Analyze/Upload.hs @@ -210,6 +210,7 @@ buildProjectSummary project locator projectUrl = do pure $ Aeson.object [ "project" .= locatorProject locator + , "projectId" .= (locatorFetcher locator <> "+" <> locatorProject locator) , "revision" .= revision , "branch" .= projectBranch project , "url" .= projectUrl From 86c20d3655bfdc52bdb9ddcd5df3e0fd2fbd8f88 Mon Sep 17 00:00:00 2001 From: spatten Date: Fri, 30 Aug 2024 16:49:35 -0700 Subject: [PATCH 2/6] update documentation for --json output --- docs/references/subcommands/analyze.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/references/subcommands/analyze.md b/docs/references/subcommands/analyze.md index 41c4582943..20696cc3c1 100644 --- a/docs/references/subcommands/analyze.md +++ b/docs/references/subcommands/analyze.md @@ -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+/new-project/refs/branch/master/123","id":"custom+/new-project$123"}} +{"branch":"master", "id":"custom+/new-project$123", "project":"org-id/new-project", "projectId":"custom+/new-project", "revision":"123", "url":"https://app.fossa.com/projects/custom+/new-project/refs/branch/master/123"} ``` ### 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 #### 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. From a15c919127750b1a6212a73bfb656b1fc8ae8ec0 Mon Sep 17 00:00:00 2001 From: spatten Date: Fri, 30 Aug 2024 17:18:13 -0700 Subject: [PATCH 3/6] more angle-brackets --- docs/references/subcommands/analyze.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/subcommands/analyze.md b/docs/references/subcommands/analyze.md index 20696cc3c1..11e35d2252 100644 --- a/docs/references/subcommands/analyze.md +++ b/docs/references/subcommands/analyze.md @@ -59,7 +59,7 @@ fossa analyze --json ``` ```json -{"branch":"master", "id":"custom+/new-project$123", "project":"org-id/new-project", "projectId":"custom+/new-project", "revision":"123", "url":"https://app.fossa.com/projects/custom+/new-project/refs/branch/master/123"} +{"branch":"master", "id":"custom+/new-project$123", "project":"/new-project", "projectId":"custom+/new-project", "revision":"123", "url":"https://app.fossa.com/projects/custom+/new-project/refs/branch/master/123"} ``` ### Running a specific fossa-deps file From 2b079039cc24661bd590c28905b0d6adcb2a612a Mon Sep 17 00:00:00 2001 From: spatten Date: Fri, 30 Aug 2024 17:20:28 -0700 Subject: [PATCH 4/6] url-encode the sample url --- docs/references/subcommands/analyze.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/subcommands/analyze.md b/docs/references/subcommands/analyze.md index 11e35d2252..36ec08be98 100644 --- a/docs/references/subcommands/analyze.md +++ b/docs/references/subcommands/analyze.md @@ -59,7 +59,7 @@ fossa analyze --json ``` ```json -{"branch":"master", "id":"custom+/new-project$123", "project":"/new-project", "projectId":"custom+/new-project", "revision":"123", "url":"https://app.fossa.com/projects/custom+/new-project/refs/branch/master/123"} +{"branch":"master", "id":"custom+/new-project$123", "project":"/new-project", "projectId":"custom+/new-project", "revision":"123", "url":"https://app.fossa.com/projects/custom%2b+$2fnew-project/refs/branch/master/123"} ``` ### Running a specific fossa-deps file From c38616552631992f05841c3ebc89659548901fd9 Mon Sep 17 00:00:00 2001 From: spatten Date: Tue, 3 Sep 2024 11:58:56 -0700 Subject: [PATCH 5/6] add and use a projectId function --- src/App/Fossa/API/BuildLink.hs | 6 +++--- src/App/Fossa/Analyze/Upload.hs | 3 ++- src/Srclib/Types.hs | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/App/Fossa/API/BuildLink.hs b/src/App/Fossa/API/BuildLink.hs index 3bd461accc..c2964c932d 100644 --- a/src/App/Fossa/API/BuildLink.hs +++ b/src/App/Fossa/API/BuildLink.hs @@ -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), @@ -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 diff --git a/src/App/Fossa/Analyze/Upload.hs b/src/App/Fossa/Analyze/Upload.hs index 7c07494317..bb10afe8c9 100644 --- a/src/App/Fossa/Analyze/Upload.hs +++ b/src/App/Fossa/Analyze/Upload.hs @@ -70,6 +70,7 @@ import Srclib.Types ( Locator (..), SourceUnit, licenseUnitToFullSourceUnit, + projectId, renderLocator, sourceUnitToFullSourceUnit, ) @@ -210,7 +211,7 @@ buildProjectSummary project locator projectUrl = do pure $ Aeson.object [ "project" .= locatorProject locator - , "projectId" .= (locatorFetcher locator <> "+" <> locatorProject locator) + , "projectId" .= projectId locator , "revision" .= revision , "branch" .= projectBranch project , "url" .= projectUrl diff --git a/src/Srclib/Types.hs b/src/Srclib/Types.hs index f11c674b57..ce1f79d087 100644 --- a/src/Srclib/Types.hs +++ b/src/Srclib/Types.hs @@ -20,6 +20,7 @@ module Srclib.Types ( renderLocator, parseLocator, pathToOriginPath, + projectId, someBaseToOriginPath, somePathToOriginPath, emptyLicenseUnit, @@ -410,6 +411,10 @@ renderLocator :: Locator -> Text renderLocator Locator{..} = locatorFetcher <> "+" <> locatorProject <> "$" <> fromMaybe "" locatorRevision +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 From 70daff0f952fea4eb4322370864f29e72111da99 Mon Sep 17 00:00:00 2001 From: spatten Date: Tue, 3 Sep 2024 12:05:50 -0700 Subject: [PATCH 6/6] add a comment --- src/Srclib/Types.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Srclib/Types.hs b/src/Srclib/Types.hs index ce1f79d087..c6155bd442 100644 --- a/src/Srclib/Types.hs +++ b/src/Srclib/Types.hs @@ -411,6 +411,7 @@ renderLocator :: Locator -> Text renderLocator Locator{..} = locatorFetcher <> "+" <> locatorProject <> "$" <> fromMaybe "" locatorRevision +-- The projectId is the full locator of the project. E.g. custom+123/someProject (+/) projectId :: Locator -> Text projectId Locator{..} = locatorFetcher <> "+" <> locatorProject