Skip to content

Feat/sp 4373 project service#14

Merged
agustingroh merged 2 commits intomainfrom
feat/SP-4373-project-service
Apr 30, 2026
Merged

Feat/sp 4373 project service#14
agustingroh merged 2 commits intomainfrom
feat/SP-4373-project-service

Conversation

@agustingroh
Copy link
Copy Markdown
Contributor

@agustingroh agustingroh commented Apr 30, 2026

Summary by CodeRabbit

  • New Features

    • Project lookup service now available with support for PURL-based queries.
    • Enhanced project data model includes source information and repository tracking.
  • Breaking Changes

    • Existing project query method has been renamed; update your implementation accordingly.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@agustingroh has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 38 minutes and 4 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a47a59fc-57ae-4319-80fd-7af52b8844e4

📥 Commits

Reviewing files that changed from the base of the PR and between 78eedfc and 671b8cb.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • internal/testutils/mock/mines.sql
  • pkg/models/projects.go
  • pkg/models/projects_test.go
  • pkg/scanoss/client.go
  • pkg/services/project.go
  • pkg/types/types.go
📝 Walkthrough

Walkthrough

Introduces new project data access functionality with a ProjectService, adds a project lookup method by PURL name and type, creates a public Project response type with nullable source fields, renames GetProjectByPurlName to GetProjectByPurlNameAndMineID, and adds an ErrProjectNotFound error.

Changes

Cohort / File(s) Summary
Release Documentation
CHANGELOG.md
Documents 0.10.0 release with ProjectService, new PURL name/type lookup method, Project response type with nullable source fields, ErrProjectNotFound error, and breaking API change renaming GetProjectByPurlName to GetProjectByPurlNameAndMineID.
Database Schema
internal/testutils/mock/mines.sql
Adds repository_url column (TEXT with empty-string default) to mines table.
Project Model
pkg/models/projects.go, pkg/models/projects_test.go
Expands Project struct with MineID, PurlType, Vendor, and source metadata fields; renames GetProjectByPurlName to GetProjectByPurlNameAndMineID; adds new GetProjectByPurlName(purlName, purlType) method with updated SQL joins for source mine data.
Service Layer & Client
pkg/services/project.go, pkg/scanoss/client.go
Introduces ProjectService with GetProject method that validates and parses PURL, queries the model layer, and converts results to types.Project; adds ErrProjectNotFound error; integrates ProjectService into Client initialization.
Public Types
pkg/types/types.go
Adds public Project type with mine ID, PURL name/type, vendor, component, license fields, and nullable source-mine pointer fields for missing database values.

Sequence Diagram(s)

sequenceDiagram
    actor Client
    participant ProjectService
    participant ProjectModel
    participant Database
    participant TypeConversion as types.Project

    Client->>ProjectService: GetProject(purl)
    ProjectService->>ProjectService: Validate & parse PURL
    ProjectService->>ProjectModel: GetProjectByPurlName(purlName, purlType)
    ProjectModel->>Database: SELECT with mines join
    Database-->>ProjectModel: Project row with source fields
    ProjectModel-->>ProjectService: models.Project
    ProjectService->>TypeConversion: Convert to types.Project
    TypeConversion-->>ProjectService: types.Project (or ErrProjectNotFound)
    ProjectService-->>Client: types.Project, error
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • chore(search):SP-4143 enhance PURL search #10 — Modifies project/PURL lookup logic and ProjectModel surface by removing CheckPurlByNameType and moving it to AllUrlsModel; directly related to the new purl-type-aware getters introduced here.

Suggested reviewers

  • isasmendiagus

Poem

🐰 A project lookup, now complete,
With PURL types and sources sweet,
Service layer dances free,
New methods bloom like clover's tree—
The API grows with grace and might! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Feat/sp 4373 project service' accurately describes the main change - introducing a new ProjectService with project lookup functionality across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/SP-4373-project-service

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 38 minutes and 4 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@agustingroh agustingroh force-pushed the feat/SP-4373-project-service branch from fd29acb to 78eedfc Compare April 30, 2026 15:12
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/models/projects.go (1)

155-164: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Inconsistent "not found" behavior between methods.

GetProjectByPurlNameAndMineID returns an empty Project{} with nil error when no rows match, while GetProjectByPurlName returns sql.ErrNoRows. This inconsistency could confuse callers—one must check the struct for emptiness, the other checks the error.

Consider aligning the behavior by returning sql.ErrNoRows when rows.Next() is false:

