From c38616552631992f05841c3ebc89659548901fd9 Mon Sep 17 00:00:00 2001 From: spatten Date: Tue, 3 Sep 2024 11:58:56 -0700 Subject: [PATCH] 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