Skip to content

Commit

Permalink
make getProject take an issue locator type too
Browse files Browse the repository at this point in the history
  • Loading branch information
spatten committed May 29, 2024
1 parent c753995 commit 99fafc5
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/App/Fossa/API/BuildWait.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ waitForScanCompletion ::
m ()
waitForScanCompletion revision locatorType cancelFlag = do
-- Route is new, this may fail on on-prem if they haven't updated
project <- recover $ getProject revision
project <- recover $ getProject revision locatorType
if maybe False projectIsMonorepo project
then fatalText "The project you are attempting to test is a monorepo project. Monorepo projects are no longer supported by FOSSA."
else waitForBuild revision locatorType cancelFlag
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 @@ -15,6 +15,7 @@ import App.Fossa.Reachability.Upload (upload)
import App.Types (
BaseDir (BaseDir),
FileUpload,
IssueLocatorType (..),
ProjectMetadata,
ProjectRevision (..),
)
Expand Down Expand Up @@ -186,7 +187,7 @@ uploadAnalysisWithFirstPartyLicensesToS3 revision mergedUnits = do

dieOnMonorepoUpload :: (Has Diagnostics sig m, Has FossaApiClient sig m) => ProjectRevision -> m ()
dieOnMonorepoUpload revision = do
project <- recover $ getProject revision
project <- recover $ getProject revision IssueLocatorCustom
when (maybe False projectIsMonorepo project) $
fatalText "This project already exists as a monorepo project. Monorepo projects are no longer supported; please create a new project instead."

Expand Down
2 changes: 1 addition & 1 deletion src/Control/Carrier/FossaApiClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ runFossaApiClient apiOpts =
GetRevisionDependencyCacheStatus rev -> Core.getRevisionDependencyCacheStatus rev
GetOrganization -> Core.getOrganization
GetPolicies -> Core.getPolicies
GetProject rev -> Core.getProject rev
GetProject rev locatorType -> Core.getProject rev locatorType
GetTeams -> Core.getTeams
AddTeamProjects teamId req -> Core.addTeamProjects teamId req
GetAnalyzedRevisions vdeps -> Core.getAnalyzedRevisions vdeps
Expand Down
5 changes: 3 additions & 2 deletions src/Control/Carrier/FossaApiClient/Internal/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ getProject ::
, Has (Reader ApiOpts) sig m
) =>
ProjectRevision ->
IssueLocatorType ->
m Project
getProject revision = do
getProject revision locatorType = do
apiOpts <- ask
API.getProject apiOpts revision
API.getProject apiOpts revision locatorType

getAnalyzedRevisions ::
( Has (Lift IO) sig m
Expand Down
5 changes: 3 additions & 2 deletions src/Control/Carrier/FossaApiClient/Internal/FossaAPIV1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -862,13 +862,14 @@ getProject ::
) =>
ApiOpts ->
ProjectRevision ->
IssueLocatorType ->
m Project
getProject apiopts ProjectRevision{..} = fossaReq $ do
getProject apiopts ProjectRevision{..} locatorType = fossaReq $ do
(baseurl, baseopts) <- useApiOpts apiopts

orgid <- organizationId <$> getOrganization apiopts

let endpoint = projectEndpoint baseurl orgid $ Locator "custom" projectName Nothing
let endpoint = projectEndpoint baseurl orgid $ Locator (toText locatorType) projectName Nothing

responseBody <$> req GET endpoint NoReqBody jsonResponse baseopts

Expand Down
6 changes: 3 additions & 3 deletions src/Control/Effect/FossaApiClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ data FossaApiClientF a where
GetLatestBuild :: ProjectRevision -> IssueLocatorType -> FossaApiClientF Build
GetOrganization :: FossaApiClientF Organization
GetPolicies :: FossaApiClientF [CoreTypes.Policy]
GetProject :: ProjectRevision -> FossaApiClientF Project
GetProject :: ProjectRevision -> IssueLocatorType -> FossaApiClientF Project
GetTeams :: FossaApiClientF [CoreTypes.Team]
GetAnalyzedRevisions :: NonEmpty VendoredDependency -> FossaApiClientF [Text]
GetAnalyzedPathRevisions :: ProjectRevision -> FossaApiClientF [AnalyzedPathDependency]
Expand Down Expand Up @@ -190,8 +190,8 @@ getOrganization :: (Has FossaApiClient sig m) => m Organization
getOrganization = sendSimple GetOrganization

-- | Fetches the project associated with a revision
getProject :: (Has FossaApiClient sig m) => ProjectRevision -> m Project
getProject = sendSimple . GetProject
getProject :: (Has FossaApiClient sig m) => ProjectRevision -> IssueLocatorType -> m Project
getProject revision locatorType = sendSimple $ GetProject revision locatorType

-- | Returns the API options currently in scope.
-- The API options contain a lot of information required to build URLs.
Expand Down
2 changes: 1 addition & 1 deletion test/App/Fossa/API/BuildWaitSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ expectGetOrganization :: Has MockApi sig m => m ()
expectGetOrganization = GetOrganization `alwaysReturns` Fixtures.organization

