Skip to content

TargetUnit service #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft

TargetUnit service #45

wants to merge 20 commits into from

Conversation

anatolyshipitz
Copy link
Collaborator

Added the TargetUnitService class along with its corresponding test file to manage target unit retrieval from the repository. This implementation enhances the functionality of the service layer by providing a dedicated method for fetching target units, improving code organization and maintainability.

anatolyshipitz and others added 17 commits June 3, 2025 18:36
- Added `RedminePool.ts` to manage MySQL connection pooling, including methods for pool creation and termination.
- Created `RedminePool.test.ts` to validate the functionality of the `RedminePool` class, ensuring proper pool management and error handling.

These additions enhance database connection management and improve test coverage for the Redmine integration.
- Updated the `RedminePool.test.ts` file to enhance type safety by defining a `PoolMock` interface.
- Refactored the test setup to improve readability and maintainability, including clearer type assertions for pool properties.
- Adjusted the formatting of the credentials object for better clarity.

These changes improve the robustness of the tests for the `RedminePool` class, ensuring better type checking and organization.
- Updated the `RedminePool` class to include error handling during pool creation and termination, ensuring that meaningful error messages are thrown when failures occur.
- Added new test cases in `RedminePool.test.ts` to validate the graceful handling of pool creation and termination errors.

These changes improve the robustness of the `RedminePool` class by ensuring it can handle errors effectively, enhancing overall reliability.
- Added `ProjectUnit` interface to define the structure of Project Unit data.
- Created `IRedmineRepository` interface for fetching project units.
- Implemented `RedmineRepository` class to handle database queries and map results to `ProjectUnit`.
- Introduced SQL query for retrieving project units based on time entries.
- Developed `RedmineService` class to provide a service layer for accessing project units.

Implements Redmine project unit management

Adds functionality to retrieve and manage project units from Redmine.

Introduces a repository pattern for data access, a service layer for business logic, and a data transfer object for representing project unit information. This provides a structured way to interact with the Redmine database and retrieve project-related data.
- Modified the SQL query in `queries.ts` to adjust the date range for fetching time entries.
- The new query now correctly calculates the start and end dates for the past week, ensuring accurate data retrieval.

This change enhances the accuracy of time entry data fetched from the Redmine API, improving reporting and analysis capabilities.
- Introduced `RedmineRepository.test.ts` to validate the functionality of the `RedmineRepository` class, including tests for mapping rows to `ProjectUnit` and error handling.
- Created `RedmineService.test.ts` to ensure the `RedmineService` correctly retrieves project units from the repository.

These additions enhance test coverage for the Redmine integration, ensuring the reliability of data retrieval and error management in the repository and service layers.
This change replaces the RedmineService and its related components with TargetUnitService to align with updated domain terminology. All references, files, and test cases have been renamed or updated to maintain consistency.
This change renames the `ProjectUnit` interface to `TargetUnit` and updates all related references in the repository and service layers. The modifications ensure consistency in terminology and improve clarity in the codebase. All relevant tests have been adjusted accordingly to reflect this change.
…tUnitRepository and related tests

This change updates the method names in the `ITargetUnitRepository`, `TargetUnitRepository`, and `TargetUnitService` classes to reflect the new terminology. All corresponding test cases have been modified to ensure consistency and maintain functionality. This refactor enhances clarity in the codebase by aligning method names with the updated domain terminology.
Removed IPoolProvider abstraction and updated queries and related tests for consistency and clarity.
Revised the SQL query in `queries.ts` to improve readability by restructuring the WHERE clause and enhancing the GROUP BY and ORDER BY sections.
Eliminated the console error logging in the `getTargetUnits` method of the `TargetUnitRepository` class to streamline error handling. This change enhances the clarity of error messages thrown by the repository without cluttering the console output.
Refactored the `mapRowToTargetUnit` method in the `TargetUnitRepository` class to use an arrow function for improved readability and conciseness. This change enhances the clarity of the code while maintaining the same functionality.
Deleted the `TargetUnitService` class and its associated test file to streamline the codebase. This change eliminates unnecessary complexity and focuses on more relevant components, enhancing overall maintainability.
Added the `TargetUnitService` class along with its corresponding test file to manage target unit retrieval from the repository. This implementation enhances the functionality of the service layer by providing a dedicated method for fetching target units, improving code organization and maintainability.
@anatolyshipitz anatolyshipitz requested a review from killev as a code owner June 5, 2025 13:30
Copy link

coderabbitai bot commented Jun 5, 2025

📝 Walkthrough

Walkthrough

A new TargetUnitService class is introduced, encapsulating repository access for fetching target units. Accompanying unit tests are added, verifying that the service correctly delegates data retrieval to the repository and returns the expected results.

Changes

Files/Paths Change Summary
workers/main/src/services/TargetUnit/TargetUnitService.ts Added TargetUnitService class with getTargetUnits method using repository injection.
workers/main/src/services/TargetUnit/TargetUnitService.test.ts Added unit tests for TargetUnitService, focusing on getTargetUnits.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant TargetUnitService
    participant ITargetUnitRepository

    Client->>TargetUnitService: getTargetUnits()
    TargetUnitService->>ITargetUnitRepository: getTargetUnits()
    ITargetUnitRepository-->>TargetUnitService: TargetUnit[]
    TargetUnitService-->>Client: TargetUnit[]