Proposed fix
 	var project Project
 	if rows.Next() {
 		err = rows.StructScan(&project)
 		if err != nil {
 			s.Errorf("Failed to parse projects table results for %#v: %v", rows, err)
 			s.Errorf("Query failed for purl_name = %v, mine_id = %v", purlName, mineID)
 			return Project{}, fmt.Errorf("failed to query the projects table: %v", err)
 		}
+	} else {
+		return Project{}, sql.ErrNoRows
 	}
 	return project, nil
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/models/projects.go` around lines 155 - 164, GetProjectByPurlNameAndMineID
currently returns an empty Project with nil error when rows.Next() is false;
change it to return sql.ErrNoRows in that case to match GetProjectByPurlName.
Specifically, in GetProjectByPurlNameAndMineID check the result of rows.Next()
and if false return Project{} and sql.ErrNoRows (instead of nil), keeping the
existing error handling for StructScan unchanged so callers receive a consistent
"not found" error.
🧹 Nitpick comments (2)
pkg/models/projects_test.go (1)

29-101: ⚡ Quick win

Missing test coverage for GetProjectByPurlName(purlName, purlType).

The new GetProjectByPurlName method (used by ProjectService.GetProject) is not exercised by this test suite. Consider adding test cases covering:

  • Successful lookup with valid purlName + purlType
  • sql.ErrNoRows when project doesn't exist
  • Empty purlName/purlType validation errors
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/models/projects_test.go` around lines 29 - 101, Add unit tests in
pkg/models/projects_test.go that exercise the new GetProjectByPurlName method
(used by ProjectService.GetProject): reuse the existing projectsModel :=
NewProjectModel(db) and ctx setup, then add three subtests: (1) a successful
lookup calling projectsModel.GetProjectByPurlName(ctx, "tablestyle", "gem") and
assert no error and non-empty result; (2) a non-existent lookup calling
GetProjectByPurlName with a bogus name/type and assert the error is
sql.ErrNoRows; and (3) validation checks calling GetProjectByPurlName with empty
purlName and/or empty purlType and assert a validation error is returned. Ensure
tests import database/sql for sql.ErrNoRows and follow the existing pattern for
setup/teardown and error assertions.
pkg/models/projects.go (1)

74-103: 💤 Low value

Consider extracting the shared query columns.

The SELECT column list is duplicated across three methods (GetProjectsByPurlName, GetProjectByPurlNameAndMineID, GetProjectByPurlName). If a column is added or renamed, all three must be updated in sync.

Extracting the common column list into a constant would reduce duplication and maintenance burden.

Also applies to: 117-139, 182-206

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/models/projects.go` around lines 74 - 103, The SELECT column list is
duplicated in GetProjectsByPurlName, GetProjectByPurlNameAndMineID and
GetProjectByPurlName—extract that repeated column list into a single
package-level constant (e.g., projectSelectCols) and concatenate it into the SQL
strings in those three methods; update each method to replace the inline SELECT
... column block with the constant, preserve the same JOIN/WHERE fragments and
parameter placeholders, and run tests to ensure the SQL formatting/spacing and
returned fields (used by structs like the one scanned into allProjects) remain
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@pkg/models/projects.go`:
- Around line 155-164: GetProjectByPurlNameAndMineID currently returns an empty
Project with nil error when rows.Next() is false; change it to return
sql.ErrNoRows in that case to match GetProjectByPurlName. Specifically, in
GetProjectByPurlNameAndMineID check the result of rows.Next() and if false
return Project{} and sql.ErrNoRows (instead of nil), keeping the existing error
handling for StructScan unchanged so callers receive a consistent "not found"
error.

---

Nitpick comments:
In `@pkg/models/projects_test.go`:
- Around line 29-101: Add unit tests in pkg/models/projects_test.go that
exercise the new GetProjectByPurlName method (used by
ProjectService.GetProject): reuse the existing projectsModel :=
NewProjectModel(db) and ctx setup, then add three subtests: (1) a successful
lookup calling projectsModel.GetProjectByPurlName(ctx, "tablestyle", "gem") and
assert no error and non-empty result; (2) a non-existent lookup calling
GetProjectByPurlName with a bogus name/type and assert the error is
sql.ErrNoRows; and (3) validation checks calling GetProjectByPurlName with empty
purlName and/or empty purlType and assert a validation error is returned. Ensure
tests import database/sql for sql.ErrNoRows and follow the existing pattern for
setup/teardown and error assertions.

In `@pkg/models/projects.go`:
- Around line 74-103: The SELECT column list is duplicated in
GetProjectsByPurlName, GetProjectByPurlNameAndMineID and
GetProjectByPurlName—extract that repeated column list into a single
package-level constant (e.g., projectSelectCols) and concatenate it into the SQL
strings in those three methods; update each method to replace the inline SELECT
... column block with the constant, preserve the same JOIN/WHERE fragments and
parameter placeholders, and run tests to ensure the SQL formatting/spacing and
returned fields (used by structs like the one scanned into allProjects) remain
unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d42d7c4c-29a3-49ba-a2e8-3dd44431093c

📥 Commits

Reviewing files that changed from the base of the PR and between 16165f8 and 78eedfc.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • internal/testutils/mock/mines.sql
  • pkg/models/projects.go
  • pkg/models/projects_test.go
  • pkg/scanoss/client.go
  • pkg/services/project.go
  • pkg/types/types.go

@agustingroh agustingroh force-pushed the feat/SP-4373-project-service branch from 78eedfc to 671b8cb Compare April 30, 2026 15:34
Copy link
Copy Markdown

@scanoss-qg scanoss-qg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@agustingroh agustingroh merged commit acbc743 into main Apr 30, 2026
3 checks passed
@agustingroh agustingroh deleted the feat/SP-4373-project-service branch April 30, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants