Skip to content

Commit

Permalink
add and use a projectId function
Browse files Browse the repository at this point in the history
  • Loading branch information
spatten committed Sep 3, 2024
1 parent 2b07903 commit c386165
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
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
3 changes: 2 additions & 1 deletion 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,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
Expand Down
5 changes: 5 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,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
Expand Down

0 comments on commit c386165

Please sign in to comment.