Skip to content

Conversation

@ahmedxgouda
Copy link
Collaborator

Resolves #1666

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 28, 2025

Summary by CodeRabbit

  • New Features

    • Added filtering and pagination support to project health metrics in the GraphQL API.
    • Introduced a new filterable field for project health metrics, including filtering by project level and score.
    • Exposed the associated project's name in the project health metrics GraphQL schema.
  • Bug Fixes

    • None.
  • Tests

    • Added and enhanced tests to cover new filter functionality, field exposure, and query behaviors for project health metrics.

Walkthrough

This change introduces a new GraphQL query field for retrieving project health metrics with filtering and pagination support. It adds a Strawberry-Django filter class for ProjectHealthMetrics, enables filtering by project level and score, updates the corresponding GraphQL node and query, and provides comprehensive tests for the new filter and query functionality.

Changes

Files/Paths Change Summary
backend/apps/owasp/graphql/filters/project_health_metrics.py Added ProjectHealthMetricsFilter class with score and custom level filter for GraphQL.
backend/apps/owasp/graphql/nodes/project_health_metrics.py Enhanced ProjectHealthMetricsNode with filter/pagination support and added project_name field.
backend/apps/owasp/graphql/queries/project_health_metrics.py Added project_health_metrics query field with filtering; updated docstring for stats resolver.
backend/tests/apps/owasp/graphql/filters/project_health_metrics_test.py New test module for ProjectHealthMetricsFilter, covering field presence and initialization.
backend/tests/apps/owasp/graphql/nodes/project_health_metrics_test.py Updated tests to check for new project_name field in the node.
backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py Refactored and parameterized tests for new/existing fields; added tests for new query resolver.

Assessment against linked issues

Objective Addressed Explanation
Implement a resolver that returns project health metrics with filters (need attention, healthy, unhealthy, filter by level) (#1666)
Add additional filters for leaders, contributors, funding, recent commits/releases (#1666) Only level and score filters are implemented; others are not present.
Consider filter for high scores with issues (#1666) No explicit filter for high scores with issues is implemented.

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Addition of project_name field and resolver in ProjectHealthMetricsNode (nodes/project_health_metrics.py) The linked issue does not request exposing the project name as a field on the metrics node.

Possibly related PRs

Suggested reviewers

  • arkid15r

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76d1312 and 7ed3923.

📒 Files selected for processing (6)
  • backend/apps/owasp/graphql/filters/project_health_metrics.py (1 hunks)
  • backend/apps/owasp/graphql/nodes/project_health_metrics.py (3 hunks)
  • backend/apps/owasp/graphql/queries/project_health_metrics.py (2 hunks)
  • backend/tests/apps/owasp/graphql/filters/project_health_metrics_test.py (1 hunks)
  • backend/tests/apps/owasp/graphql/nodes/project_health_metrics_test.py (2 hunks)
  • backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py (2 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: ahmedxgouda
PR: OWASP/Nest#1676
File: backend/apps/owasp/graphql/filters/project_health_metrics.py:17-22
Timestamp: 2025-06-29T00:41:32.169Z
Learning: In the OWASP Nest codebase, when implementing GraphQL filters that convert string values to enums (like ProjectLevel), do not catch ValueError exceptions for invalid values. Let the errors propagate to provide proper error responses to GraphQL clients rather than silently ignoring invalid input.
backend/apps/owasp/graphql/queries/project_health_metrics.py (1)
Learnt from: ahmedxgouda
PR: OWASP/Nest#1676
File: backend/apps/owasp/graphql/filters/project_health_metrics.py:17-22
Timestamp: 2025-06-29T00:41:32.169Z
Learning: In the OWASP Nest codebase, when implementing GraphQL filters that convert string values to enums (like ProjectLevel), do not catch ValueError exceptions for invalid values. Let the errors propagate to provide proper error responses to GraphQL clients rather than silently ignoring invalid input.
backend/apps/owasp/graphql/nodes/project_health_metrics.py (1)
Learnt from: ahmedxgouda
PR: OWASP/Nest#1676
File: backend/apps/owasp/graphql/filters/project_health_metrics.py:17-22
Timestamp: 2025-06-29T00:41:32.169Z
Learning: In the OWASP Nest codebase, when implementing GraphQL filters that convert string values to enums (like ProjectLevel), do not catch ValueError exceptions for invalid values. Let the errors propagate to provide proper error responses to GraphQL clients rather than silently ignoring invalid input.
backend/apps/owasp/graphql/filters/project_health_metrics.py (1)
Learnt from: ahmedxgouda
PR: OWASP/Nest#1676
File: backend/apps/owasp/graphql/filters/project_health_metrics.py:17-22
Timestamp: 2025-06-29T00:41:32.169Z
Learning: In the OWASP Nest codebase, when implementing GraphQL filters that convert string values to enums (like ProjectLevel), do not catch ValueError exceptions for invalid values. Let the errors propagate to provide proper error responses to GraphQL clients rather than silently ignoring invalid input.
backend/tests/apps/owasp/graphql/filters/project_health_metrics_test.py (1)
Learnt from: ahmedxgouda
PR: OWASP/Nest#1676
File: backend/apps/owasp/graphql/filters/project_health_metrics.py:17-22
Timestamp: 2025-06-29T00:41:32.169Z
Learning: In the OWASP Nest codebase, when implementing GraphQL filters that convert string values to enums (like ProjectLevel), do not catch ValueError exceptions for invalid values. Let the errors propagate to provide proper error responses to GraphQL clients rather than silently ignoring invalid input.
backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py (1)
Learnt from: ahmedxgouda
PR: OWASP/Nest#1676
File: backend/apps/owasp/graphql/filters/project_health_metrics.py:17-22
Timestamp: 2025-06-29T00:41:32.169Z
Learning: In the OWASP Nest codebase, when implementing GraphQL filters that convert string values to enums (like ProjectLevel), do not catch ValueError exceptions for invalid values. Let the errors propagate to provide proper error responses to GraphQL clients rather than silently ignoring invalid input.
🧬 Code Graph Analysis (5)
backend/apps/owasp/graphql/queries/project_health_metrics.py (3)
backend/apps/owasp/graphql/filters/project_health_metrics.py (1)
  • ProjectHealthMetricsFilter (12-22)
backend/apps/owasp/graphql/nodes/project_health_metrics.py (1)
  • ProjectHealthMetricsNode (30-76)
backend/apps/owasp/graphql/nodes/project_health_stats.py (1)
  • ProjectHealthStatsNode (7-20)
backend/apps/owasp/graphql/nodes/project_health_metrics.py (1)
backend/apps/owasp/graphql/filters/project_health_metrics.py (1)
  • ProjectHealthMetricsFilter (12-22)
backend/apps/owasp/graphql/filters/project_health_metrics.py (2)
backend/apps/owasp/models/enums/project.py (1)
  • ProjectLevel (27-34)
backend/apps/owasp/models/project_health_metrics.py (1)
  • ProjectHealthMetrics (16-210)
backend/tests/apps/owasp/graphql/filters/project_health_metrics_test.py (2)
backend/apps/owasp/graphql/filters/project_health_metrics.py (1)
  • ProjectHealthMetricsFilter (12-22)
backend/apps/owasp/models/enums/project.py (1)
  • ProjectLevel (27-34)
backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py (3)
backend/apps/owasp/graphql/nodes/project_health_metrics.py (1)
  • ProjectHealthMetricsNode (30-76)
backend/apps/owasp/graphql/queries/project_health_metrics.py (2)
  • project_health_stats (22-29)
  • ProjectHealthMetricsQuery (13-29)
backend/apps/owasp/graphql/nodes/project_health_stats.py (1)
  • ProjectHealthStatsNode (7-20)
🪛 Pylint (3.3.7)
backend/apps/owasp/graphql/queries/project_health_metrics.py

[error] 4-4: Unable to import 'strawberry_django'

(E0401)

backend/apps/owasp/graphql/nodes/project_health_metrics.py

[error] 71-71: Instance of 'ProjectHealthMetricsNode' has no 'project' member

(E1101)

backend/apps/owasp/graphql/filters/project_health_metrics.py

[error] 3-3: Unable to import 'strawberry'

(E0401)


[error] 4-4: Unable to import 'strawberry_django'

(E0401)


[error] 5-5: Unable to import 'django.db.models'

(E0401)


[warning] 20-20: Unused argument 'prefix'

(W0613)


[refactor] 12-12: Too few public methods (1/2)

(R0903)

backend/tests/apps/owasp/graphql/filters/project_health_metrics_test.py

[error] 17-17: Class 'ProjectHealthMetricsFilter' has no 'strawberry_definition' member

(E1101)


[warning] 25-25: Comparing against a callable, did you omit the parenthesis?

(W0143)

backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py

[error] 27-27: Class 'ProjectHealthMetricsQuery' has no 'strawberry_definition' member

(E1101)


[error] 42-42: Class 'ProjectHealthMetricsQuery' has no 'strawberry_definition' member

(E1101)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Run frontend unit tests
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run backend tests
  • GitHub Check: CodeQL (javascript-typescript)
🔇 Additional comments (11)
backend/apps/owasp/graphql/filters/project_health_metrics.py (1)

11-22: Well-implemented filter class following GraphQL best practices.

The filter implementation correctly:

  • Uses automatic field filtering for score
  • Implements custom level filter that properly converts string to ProjectLevel enum
  • Follows the established pattern of letting ValueError propagate for invalid enum values, providing proper error responses to GraphQL clients

The static analysis warnings about unused prefix parameter and import errors are false positives - prefix is required by the strawberry framework, and the imports are valid at runtime.

backend/tests/apps/owasp/graphql/nodes/project_health_metrics_test.py (1)

33-33: Test updates correctly reflect the new project_name field.

The additions properly include the new project_name field in both the expected fields validation and the parameterized type checking tests.

Also applies to: 69-69

backend/apps/owasp/graphql/nodes/project_health_metrics.py (2)

8-8: Excellent integration of filtering and pagination capabilities.

The addition of ProjectHealthMetricsFilter and pagination=True properly enables filtering and pagination support for the GraphQL node.

Also applies to: 27-28


68-71: Clean implementation of the project_name field resolver.

The new field resolver correctly exposes the associated project's name through the Django model relationship.

The static analysis warning about no 'project' member is a false positive - this is a valid Django model relationship that exists at runtime.

backend/tests/apps/owasp/graphql/filters/project_health_metrics_test.py (1)

7-26: Comprehensive test coverage for the filter class.

The tests properly verify:

  • Strawberry GraphQL definition integration
  • Expected filter fields presence (score and level)
  • Correct initialization and enum conversion for the level filter

The static analysis warnings are false positives - strawberry definitions exist at runtime, and the enum comparison is valid.

backend/apps/owasp/graphql/queries/project_health_metrics.py (3)

4-7: Proper imports for enhanced GraphQL functionality.

The imports correctly bring in the necessary components for filtering support.


16-19: Well-designed filterable query field.

The new project_health_metrics field properly integrates with the ProjectHealthMetricsFilter to enable filtering capabilities and includes a clear description for the GraphQL schema.


26-26: Improved documentation clarity.

The updated docstring clearly specifies the return type, enhancing code readability and maintainability.

backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py (3)

5-7: Good addition of imports for enhanced testing.

The pytest import enables parameterized testing and the ProjectHealthMetricsNode import supports the new test functionality.


15-29: Excellent use of parameterized testing for field existence.

The parameterized approach for testing both project_health_stats and project_health_metrics fields makes the test more maintainable and comprehensive.


31-46: Well-structured parameterized test for field configuration.

The test properly validates that both fields have the correct types in the Strawberry definition using appropriate type checking logic.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in a Comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py (1)

125-140: Simplify the project health metrics test.

The test logic is straightforward but could be cleaner.

Consider testing the actual field access pattern:

def test_resolve_project_health_metrics(self):
    """Test resolving project health metrics."""
-   metrics = [
-       ProjectHealthMetrics(
-           score=85.0,
-           stars_count=1000,
-           forks_count=200,
-       )
-   ]
-   query = ProjectHealthMetricsQuery(project_health_metrics=metrics)
-   result = query.project_health_metrics
-   assert isinstance(result, list)
-   assert len(result) == 1
-   assert result[0].stars_count == 1000
-   assert result[0].score == 85.0
+   query = ProjectHealthMetricsQuery()
+   # Test that the field exists and has correct type annotation
+   assert hasattr(query, 'project_health_metrics')
+   field = next(f for f in query.__strawberry_definition__.fields if f.name == 'project_health_metrics')
+   assert field.filters is not None  # Verify filtering is enabled
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d46f15f and 53eae73.

📒 Files selected for processing (9)
  • backend/apps/owasp/graphql/filters/project_health_metrics.py (1 hunks)
  • backend/apps/owasp/graphql/nodes/health_stats.py (1 hunks)
  • backend/apps/owasp/graphql/nodes/project_health_metrics.py (3 hunks)
  • backend/apps/owasp/graphql/queries/__init__.py (2 hunks)
  • backend/apps/owasp/graphql/queries/project_health_metrics.py (1 hunks)
  • backend/apps/owasp/models/project_health_metrics.py (2 hunks)
  • backend/tests/apps/owasp/graphql/nodes/health_stats_test.py (1 hunks)
  • backend/tests/apps/owasp/graphql/nodes/project_health_metrics_test.py (2 hunks)
  • backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (6)
backend/apps/owasp/graphql/queries/__init__.py (1)
backend/apps/owasp/graphql/queries/project_health_metrics.py (1)
  • ProjectHealthMetricsQuery (15-31)
backend/apps/owasp/graphql/nodes/project_health_metrics.py (1)
backend/apps/owasp/graphql/filters/project_health_metrics.py (1)
  • ProjectHealthMetricsFilter (12-22)
backend/tests/apps/owasp/graphql/nodes/health_stats_test.py (2)
backend/apps/owasp/graphql/queries/project_health_metrics.py (1)
  • health_stats (24-31)
backend/apps/owasp/graphql/nodes/health_stats.py (1)
  • HealthStatsNode (7-20)
backend/apps/owasp/graphql/filters/project_health_metrics.py (2)
backend/apps/owasp/models/enums/project.py (1)
  • ProjectLevel (27-34)
backend/apps/owasp/models/project_health_metrics.py (1)
  • ProjectHealthMetrics (13-198)
backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py (3)
backend/apps/owasp/graphql/queries/project_health_metrics.py (2)
  • health_stats (24-31)
  • ProjectHealthMetricsQuery (15-31)
backend/apps/owasp/graphql/nodes/health_stats.py (1)
  • HealthStatsNode (7-20)
backend/apps/owasp/models/project_health_metrics.py (1)
  • ProjectHealthMetrics (13-198)
backend/apps/owasp/models/project_health_metrics.py (2)
backend/apps/owasp/graphql/queries/project_health_metrics.py (1)
  • health_stats (24-31)
backend/apps/owasp/graphql/nodes/health_stats.py (1)
  • HealthStatsNode (7-20)
🪛 Pylint (3.3.7)
backend/apps/owasp/graphql/nodes/project_health_metrics.py

[error] 71-71: Instance of 'ProjectHealthMetricsNode' has no 'project' member

(E1101)

backend/apps/owasp/graphql/queries/project_health_metrics.py

[refactor] 15-15: Too few public methods (1/2)

(R0903)

backend/tests/apps/owasp/graphql/nodes/health_stats_test.py

[error] 13-13: Class 'HealthStatsNode' has no 'strawberry_definition' member

(E1101)


[error] 33-33: Class 'HealthStatsNode' has no 'strawberry_definition' member

(E1101)

backend/apps/owasp/graphql/nodes/health_stats.py

[refactor] 7-7: Too few public methods (0/2)

(R0903)

backend/apps/owasp/graphql/filters/project_health_metrics.py

[refactor] 12-12: Too few public methods (1/2)

(R0903)

backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py

[error] 29-29: Class 'ProjectHealthMetricsQuery' has no 'strawberry_definition' member

(E1101)


[error] 44-44: Class 'ProjectHealthMetricsQuery' has no 'strawberry_definition' member

(E1101)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Run frontend unit tests
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run backend tests
🔇 Additional comments (9)
backend/apps/owasp/graphql/nodes/health_stats.py (1)

6-20: LGTM! Well-structured GraphQL type definition.

The HealthStatsNode follows GraphQL conventions and provides a comprehensive set of fields for aggregated health statistics. All field types are appropriately chosen for their purposes.

backend/apps/owasp/graphql/queries/__init__.py (1)

8-8: LGTM! Clean integration of the new query class.

The addition of ProjectHealthMetricsQuery follows the established pattern and correctly integrates the new health metrics querying capabilities into the main OWASP GraphQL schema.

Also applies to: 20-20

backend/tests/apps/owasp/graphql/nodes/project_health_metrics_test.py (1)

33-33: LGTM! Appropriate test coverage for the new field.

The test updates correctly include the new project_name field in both the field names verification and type checking, ensuring proper test coverage for the enhancement.

Also applies to: 69-69

backend/apps/owasp/graphql/nodes/project_health_metrics.py (2)

8-8: LGTM! Proper integration of filtering and pagination capabilities.

The addition of ProjectHealthMetricsFilter and pagination follows Strawberry-Django best practices and enhances the GraphQL API with essential querying capabilities.

Also applies to: 27-28


68-71: LGTM! Clean field resolver implementation.

The project_name field resolver correctly accesses the related project's name. The static analysis warning about missing 'project' member is incorrect since ProjectHealthMetricsNode is based on the ProjectHealthMetrics model which has a project foreign key relationship.

backend/tests/apps/owasp/graphql/nodes/health_stats_test.py (1)

1-61: Well-structured comprehensive test suite.

The test implementation effectively validates the HealthStatsNode GraphQL definition and field types using a clean parametrized approach. The helper method _get_field_by_name provides good abstraction for field lookup.

backend/apps/owasp/graphql/queries/project_health_metrics.py (1)

14-32: Clean GraphQL query implementation.

The query class properly exposes both filtered list queries and aggregated statistics with appropriate type annotations and documentation.

backend/apps/owasp/models/project_health_metrics.py (1)

141-156: LGTM - Efficient latest metrics retrieval.

The subquery approach correctly retrieves the most recent health metrics per project using the outer reference pattern.

backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py (1)

17-49: Good field definition validation.

The parametrized tests effectively verify that the GraphQL query class has the correct field definitions and types.

@ahmedxgouda ahmedxgouda force-pushed the dashboard/internal-metrics-resolver branch from 53eae73 to d2ac5ef Compare June 29, 2025 00:37
Copy link
Contributor

@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.

Actionable comments posted: 2

♻️ Duplicate comments (3)
backend/apps/owasp/graphql/filters/project_health_metrics.py (1)

17-22: Add error handling for invalid project level values.

The custom level filter lacks error handling when converting the string value to ProjectLevel enum. If an invalid value is passed, ProjectLevel(value) will raise a ValueError.

backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py (2)

88-88: Fix incorrect query constructor usage.

Same issue as above - GraphQL query classes shouldn't be instantiated with field values.

-        query = ProjectHealthMetricsQuery(project_health_metrics=metrics)
+        query = ProjectHealthMetricsQuery()

66-66: Fix incorrect query constructor usage.

GraphQL query classes shouldn't be instantiated with field values. The project_health_metrics parameter should be removed from the constructor.

-        query = ProjectHealthMetricsQuery(project_health_metrics=[])
+        query = ProjectHealthMetricsQuery()
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53eae73 and d2ac5ef.

📒 Files selected for processing (5)
  • backend/apps/owasp/graphql/filters/project_health_metrics.py (1 hunks)
  • backend/apps/owasp/graphql/nodes/project_health_metrics.py (3 hunks)
  • backend/apps/owasp/graphql/queries/project_health_metrics.py (1 hunks)
  • backend/tests/apps/owasp/graphql/nodes/project_health_metrics_test.py (2 hunks)
  • backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/tests/apps/owasp/graphql/nodes/project_health_metrics_test.py
🧰 Additional context used
🧬 Code Graph Analysis (2)
backend/apps/owasp/graphql/nodes/project_health_metrics.py (1)
backend/apps/owasp/graphql/filters/project_health_metrics.py (1)
  • ProjectHealthMetricsFilter (12-22)
backend/apps/owasp/graphql/queries/project_health_metrics.py (4)
backend/apps/owasp/graphql/nodes/health_stats.py (1)
  • HealthStatsNode (7-20)
backend/apps/owasp/graphql/filters/project_health_metrics.py (1)
  • ProjectHealthMetricsFilter (12-22)
backend/apps/owasp/graphql/nodes/project_health_metrics.py (1)
  • ProjectHealthMetricsNode (30-76)
backend/apps/owasp/models/project_health_metrics.py (2)
  • ProjectHealthMetrics (13-198)
  • get_overall_stats (158-198)
🪛 Pylint (3.3.7)
backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py

[error] 27-27: Class 'ProjectHealthMetricsQuery' has no 'strawberry_definition' member

(E1101)


[error] 42-42: Class 'ProjectHealthMetricsQuery' has no 'strawberry_definition' member

(E1101)

backend/apps/owasp/graphql/filters/project_health_metrics.py

[refactor] 12-12: Too few public methods (1/2)

(R0903)

backend/apps/owasp/graphql/nodes/project_health_metrics.py

[error] 71-71: Instance of 'ProjectHealthMetricsNode' has no 'project' member

(E1101)

backend/apps/owasp/graphql/queries/project_health_metrics.py

[refactor] 15-15: Too few public methods (1/2)

(R0903)

🔇 Additional comments (8)
backend/apps/owasp/graphql/filters/project_health_metrics.py (1)

11-16: LGTM: Clean filter implementation.

The filter class structure and auto-typing for the score field are implemented correctly following Strawberry-Django patterns.

backend/apps/owasp/graphql/nodes/project_health_metrics.py (2)

27-28: LGTM: Proper filtering and pagination integration.

The addition of filtering and pagination capabilities follows Strawberry-Django best practices and integrates well with the existing node structure.


68-71: Relationship Verified: project ForeignKey Exists

  • The ProjectHealthMetrics model defines project = models.ForeignKey("owasp.Project", on_delete=models.CASCADE, related_name="health_metrics") in backend/apps/owasp/models/project_health_metrics.py:28-32.
    No further action required.
backend/apps/owasp/graphql/queries/project_health_metrics.py (2)

18-21: LGTM: Proper field configuration.

The project_health_metrics field is correctly configured with filtering support and appropriate description.


23-31: LGTM: Clean resolver implementation.

The health_stats resolver correctly delegates to the model's static method and includes proper type annotations and documentation.

backend/tests/apps/owasp/graphql/queries/project_health_metrics_test.py (3)

15-29: LGTM: Comprehensive field definition testing.

The parametrized tests for checking Strawberry field definitions are well-structured and cover all expected fields.


31-46: LGTM: Proper type validation testing.

The field configuration tests correctly validate the expected types for each GraphQL field.


48-69: LGTM: Improved mocking strategy.

The test now properly mocks the get_overall_stats method and validates the expected behavior. This addresses the issues mentioned in previous reviews.

@ahmedxgouda ahmedxgouda force-pushed the dashboard/internal-metrics-resolver branch from d2ac5ef to b035e75 Compare June 29, 2025 14:36
@ahmedxgouda ahmedxgouda force-pushed the dashboard/internal-metrics-resolver branch from 76d1312 to 7ed3923 Compare July 3, 2025 18:01
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 3, 2025

@ahmedxgouda ahmedxgouda marked this pull request as ready for review July 3, 2025 18:05
@ahmedxgouda ahmedxgouda requested a review from arkid15r as a code owner July 3, 2025 18:05
Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

I'm merging this as is -- we'll probably need to revisit it later.

Thank you 👍

@arkid15r arkid15r added this pull request to the merge queue Jul 3, 2025
Merged via the queue into OWASP:main with commit d7ec57a Jul 3, 2025
23 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 4, 2025
2 tasks
@ahmedxgouda ahmedxgouda deleted the dashboard/internal-metrics-resolver branch August 10, 2025 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement GraphQL resolver to returns project health metrics in the internal dashboard

2 participants