expectGetProject :: Has MockApi sig m => m ()
expectGetProject = (GetProject Fixtures.projectRevision) `alwaysReturns` Fixtures.project
expectGetProject = (GetProject Fixtures.projectRevision IssueLocatorCustom) `alwaysReturns` Fixtures.project

expectGetLatestBuild :: Has MockApi sig m => BuildStatus -> m ()
expectGetLatestBuild status =
Expand Down
12 changes: 6 additions & 6 deletions test/App/Fossa/Analyze/UploadSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module App.Fossa.Analyze.UploadSpec (spec) where

import App.Fossa.Analyze.Upload (ScanUnits (..), mergeSourceAndLicenseUnits, uploadSuccessfulAnalysis)
import App.Fossa.Config.Analyze (JsonOutput (JsonOutput))
import App.Types (FileUpload (..))
import App.Types (FileUpload (..), IssueLocatorType (..))
import Control.Algebra (Has)
import Control.Carrier.Git (GitC)
import Control.Carrier.Simple (interpret)
Expand Down Expand Up @@ -39,12 +39,12 @@ expectedLocator = uploadLocator Fixtures.uploadResponse

expectGetSuccess :: Has MockApi sig m => m ()
expectGetSuccess = do
GetProject Fixtures.projectRevision `alwaysReturns` Fixtures.project
GetProject Fixtures.projectRevision IssueLocatorCustom `alwaysReturns` Fixtures.project
GetOrganization `alwaysReturns` Fixtures.organization
GetApiOpts `alwaysReturns` Fixtures.apiOpts

expectGetProject :: Has MockApi sig m => m ()
expectGetProject = GetProject Fixtures.projectRevision `alwaysReturns` Fixtures.project
expectGetProject = GetProject Fixtures.projectRevision IssueLocatorCustom `alwaysReturns` Fixtures.project

expectGetOrganizationWithFullFileUploads :: Has MockApi sig m => m ()
expectGetOrganizationWithFullFileUploads =
Expand Down Expand Up @@ -106,7 +106,7 @@ expectedMergedFullSourceUnits = NE.fromList [fullSourceUnit, fullLicenseUnit]

expectGetSuccessWithReachability :: Has MockApi sig m => m ()
expectGetSuccessWithReachability = do
GetProject Fixtures.projectRevision `alwaysReturns` Fixtures.project
GetProject Fixtures.projectRevision IssueLocatorCustom `alwaysReturns` Fixtures.project
GetOrganization `alwaysReturns` Fixtures.organization{orgSupportsReachability = True}
GetApiOpts `alwaysReturns` Fixtures.apiOpts

Expand Down Expand Up @@ -178,7 +178,7 @@ uploadSuccessfulAnalysisSpec = do
. expectFatal'
. withGit mockGit
$ do
GetProject Fixtures.projectRevision `returnsOnce` Fixtures.project{projectIsMonorepo = True}
GetProject Fixtures.projectRevision IssueLocatorCustom `returnsOnce` Fixtures.project{projectIsMonorepo = True}
uploadSuccessfulAnalysis
baseDir
Fixtures.projectMetadata
Expand All @@ -189,7 +189,7 @@ uploadSuccessfulAnalysisSpec = do
it' "continues if fetching the project fails"
. withGit mockGit
$ do
GetProject Fixtures.projectRevision `fails` "Mocked failure fetching project"
GetProject Fixtures.projectRevision IssueLocatorCustom `fails` "Mocked failure fetching project"
expectAnalysisUploadSuccess
expectContributorUploadSuccess
GetOrganization `alwaysReturns` Fixtures.organization
Expand Down
6 changes: 3 additions & 3 deletions test/App/Fossa/ReportSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ parseReportOutputSpec =

expectBuildSuccess :: (Has MockApi sig m) => m ()
expectBuildSuccess = do
(GetProject Fixtures.projectRevision) `returnsOnce` Fixtures.project
(GetProject Fixtures.projectRevision IssueLocatorCustom) `returnsOnce` Fixtures.project
(GetLatestBuild Fixtures.projectRevision IssueLocatorCustom) `returnsOnce` Fixtures.successfulBuild

expectBuildPending :: (Has MockApi sig m) => m ()
expectBuildPending = do
GetApiOpts `alwaysReturns` Fixtures.apiOpts -- It needs to fetch the poll delay
(GetProject Fixtures.projectRevision) `returnsOnce` Fixtures.project
(GetProject Fixtures.projectRevision IssueLocatorCustom) `returnsOnce` Fixtures.project
(GetLatestBuild Fixtures.projectRevision IssueLocatorCustom) `alwaysReturns` Fixtures.pendingBuild

expectBuildError :: (Has MockApi sig m) => m ()
expectBuildError = do
(GetProject Fixtures.projectRevision) `returnsOnce` Fixtures.project
(GetProject Fixtures.projectRevision IssueLocatorCustom) `returnsOnce` Fixtures.project
(GetLatestBuild Fixtures.projectRevision IssueLocatorCustom) `fails` "Mock failure: GetLatestBuild"

expectFetchIssuesSuccess :: (Has MockApi sig m) => m ()
Expand Down

0 comments on commit 99fafc5

Please sign in to comment.