Loading

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

github-actions bot commented Jun 5, 2025

🔍 Vulnerabilities of temporal-test:latest

📦 Image Reference temporal-test:latest
digestsha256:da30eca7154c7c4cb2616e31f7411021ea9146d5b15c68adf2a57df4c52b164c
vulnerabilitiescritical: 2 high: 7 medium: 0 low: 0
platformlinux/amd64
size218 MB
packages358
📦 Base Image alpine:3
also known as
  • 3.21
  • 3.21.3
  • latest
digestsha256:1c4eef651f65e2f7daee7ee785882ac164b02b78fb74503052a26dc061c90474
vulnerabilitiescritical: 0 high: 0 medium: 0 low: 0
critical: 1 high: 0 medium: 0 low: 0 stdlib 1.23.2 (golang)

pkg:golang/[email protected]

critical : CVE--2025--22871

Affected range<1.23.8
Fixed version1.23.8
EPSS Score0.018%
EPSS Percentile3rd percentile
Description

The net/http package improperly accepts a bare LF as a line terminator in chunked data chunk-size lines. This can permit request smuggling if a net/http server is used in conjunction with a server that incorrectly accepts a bare LF as part of a chunk-ext.

critical: 1 high: 0 medium: 0 low: 0 stdlib 1.23.6 (golang)

pkg:golang/[email protected]

critical : CVE--2025--22871

Affected range<1.23.8
Fixed version1.23.8
EPSS Score0.018%
EPSS Percentile3rd percentile
Description

The net/http package improperly accepts a bare LF as a line terminator in chunked data chunk-size lines. This can permit request smuggling if a net/http server is used in conjunction with a server that incorrectly accepts a bare LF as part of a chunk-ext.

critical: 0 high: 1 medium: 0 low: 0 golang.org/x/oauth2 0.7.0 (golang)

pkg:golang/golang.org/x/[email protected]

high : CVE--2025--22868

Affected range<0.27.0
Fixed version0.27.0
EPSS Score0.063%
EPSS Percentile20th percentile
Description

An attacker can pass a malicious malformed token which causes unexpected memory to be consumed during parsing.

critical: 0 high: 1 medium: 0 low: 0 github.com/golang-jwt/jwt/v4 4.5.1 (golang)

pkg:golang/github.com/golang-jwt/[email protected]#v4

high 8.7: CVE--2025--30204 Asymmetric Resource Consumption (Amplification)

Affected range<4.5.2
Fixed version4.5.2
CVSS Score8.7
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
EPSS Score0.025%
EPSS Percentile5th percentile
Description

Summary

Function parse.ParseUnverified currently splits (via a call to strings.Split) its argument (which is untrusted data) on periods.

As a result, in the face of a malicious request whose Authorization header consists of Bearer followed by many period characters, a call to that function incurs allocations to the tune of O(n) bytes (where n stands for the length of the function's argument), with a constant factor of about 16. Relevant weakness: CWE-405: Asymmetric Resource Consumption (Amplification)

Details

See parse.ParseUnverified

Impact

Excessive memory allocation

critical: 0 high: 1 medium: 0 low: 0 golang.org/x/crypto 0.32.0 (golang)

pkg:golang/golang.org/x/[email protected]

high : CVE--2025--22869

Affected range<0.35.0
Fixed version0.35.0
EPSS Score0.051%
EPSS Percentile16th percentile
Description

SSH servers which implement file transfer protocols are vulnerable to a denial of service attack from clients which complete the key exchange slowly, or not at all, causing pending content to be read into memory, but never transmitted.

critical: 0 high: 1 medium: 0 low: 0 c-ares 1.34.3-r0 (apk)

pkg:apk/alpine/[email protected]?os_name=alpine&os_version=3.21

high : CVE--2025--31498

Affected range<1.34.5-r0
Fixed version1.34.5-r0
EPSS Score0.147%
EPSS Percentile36th percentile
Description
critical: 0 high: 1 medium: 0 low: 0 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc 0.36.4 (golang)

pkg:golang/go.opentelemetry.io/contrib/[email protected]#google.golang.org/grpc/otelgrpc

high 7.5: CVE--2023--47108 Allocation of Resources Without Limits or Throttling

Affected range<0.46.0
Fixed version0.46.0
CVSS Score7.5
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
EPSS Score2.678%
EPSS Percentile85th percentile
Description

Summary

The grpc Unary Server Interceptor opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go

// UnaryServerInterceptor returns a grpc.UnaryServerInterceptor suitable
// for use in a grpc.NewServer call.
func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor {

out of the box adds labels

  • net.peer.sock.addr
  • net.peer.sock.port

that have unbound cardinality. It leads to the server's potential memory exhaustion when many malicious requests are sent.

Details

An attacker can easily flood the peer address and port for requests.

PoC

Apply the attached patch to the example and run the client multiple times. Observe how each request will create a unique histogram and how the memory consumption increases during it.

Impact

In order to be affected, the program has to configure a metrics pipeline, use UnaryServerInterceptor, and does not filter any client IP address and ports via middleware or proxies, etc.

Others

It is similar to already reported vulnerabilities.

Workaround for affected versions

As a workaround to stop being affected, a view removing the attributes can be used.

The other possibility is to disable grpc metrics instrumentation by passing otelgrpc.WithMeterProvider option with noop.NewMeterProvider.

Solution provided by upgrading

In PR #4322, to be released with v0.46.0, the attributes were removed.

References

critical: 0 high: 1 medium: 0 low: 0 golang.org/x/oauth2 0.26.0 (golang)

pkg:golang/golang.org/x/[email protected]

high : CVE--2025--22868

Affected range<0.27.0
Fixed version0.27.0
EPSS Score0.063%
EPSS Percentile20th percentile
Description

An attacker can pass a malicious malformed token which causes unexpected memory to be consumed during parsing.

critical: 0 high: 1 medium: 0 low: 0 github.com/golang-jwt/jwt 3.2.2+incompatible (golang)

pkg:golang/github.com/golang-jwt/[email protected]%2Bincompatible

high 8.7: CVE--2025--30204 Asymmetric Resource Consumption (Amplification)

Affected range>=3.2.0
<=3.2.2
Fixed versionNot Fixed
CVSS Score8.7
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
EPSS Score0.025%
EPSS Percentile5th percentile
Description

Summary

Function parse.ParseUnverified currently splits (via a call to strings.Split) its argument (which is untrusted data) on periods.

As a result, in the face of a malicious request whose Authorization header consists of Bearer followed by many period characters, a call to that function incurs allocations to the tune of O(n) bytes (where n stands for the length of the function's argument), with a constant factor of about 16. Relevant weakness: CWE-405: Asymmetric Resource Consumption (Amplification)

Details

See parse.ParseUnverified

Impact

Excessive memory allocation

Base automatically changed from feat/redmine-service to main June 5, 2025 13:44
@anatolyshipitz anatolyshipitz enabled auto-merge (squash) June 5, 2025 13:49
Copy link

@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: 0

🧹 Nitpick comments (2)
workers/main/src/services/TargetUnit/TargetUnitService.test.ts (2)

35-35: Fix inconsistent terminology in test description.

The test description mentions "project units" but should be "target units" to match the service name and functionality.

-  it('should return project units from the repository', async () => {
+  it('should return target units from the repository', async () => {

35-44: Consider adding additional test coverage.

While the current test covers the happy path well, consider adding tests for:

  • Error handling when the repository throws an exception
  • Edge cases like empty arrays from the repository

Example additional test:

it('should propagate repository errors', async () => {
  const error = new Error('Repository error');
  mockRepo.getTargetUnits.mockRejectedValueOnce(error);

  await expect(service.getTargetUnits()).rejects.toThrow('Repository error');
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 022ed8d and 1d9bbd1.

📒 Files selected for processing (2)
  • workers/main/src/services/TargetUnit/TargetUnitService.test.ts (1 hunks)
  • workers/main/src/services/TargetUnit/TargetUnitService.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
workers/main/src/services/TargetUnit/TargetUnitService.ts (2)
workers/main/src/services/TargetUnit/ITargetUnitRepository.ts (1)
  • ITargetUnitRepository (3-5)
workers/main/src/common/types.ts (1)
  • TargetUnit (1-12)
workers/main/src/services/TargetUnit/TargetUnitService.test.ts (2)
workers/main/src/common/types.ts (1)
  • TargetUnit (1-12)
workers/main/src/services/TargetUnit/TargetUnitService.ts (1)
  • TargetUnitService (4-10)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Docker Security Scanning (temporal, Dockerfile.temporal, temporal-test:latest)
  • GitHub Check: Docker Security Scanning (n8n, Dockerfile.n8n, n8n-test:latest)
  • GitHub Check: SonarQube
  • GitHub Check: Service Availability Check
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (actions)
🔇 Additional comments (3)
workers/main/src/services/TargetUnit/TargetUnitService.ts (1)

1-10: LGTM! Clean implementation following dependency injection pattern.

The service implementation is well-structured with proper dependency injection and clear method signatures. The simple delegation pattern provides a clean service layer abstraction that can be extended in the future if additional business logic is needed.

workers/main/src/services/TargetUnit/TargetUnitService.test.ts (2)

6-16: LGTM! Good use of helper functions for test data creation.

The createTargetUnit helper function with default values and override capability is a clean pattern that makes tests more readable and maintainable.


18-33: LGTM! Proper test setup and teardown.

The test setup follows Vitest best practices with proper mock creation, initialization, and cleanup.

Copy link

sonarqubecloud bot commented Jun 7, 2025

@anatolyshipitz anatolyshipitz marked this pull request as draft June 9, 2025 07:07
auto-merge was automatically disabled June 9, 2025 07:07

Pull request was converted to draft

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.

1 participant