Release groups: resolve add-projects target via server-side lookup (CORE-7241)#1728
Conversation
WalkthroughAdds a faster server-side lookup path for Changes
Sequence Diagram(s)sequenceDiagram
participant AddProjectsMain
participant FossaApiClient
participant Core
participant FossaAPIV1
AddProjectsMain->>FossaApiClient: getOrganization
FossaApiClient-->>AddProjectsMain: Organization
alt orgSupportsFasterReleaseGroupAddProjects = True
AddProjectsMain->>FossaApiClient: resolveReleaseGroupRelease(rgTitle, releaseTitle)
FossaApiClient->>Core: resolveReleaseGroupRelease
Core->>FossaAPIV1: resolveReleaseGroupRelease
FossaAPIV1-->>Core: ReleaseGroupReleaseLookup
Core-->>AddProjectsMain: releaseGroupId, releaseId
else fallback
AddProjectsMain->>FossaApiClient: getReleaseGroups
AddProjectsMain->>FossaApiClient: getReleaseGroupReleases
FossaApiClient-->>AddProjectsMain: releaseGroupId, releaseId
end
AddProjectsMain->>FossaApiClient: updateReleaseGroupRelease(payload)
FossaApiClient-->>AddProjectsMain: updated release
Related PRs: None identified. Suggested labels: enhancement, api Suggested reviewers: None identified. Poem: A rabbit hopped down the lookup road, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/App/Fossa/ReleaseGroup/AddProjects.hs`:
- Around line 33-53: Add test coverage for the server-side lookup failure path
in AddProjectsSpec by exercising the orgSupportsFasterReleaseGroupAddProjects
branch in AddProjects and asserting the behavior when resolveReleaseGroupRelease
fails or returns no match. Reuse the existing fast-lookup setup around
ResolveReleaseGroupRelease and verify the error-handling path matches the
intended fatal/context behavior, similar to the existing fallback failure tests
for retrieveReleaseGroupId and retrieveReleaseGroupRelease.
In `@test/App/Fossa/API/BuildLinkSpec.hs`:
- Around line 45-61: The test fixtures in BuildLinkSpec still construct
Organization with a long positional list of fields, which is brittle and
obscures the intent of orgSupportsFasterReleaseGroupAddProjects. Update the org
values in the affected getBuildURLWithOrg tests to use named-field record syntax
for Organization, keeping the same field values but making the relevant flag
explicit and easier to maintain as Organization evolves.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Pro
Run ID: bc9866f2-dff3-40e1-995c-282fc6958fc2
📒 Files selected for processing (12)
Changelog.mdsrc/App/Fossa/ReleaseGroup/AddProjects.hssrc/Control/Carrier/FossaApiClient.hssrc/Control/Carrier/FossaApiClient/Internal/Core.hssrc/Control/Carrier/FossaApiClient/Internal/FossaAPIV1.hssrc/Control/Effect/FossaApiClient.hssrc/Fossa/API/CoreTypes.hssrc/Fossa/API/Types.hstest/App/Fossa/API/BuildLinkSpec.hstest/App/Fossa/ReleaseGroup/AddProjectsSpec.hstest/Test/Fixtures.hstest/Test/MockApi.hs
…syntax Organization fixtures in BuildLinkSpec
| <*> obj .:? "supportsGitBackedCargoLocators" .!= False | ||
| <*> obj .:? "subscription" .!= Free | ||
| <*> obj .:? "snippetScanSourceCodeRetentionDays" .!= Nothing | ||
| <*> obj .:? "supportsFasterRGAddProject" .!= False |
There was a problem hiding this comment.
[nit] is there a reason why we abbreviate this one while the others are fully spelled out?
There was a problem hiding this comment.
It's abbreviated in the API response, but it seemed like most other variables in the CLI are expanded so I just went with the flow.
Overview
fossa release-group add-projectsresolves its target release by first listingevery release group (
GET /api/project_group) and then every release inthe matched group with all of their projects (
GET /api/project_group/:id/release),filtering by title client-side. For organizations with large numbers of release groups
and releases, those responses are large enough to time out.
This change makes the CLI resolve the release group + release titles to their numeric
ids in a single request against a new endpoint,
GET /api/cli/project_group/release_lookup,which filters in the database and returns only the ids. The CLI gates on a new
supportsFasterRGAddProjectcapability flag fromGET /api/cli/organization: when theconnected FOSSA instance advertises it, the CLI uses the lookup; otherwise it falls back
to the existing list-and-filter behavior, so older FOSSA instances are unaffected.
It also drops the now-unused
projectGroupReleaseIdfield from the release updaterequest. Core determines whether each project is new or an update from its own database,
so the CLI no longer needs to fetch the release's current projects to compute it.
Acceptance criteria
supportsFasterRGAddProject,fossa release-group add-projectsresolves its target with one lookup request insteadof listing all release groups and releases, so it no longer times out for large orgs.
Testing plan
(fossas/FOSSA#18308, which returns
supportsFasterRGAddProject: true), using a full-access API token:--debug, and by watching the Core server logs, that it callsGET /api/cli/project_group/release_lookuprather than the fullGET /api/project_grouplist, and that the projects are added.
supportsFasterRGAddProject: falseinroutes/cli/v0.ts(and restartCore), then run the same command; confirm from
--debugand the server logs that it usesGET /api/project_group+GET /api/project_group/:id/release, and the result is unchanged.Risks
projectGroupReleaseIdfrom the update body (it previously sentthe release id for already-present projects). This is safe because Core computes
add-vs-update from its own database and never read the field; the paired Core PR removes it
from the request schema. Worth a reviewer sanity check that the update body is accepted.
unchanged fallback, so there is no behavior change for older FOSSA deployments.
Metrics
Not tracked by the CLI. The change reduces API payload size and request count for
add-projects(two list calls -> one id lookup), which is what eliminates the timeouts.References
supportsFasterRGAddProjectflag): fossas/FOSSA#18308.Checklist
AddProjectsSpeccovers both the lookup and fallback paths.)docs/change.Changelog.md: added an## Unreleasedentry..fossa.yml/fossa-deps: not changed.release-group add-projectsflags are unchanged, so nodocs/references/subcommandsupdate.