Skip to content
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

Gitlab Connector #421

Merged
merged 17 commits into from
May 13, 2024
Merged

Gitlab Connector #421

merged 17 commits into from
May 13, 2024

Conversation

mit-27
Copy link
Contributor

@mit-27 mit-27 commented May 5, 2024

  • Closes feat: Add Gitlab integration to ticketing vertical #367
  • Objects
    • Collections
    • Comments
    • Tags
      • It is not compatible with Panora's Unified Model. The tag should be associated with the ticket (issue). However, for GitLab, tags are associated with individual projects, which makes it incompatible with Panora's Unified Model.
    • Tickets
    • Users

Copy link

changeset-bot bot commented May 5, 2024

⚠️ No Changeset found

Latest commit: 7cb9863

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented May 5, 2024

@mit-27 is attempting to deploy a commit to the Panora Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented May 5, 2024

Walkthrough

The recent updates focus on integrating Gitlab into the ticketing system, enhancing functionalities across collections, comments, tags, tickets, and user data synchronization. These changes introduce new services, mappers, and types specific to Gitlab, improving the system's ability to interact effectively with Gitlab resources.

Changes

File Path Summary
.../gitlab/gitlab.service.ts
.../ticketing/collection/...
.../ticketing/comment/...
.../ticketing/tag/...
.../ticketing/ticket/...
.../ticketing/user/...
Added Gitlab integration across multiple modules, including services for collections, comments, tags, tickets, and users.
.../types/...
.../mappers.ts
Introduced new types and mappers to handle Gitlab-specific data formats.
.../@lib/@utils/index.ts
.../shared/src/...
Updated utility functions and shared configurations to support Gitlab integration.

Assessment against linked issues

Objective Addressed Explanation
Add Gitlab integration to ticketing vertical (Collections, Comments, Tags, Tickets, Users) [#367]
Ensure all Gitlab-related data types and services are implemented [#367]

Poem

🐇 Oh hooray, what a day, Gitlab's here to stay!
In tickets and tags, we sync and we play.
🌟 From comments to users, our system now sings,
With each line of code, new integration it brings.
Let's hop and celebrate, for teamwork's the key,
In the world of code, together we're free! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
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: 7

Out of diff range and nitpick comments (4)
packages/shared/src/authUrl.ts (1)

Line range hint 85-100: Ensure proper error handling for missing clientId and scopes.

-  if (!clientId) throw new Error(`No client id for type ${type}`)
+  if (!clientId) {
+    throw new Error(`No client id for type ${type}`);
+  }
-  const scopes = data.SCOPE
+  const scopes = data.SCOPE;
+  if (!scopes) {
+    throw new Error(`No scopes provided for type ${type}`);
+  }
packages/api/src/@core/connections/ticketing/services/gitlab/gitlab.service.ts (1)

Line range hint 198-198: Correct the logging to reflect the actual service being used (Gitlab instead of Jira).

-      this.logger.log('OAuth credentials updated : jira ');
+      this.logger.log('OAuth credentials updated : gitlab ');
packages/shared/src/utils.ts (2)

17-23: Consider adding a comment explaining the purpose of customPropertiesUrl in the ProviderConfig type. This helps maintainers understand its use case, especially since it appears in multiple places within the configuration.


2164-2172: The function getActiveProvidersForVertical assumes that any provider not explicitly marked as inactive (active: false) is considered active. Consider adding a comment in the function to clarify this assumption for future maintainers.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1d82310 and 1632ad6.
Files ignored due to path filters (1)
  • packages/api/swagger/swagger-spec.json is excluded by !**/*.json
Files selected for processing (15)
  • packages/api/src/@core/connections/ticketing/services/gitlab/gitlab.service.ts (3 hunks)
  • packages/api/src/@core/utils/types/original/original.ticketing.ts (6 hunks)
  • packages/api/src/ticketing/collection/collection.module.ts (2 hunks)
  • packages/api/src/ticketing/collection/services/collection.service.ts (1 hunks)
  • packages/api/src/ticketing/collection/services/gitlab/index.ts (1 hunks)
  • packages/api/src/ticketing/collection/services/gitlab/mappers.ts (1 hunks)
  • packages/api/src/ticketing/collection/services/gitlab/types.ts (1 hunks)
  • packages/api/src/ticketing/collection/services/jira/index.ts (2 hunks)
  • packages/api/src/ticketing/collection/sync/sync.service.ts (3 hunks)
  • packages/api/src/ticketing/collection/types/index.ts (1 hunks)
  • packages/api/src/ticketing/collection/types/mappingsTypes.ts (1 hunks)
  • packages/shared/src/authUrl.ts (3 hunks)
  • packages/shared/src/enum.ts (1 hunks)
  • packages/shared/src/providers.ts (1 hunks)
  • packages/shared/src/utils.ts (148 hunks)
Files not summarized due to errors (1)
  • packages/shared/src/utils.ts: Error: Message exceeds token limit
Files skipped from review due to trivial changes (2)
  • packages/shared/src/enum.ts
  • packages/shared/src/providers.ts
Additional comments not posted (13)
packages/api/src/ticketing/collection/types/mappingsTypes.ts (3)

1-1: Ensure that the GitlabCollectionMapper and JiraCollectionMapper are correctly imported and utilized.


6-6: Initialization of gitlabCollectionMapper is correctly done.


10-14: The mapping object for gitlab correctly binds the unify and desunify methods to ensure the correct context is preserved when these methods are called.

packages/api/src/ticketing/collection/types/index.ts (2)

6-6: Import statements are correctly organized and necessary types are included.


15-18: The addCollection method in the ICollectionService interface is correctly defined with appropriate parameters and return type.

packages/api/src/ticketing/collection/collection.module.ts (1)

36-36: The GitlabService is correctly added to the providers array, ensuring it is available for dependency injection within the module.

packages/api/src/ticketing/collection/services/gitlab/mappers.ts (1)

8-56: The GitlabCollectionMapper class correctly implements the desunify and unify methods as per the ICollectionMapper interface. The methods handle custom field mappings and ensure proper transformation between unified and Gitlab-specific formats.

packages/api/src/ticketing/collection/services/jira/index.ts (1)

66-73: The addCollection method in JiraService is defined but returns null. This might be intentional (e.g., method not implemented yet), but it's important to ensure that this is either fully implemented or properly documented if it's a work in progress.

packages/api/src/ticketing/collection/services/gitlab/types.ts (1)

1-98: The GitlabCollection interface is comprehensive and includes a wide range of properties that cover various aspects of a Gitlab project. Ensure that all optional properties are correctly marked and that data types are appropriate for each property.

packages/shared/src/authUrl.ts (1)

130-130: Clarify the use of code_challenge and code_challenge_method for Gitlab OAuth.

packages/api/src/@core/connections/ticketing/services/gitlab/gitlab.service.ts (1)

108-108: Validate the use of account_url from providersConfig to ensure it is correctly populated and used.

Verification successful

The search results confirm that account_url is widely used across various services within the codebase, including the specific file and line in question (packages/api/src/@core/connections/ticketing/services/gitlab/gitlab.service.ts). The usage pattern generally involves constructing API endpoints by appending specific paths to account_url, which is consistent with typical usage scenarios for such a configuration parameter.

Given this context, the usage of account_url as seen in the GitlabConnectionService and across other services appears to be correct and consistent. The configuration is being properly retrieved (providersConfig['ticketing']['gitlab'].urls.apiUrl) and utilized in forming API requests, which aligns with the expected behavior described in the review comment.

Conclusion:
The use of account_url in the GitlabConnectionService and throughout the codebase is verified to be correctly populated and used as per the standards observed in similar services. No discrepancies or issues were found regarding its implementation.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct population and usage of `account_url` in the GitlabConnectionService.

# Test: Search for the usage of `account_url`. Expect: Correct retrieval and usage in service methods.
rg --type typescript 'account_url'

Length of output: 69



Script:

#!/bin/bash
# Correcting the script to search for the usage of `account_url` in TypeScript files.
rg --type-add 'typescript:*.ts' -g '*.ts' 'account_url'

Length of output: 21717

packages/api/src/@core/utils/types/original/original.ticketing.ts (1)

116-118: LGTM! The Gitlab type definitions are correctly integrated with existing ticketing types.

packages/shared/src/utils.ts (1)

2164-2172: The implementation of providersArray is straightforward and correctly utilizes getActiveProvidersForVertical. Good use of existing functionality.

@@ -68,6 +68,7 @@ export class CollectionService {
remote_data?: boolean,
): Promise<UnifiedCollectionOutput[]> {
try {
console.log("In collection service : ", integrationId)
Copy link
Contributor

Choose a reason for hiding this comment

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

The logging statement in getCollections method provides useful debugging information. Ensure that such logs are appropriately gated (e.g., only in debug mode) to avoid verbose logging in production.

- console.log("In collection service : ", integrationId)
+ if (process.env.DEBUG_MODE === 'true') {
+   console.log("In collection service : ", integrationId);
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
console.log("In collection service : ", integrationId)
if (process.env.DEBUG_MODE === 'true') {
console.log("In collection service : ", integrationId);
}

},
});

console.log("xzx : ", `${connection.account_url}/projects`)
Copy link
Contributor

Choose a reason for hiding this comment

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

The logging statement in syncCollections method of GitlabService is useful for debugging. Consider gating this log under a debug mode check to prevent verbose output in production environments.

- console.log("xzx : ", `${connection.account_url}/projects`)
+ if (process.env.DEBUG_MODE === 'true') {
+   console.log("xzx : ", `${connection.account_url}/projects`);
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
console.log("xzx : ", `${connection.account_url}/projects`)
if (process.env.DEBUG_MODE === 'true') {
console.log("xzx : ", `${connection.account_url}/projects`);
}

Comment on lines +104 to +105
const BASE_URL: string = providerName === 'gorgias' ? `${apiUrl}${baseUrl}` :
data.SUBDOMAIN ? data.SUBDOMAIN + baseUrl : baseUrl;
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor the construction of BASE_URL to handle potential null values more gracefully.

-  const BASE_URL: string = providerName === 'gorgias' ? `${apiUrl}${baseUrl}` :
-    data.SUBDOMAIN ? data.SUBDOMAIN + baseUrl : baseUrl;
+  let baseDomain = baseUrl;
+  if (providerName === 'gorgias') {
+    baseDomain = `${apiUrl}${baseUrl}`;
+  } else if (data.SUBDOMAIN) {
+    baseDomain = `${data.SUBDOMAIN}${baseUrl}`;
+  }
+  const BASE_URL = baseDomain || throw new Error(`Base URL cannot be determined for provider: ${providerName}`);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const BASE_URL: string = providerName === 'gorgias' ? `${apiUrl}${baseUrl}` :
data.SUBDOMAIN ? data.SUBDOMAIN + baseUrl : baseUrl;
let baseDomain = baseUrl;
if (providerName === 'gorgias') {
baseDomain = `${apiUrl}${baseUrl}`;
} else if (data.SUBDOMAIN) {
baseDomain = `${data.SUBDOMAIN}${baseUrl}`;
}
const BASE_URL = baseDomain || throw new Error(`Base URL cannot be determined for provider: ${providerName}`);

@@ -67,7 +67,7 @@ export class GitlabConnectionService implements ITicketingConnectionService {
grant_type: 'authorization_code',
});
const res = await axios.post(
`https://api.gitlab.app/oauth/token`,
`https://gitlab.com/oauth/token`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the URL used for the OAuth token exchange is configurable rather than hardcoded.

-        `https://gitlab.com/oauth/token`,
+        `${providersConfig['ticketing']['gitlab'].urls.apiUrl}/oauth/token`,

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
`https://gitlab.com/oauth/token`,
`${providersConfig['ticketing']['gitlab'].urls.apiUrl}/oauth/token`,

@@ -59,7 +59,7 @@ export class SyncService implements OnModuleInit {
}
//function used by sync worker which populate our tcg_collections table
//its role is to fetch all collections from providers 3rd parties and save the info inside our db
//@Cron('*/2 * * * *') // every 2 minutes (for testing)
// @Cron('*/2 * * * *') // every 2 minutes (for testing)
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the CRON schedule comment to reflect the actual schedule used (every 8 hours).

-  // @Cron('*/2 * * * *') // every 2 minutes (for testing)
+  // @Cron('0 */8 * * *') // every 8 hours

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// @Cron('*/2 * * * *') // every 2 minutes (for testing)
// @Cron('0 */8 * * *') // every 8 hours

@@ -195,6 +195,7 @@
): Promise<TicketingCollection[]> {
try {
let collections_results: TicketingCollection[] = [];
console.log(collections)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unnecessary console logging to maintain clean and professional code.

-      console.log(collections)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
console.log(collections)

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1632ad6 and b612011.
Files selected for processing (1)
  • packages/shared/src/webhookScopes.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/shared/src/webhookScopes.ts

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

Out of diff range and nitpick comments (1)
packages/shared/src/utils.ts (1)

17-23: Consider adding a comment explaining the purpose of customPropertiesUrl in the ProviderConfig type. This will help other developers understand its use case, especially since it appears in multiple places within the configuration object.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between b612011 and 0dbf755.
Files selected for processing (6)
  • packages/api/src/ticketing/user/services/gitlab/index.ts (1 hunks)
  • packages/api/src/ticketing/user/services/gitlab/mappers.ts (1 hunks)
  • packages/api/src/ticketing/user/services/gitlab/types.ts (1 hunks)
  • packages/api/src/ticketing/user/types/mappingsTypes.ts (1 hunks)
  • packages/api/src/ticketing/user/user.module.ts (2 hunks)
  • packages/shared/src/utils.ts (148 hunks)
Files not summarized due to errors (1)
  • packages/shared/src/utils.ts: Error: Message exceeds token limit
Files skipped from review due to trivial changes (1)
  • packages/api/src/ticketing/user/services/gitlab/types.ts
Additional comments not posted (9)
packages/api/src/ticketing/user/types/mappingsTypes.ts (3)

1-1: Ensure that the GitlabUserMapper import is correctly utilized within the file.

Verification successful

The verification process has confirmed that the GitlabUserMapper is indeed utilized within the file mappingsTypes.ts. The import statement is followed by an instantiation of GitlabUserMapper, which indicates that the import is actively used in the file.

Conclusion:

  • The import of GitlabUserMapper is correctly utilized in the file mappingsTypes.ts.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `GitlabUserMapper` is used in the file `mappingsTypes.ts`.

# Test: Search for the usage of `GitlabUserMapper`. Expect: At least one occurrence.
rg --type ts 'GitlabUserMapper' 'packages/api/src/ticketing/user/types/mappingsTypes.ts'

Length of output: 198


10-10: Addition of GitlabUserMapper instance is consistent with the pattern used for other services.


22-25: The method bindings for gitlab in userUnificationMapping are correctly implemented.

packages/api/src/ticketing/user/user.module.ts (1)

42-42: Addition of GitlabService to the providers list ensures it is available for dependency injection.

packages/api/src/ticketing/user/services/gitlab/mappers.ts (1)

8-58: The GitlabUserMapper class is well-implemented with methods to handle both single and batch user data transformations.

packages/api/src/ticketing/user/services/gitlab/index.ts (1)

13-63: The GitlabService class correctly implements user synchronization with Gitlab, including error handling and logging.

packages/shared/src/utils.ts (3)

111-116: Ensure that the authBaseUrl and apiUrl for the 'accelo' provider are absolute URLs unless relative URLs are handled dynamically. Relative URLs could lead to requests being sent to incorrect addresses.


2164-2172: The function providersArray correctly constructs an array of provider details. However, consider adding error handling or logging to manage cases where the provider or vertical does not exist, as previously suggested by another review. This would improve debugging and maintainability.


394-402: The gitlab provider configuration has been added with detailed scopes and URLs. Ensure that the authBaseUrl and apiUrl are correct and accessible. This is crucial as incorrect URLs can lead to failed connections with the Gitlab API.

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 0dbf755 and f2404a2.
Files selected for processing (12)
  • packages/api/src/@core/connections/ticketing/services/gitlab/gitlab.service.ts (6 hunks)
  • packages/api/src/ticketing/collection/services/gitlab/index.ts (1 hunks)
  • packages/api/src/ticketing/collection/services/jira/index.ts (2 hunks)
  • packages/api/src/ticketing/collection/types/index.ts (1 hunks)
  • packages/api/src/ticketing/tag/services/gitlab/index.ts (1 hunks)
  • packages/api/src/ticketing/tag/services/gitlab/mappers.ts (1 hunks)
  • packages/api/src/ticketing/tag/services/gitlab/types.ts (1 hunks)
  • packages/api/src/ticketing/tag/tag.module.ts (2 hunks)
  • packages/api/src/ticketing/tag/types/mappingsTypes.ts (2 hunks)
  • packages/api/src/ticketing/user/services/gitlab/index.ts (1 hunks)
  • packages/api/src/ticketing/user/services/gitlab/mappers.ts (1 hunks)
  • packages/api/src/ticketing/user/sync/sync.service.ts (3 hunks)
Files skipped from review due to trivial changes (1)
  • packages/api/src/ticketing/collection/types/index.ts
Files skipped from review as they are similar to previous changes (5)
  • packages/api/src/@core/connections/ticketing/services/gitlab/gitlab.service.ts
  • packages/api/src/ticketing/collection/services/gitlab/index.ts
  • packages/api/src/ticketing/collection/services/jira/index.ts
  • packages/api/src/ticketing/user/services/gitlab/index.ts
  • packages/api/src/ticketing/user/services/gitlab/mappers.ts
Additional comments not posted (7)
packages/api/src/ticketing/tag/services/gitlab/types.ts (2)

11-24: The Commit interface is well-defined and clear.


26-29: The Release interface is correctly defined.

packages/api/src/ticketing/tag/types/mappingsTypes.ts (1)

11-29: The registration of GitlabTagMapper is correctly implemented, and the use of .bind is appropriate for maintaining the this context.

packages/api/src/ticketing/tag/services/gitlab/mappers.ts (1)

19-47: The unify method is implemented correctly, efficiently handling both single and array inputs.

packages/api/src/ticketing/tag/tag.module.ts (1)

42-42: The addition of GitlabService to the providers list is correctly implemented, ensuring availability for dependency injection.

packages/api/src/ticketing/tag/services/gitlab/index.ts (1)

28-69: The syncTags method is well-implemented, correctly handling API calls, using encrypted tokens for authorization, and logging the process.

packages/api/src/ticketing/user/sync/sync.service.ts (1)

Line range hint 63-262: The syncUsers method is well-implemented, handling user synchronization across different providers, correctly managing errors, and logging the process.

release: Release
name: string
target: string
message: any
Copy link
Contributor

Choose a reason for hiding this comment

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

Specify a more precise type for the message property instead of any to enhance type safety.

Comment on lines 9 to 17
desunify(
source: UnifiedTagInput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): GitlabTagInput {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implement the desunify method or ensure it returns a meaningful value. Currently, it returns nothing, which is likely an oversight.

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between f2404a2 and 3143f5c.
Files selected for processing (2)
  • packages/api/src/@core/utils/types/original/original.ticketing.ts (8 hunks)
  • packages/api/src/ticketing/tag/services/gitlab/mappers.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/api/src/@core/utils/types/original/original.ticketing.ts
  • packages/api/src/ticketing/tag/services/gitlab/mappers.ts

@Rutik7066
Copy link

Hi @mit-27 may pick this code to solve #367

@mit-27
Copy link
Contributor Author

mit-27 commented May 7, 2024

Sorry @Rutik7066, I am already on it.Feel free to pick any other issue.

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: 12

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 3143f5c and d3a0199.
Files selected for processing (18)
  • packages/api/src/@core/utils/types/original/original.ticketing.ts (9 hunks)
  • packages/api/src/ticketing/@lib/@utils/index.ts (1 hunks)
  • packages/api/src/ticketing/comment/comment.module.ts (2 hunks)
  • packages/api/src/ticketing/comment/services/gitlab/index.ts (1 hunks)
  • packages/api/src/ticketing/comment/services/gitlab/mappers.ts (1 hunks)
  • packages/api/src/ticketing/comment/services/gitlab/types.ts (1 hunks)
  • packages/api/src/ticketing/comment/sync/sync.service.ts (1 hunks)
  • packages/api/src/ticketing/comment/types/mappingsTypes.ts (2 hunks)
  • packages/api/src/ticketing/tag/tag.module.ts (1 hunks)
  • packages/api/src/ticketing/tag/types/mappingsTypes.ts (2 hunks)
  • packages/api/src/ticketing/ticket/services/gitlab/index.ts (1 hunks)
  • packages/api/src/ticketing/ticket/services/gitlab/mappers.ts (1 hunks)
  • packages/api/src/ticketing/ticket/services/gitlab/types.ts (1 hunks)
  • packages/api/src/ticketing/ticket/sync/sync.service.ts (1 hunks)
  • packages/api/src/ticketing/ticket/ticket.module.ts (2 hunks)
  • packages/api/src/ticketing/ticket/types/mappingsTypes.ts (2 hunks)
  • packages/shared/src/enum.ts (1 hunks)
  • packages/shared/src/providers.ts (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • packages/api/src/@core/utils/types/original/original.ticketing.ts
  • packages/api/src/ticketing/tag/tag.module.ts
  • packages/api/src/ticketing/tag/types/mappingsTypes.ts
  • packages/shared/src/enum.ts
  • packages/shared/src/providers.ts
Additional comments not posted (21)
packages/api/src/ticketing/comment/services/gitlab/types.ts (3)

1-18: The GitlabComment interface is well-defined with appropriate fields for GitLab comments. Ensure that the attachment type is appropriately handled in the system since it's currently set to any.


20-27: The Author interface is clearly defined. Consider adding type annotations for fields like email to ensure they meet expected formats (e.g., regex for emails).


30-31: The type aliases GitlabCommentInput and GitlabCommentOutput are correctly defined as partials of GitlabComment, facilitating flexible API interactions.

packages/api/src/ticketing/comment/types/mappingsTypes.ts (2)

1-2: Ensure that all imported mappers are utilized within the file. The import of GitlabCommentMapper is correctly placed and used in the mapping object.


11-33: The commentUnificationMapping object correctly binds methods from various comment mappers to handle unification and de-unification. This setup facilitates easy extension and maintenance of comment handling across different platforms.

packages/api/src/ticketing/comment/comment.module.ts (2)

1-1: The import of GitlabService is correctly placed for integration within the comment module. Ensure that this service is properly implemented to interact with GitLab's API.


42-42: The inclusion of GitlabService in the providers array of the @Module decorator ensures that it is available throughout the comment module. This is crucial for the integration of GitLab services.

packages/api/src/ticketing/ticket/ticket.module.ts (2)

1-1: The import of GitlabService is correctly placed for integration within the ticket module. Ensure that this service is properly implemented to interact with GitLab's API.


46-46: The inclusion of GitlabService in the providers array of the @Module decorator ensures that it is available throughout the ticket module. This is crucial for the integration of GitLab services.

packages/api/src/ticketing/ticket/services/gitlab/types.ts (8)

1-36: The GitlabTicket interface is well-defined with appropriate fields for GitLab tickets. Ensure that the types for fields like assignees, weight, epic, assignee, milestone, closed_by, due_date, and description are appropriately handled in the system since they're currently set to any.


38-44: The Epic interface is clearly defined with fields relevant to an epic in GitLab. Ensure that the url field is validated to be a proper URL format.


46-53: The Author interface for tickets is similar to that in comments but includes additional fields like avatar_url and web_url. Ensure these fields are correctly handled and validated, especially web_url for proper URL format.


55-59: The References interface is well-structured to hold different types of references. Ensure that these references are correctly parsed and used within the system.


61-66: The TimeStats interface captures time-related statistics for tickets. The use of any for human_time_estimate and human_total_time_spent should be revisited to ensure they are parsed and displayed correctly in the UI.


68-74: The Links interface provides URLs related to a ticket. Ensure all URLs are validated and securely handled to prevent injection attacks.


76-79: The TaskCompletionStatus interface is straightforward and effectively captures the completion status of tasks within a ticket.


81-82: The type aliases GitlabTicketInput and GitlabTicketOutput are correctly defined as partials of GitlabTicket, facilitating flexible API interactions.

packages/api/src/ticketing/ticket/types/mappingsTypes.ts (2)

1-2: Ensure that all imported mappers are utilized within the file. The import of GitlabTicketMapper is correctly placed and used in the mapping object.


15-44: The ticketUnificationMapping object correctly binds methods from various ticket mappers to handle unification and de-unification. This setup facilitates easy extension and maintenance of ticket handling across different platforms.

packages/api/src/ticketing/ticket/services/gitlab/index.ts (1)

14-105: The GitlabService class is well-structured and implements necessary methods to interact with GitLab's ticketing API. Ensure that error handling is robust and that all external calls are secured.

packages/api/src/ticketing/comment/services/gitlab/mappers.ts (1)

13-123: The GitlabCommentMapper class effectively provides methods for transforming comments between GitLab-specific and unified formats. Ensure that the TODO items, especially regarding attachments, are addressed promptly to avoid incomplete features.

Comment on lines +107 to +120
async getCollectionUuidFromRemoteId(remote_id: string, remote_platform: string) {
try {
const res = await this.prisma.tcg_collections.findFirst({
where: {
remote_id: remote_id,
remote_platform: remote_platform,
},
});
if (!res) return;
return res.id_tcg_collection;
} catch (error) {
throw new Error(error);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling the case where the result is null more gracefully.

-      if (!res) return;
+      if (!res) throw new Error(`Collection not found for remote ID ${remote_id} and platform ${remote_platform}`);

This change ensures that the function throws an informative error when no collection is found, rather than silently failing.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async getCollectionUuidFromRemoteId(remote_id: string, remote_platform: string) {
try {
const res = await this.prisma.tcg_collections.findFirst({
where: {
remote_id: remote_id,
remote_platform: remote_platform,
},
});
if (!res) return;
return res.id_tcg_collection;
} catch (error) {
throw new Error(error);
}
}
async getCollectionUuidFromRemoteId(remote_id: string, remote_platform: string) {
try {
const res = await this.prisma.tcg_collections.findFirst({
where: {
remote_id: remote_id,
remote_platform: remote_platform,
},
});
if (!res) throw new Error(`Collection not found for remote ID ${remote_id} and platform ${remote_platform}`);
return res.id_tcg_collection;
} catch (error) {
throw new Error(error);
}
}

Comment on lines +122 to +134
async getCollectionRemoteIdFromUuid(uuid: string) {
try {
const res = await this.prisma.tcg_collections.findFirst({
where: {
id_tcg_collection: uuid,
},
});
if (!res) throw new Error(`tcg_contact not found for uuid ${uuid}`);
return res.remote_id;
} catch (error) {
throw new Error(error);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure consistent error messages for better debugging and user feedback.

-      if (!res) throw new Error(`tcg_contact not found for uuid ${uuid}`);
+      if (!res) throw new Error(`Collection not found for uuid ${uuid}`);

This change corrects the error message to reflect the actual entity being queried, which is a collection, not a contact.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async getCollectionRemoteIdFromUuid(uuid: string) {
try {
const res = await this.prisma.tcg_collections.findFirst({
where: {
id_tcg_collection: uuid,
},
});
if (!res) throw new Error(`tcg_contact not found for uuid ${uuid}`);
return res.remote_id;
} catch (error) {
throw new Error(error);
}
}
async getCollectionRemoteIdFromUuid(uuid: string) {
try {
const res = await this.prisma.tcg_collections.findFirst({
where: {
id_tcg_collection: uuid,
},
});
if (!res) throw new Error(`Collection not found for uuid ${uuid}`);
return res.remote_id;
} catch (error) {
throw new Error(error);
}
}

Comment on lines +136 to +149
async getTicketUuidFromRemoteId(remote_id: string, remote_platform: string) {
try {
const res = await this.prisma.tcg_tickets.findFirst({
where: {
remote_id: remote_id,
remote_platform: remote_platform,
},
});
if (!res) return;
return res.id_tcg_ticket;
} catch (error) {
throw new Error(error);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling the case where the result is null more gracefully.

-      if (!res) return;
+      if (!res) throw new Error(`Ticket not found for remote ID ${remote_id} and platform ${remote_platform}`);

This change ensures that the function throws an informative error when no ticket is found, rather than silently failing.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async getTicketUuidFromRemoteId(remote_id: string, remote_platform: string) {
try {
const res = await this.prisma.tcg_tickets.findFirst({
where: {
remote_id: remote_id,
remote_platform: remote_platform,
},
});
if (!res) return;
return res.id_tcg_ticket;
} catch (error) {
throw new Error(error);
}
}
async getTicketUuidFromRemoteId(remote_id: string, remote_platform: string) {
try {
const res = await this.prisma.tcg_tickets.findFirst({
where: {
remote_id: remote_id,
remote_platform: remote_platform,
},
});
if (!res) throw new Error(`Ticket not found for remote ID ${remote_id} and platform ${remote_platform}`);
return res.id_tcg_ticket;
} catch (error) {
throw new Error(error);
}
}

Comment on lines +151 to +163
async getTicketRemoteIdFromUuid(uuid: string) {
try {
const res = await this.prisma.tcg_tickets.findFirst({
where: {
id_tcg_ticket: uuid,
},
});
if (!res) throw new Error(`tcg_contact not found for uuid ${uuid}`);
return res.remote_id;
} catch (error) {
throw new Error(error);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure consistent error messages for better debugging and user feedback.

-      if (!res) throw new Error(`tcg_contact not found for uuid ${uuid}`);
+      if (!res) throw new Error(`Ticket not found for uuid ${uuid}`);

This change corrects the error message to reflect the actual entity being queried, which is a ticket, not a contact.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async getTicketRemoteIdFromUuid(uuid: string) {
try {
const res = await this.prisma.tcg_tickets.findFirst({
where: {
id_tcg_ticket: uuid,
},
});
if (!res) throw new Error(`tcg_contact not found for uuid ${uuid}`);
return res.remote_id;
} catch (error) {
throw new Error(error);
}
}
async getTicketRemoteIdFromUuid(uuid: string) {
try {
const res = await this.prisma.tcg_tickets.findFirst({
where: {
id_tcg_ticket: uuid,
},
});
if (!res) throw new Error(`Ticket not found for uuid ${uuid}`);
return res.remote_id;
} catch (error) {
throw new Error(error);
}
}

Comment on lines +16 to +67
async desunify(
source: UnifiedTicketInput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): Promise<GitlabTicketInput> {

// TODO - Project_id should be mandatory field for gitlab provider

const remote_project_id = await this.utils.getCollectionRemoteIdFromUuid(source.project_id);




const result: GitlabTicketInput = {
title: source.name,
description: source.description ? source.description : '',
project_id: Number(remote_project_id)
};

if (source.status) {
result.type = source.status === "OPEN" ? "opened" : "closed";
}

if (source.assigned_to && source.assigned_to.length > 0) {
const data = await this.utils.getAsigneeRemoteIdFromUserUuid(
source.assigned_to[0],
);
result.assignee = {
id: Number(data),
};
}

if (source.tags) {
result.labels = source.tags ? source.tags : []
}

// TODO - Custom fields mapping
// if (customFieldMappings && source.field_mappings) {
// result.meta = {}; // Ensure meta exists
// for (const [k, v] of Object.entries(source.field_mappings)) {
// const mapping = customFieldMappings.find(
// (mapping) => mapping.slug === k,
// );
// if (mapping) {
// result.meta[mapping.remote_id] = v;
// }
// }
// }

return result;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider implementing the custom fields mapping logic.

The commented-out code for custom fields mapping (lines 54-65) suggests a planned feature that is not yet implemented. Would you like me to help implement this feature or should we track this as a task in your project management tool?

Comment on lines 32 to 121
async addComment(
commentData: GitlabCommentInput,
linkedUserId: string,
remoteIdTicket: string,
): Promise<ApiResponse<GitlabCommentOutput>> {
try {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'gitlab',
vertical: 'ticketing',
},
});

let uploads = [];
const uuids = commentData.attachment as any[];
if (uuids && uuids.length > 0) {
const attachmentPromises = uuids.map(async (uuid) => {
const res = await this.prisma.tcg_attachments.findUnique({
where: {
id_tcg_attachment: uuid.extra,
},
});
if (!res) {
throw new Error(`tcg_attachment not found for uuid ${uuid}`);
}
// Assuming you want to construct the right binary attachment here
// For now, we'll just return the URL
const stats = fs.statSync(res.file_url);
return {
url: res.file_url,
name: res.file_name,
size: stats.size,
content_type: 'application/pdf', //todo
};
});
uploads = await Promise.all(attachmentPromises);
}

// Assuming you want to modify the comment object here
// For now, we'll just add the uploads to the comment
const data = {
...commentData,
attachments: uploads,
};

const ticket = await this.prisma.tcg_tickets.findUnique({
where: {
id_tcg_ticket: remoteIdTicket,
},
select: {
collections: true
},
});

const remote_project_id = await this.utils.getCollectionRemoteIdFromUuid(ticket.collections[0])






const resp = await axios.post(
`${connection.account_url}/projects/${remote_project_id}/issues/${remoteIdTicket}/notes`,
JSON.stringify(data),
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
},
);

return {
data: resp.data,
message: 'Gitlab comment created',
statusCode: 201,
};
} catch (error) {
handleServiceError(
error,
this.logger,
'Gitlab',
TicketingObject.comment,
ActionType.POST,
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor to improve error handling and reduce code duplication.

The methods addComment and syncComments share similar structures and error handling strategies. Consider refactoring to a common method that handles the repetitive tasks such as fetching the connection and handling errors.

Comment on lines +46 to +69
let uploads = [];
const uuids = commentData.attachment as any[];
if (uuids && uuids.length > 0) {
const attachmentPromises = uuids.map(async (uuid) => {
const res = await this.prisma.tcg_attachments.findUnique({
where: {
id_tcg_attachment: uuid.extra,
},
});
if (!res) {
throw new Error(`tcg_attachment not found for uuid ${uuid}`);
}
// Assuming you want to construct the right binary attachment here
// For now, we'll just return the URL
const stats = fs.statSync(res.file_url);
return {
url: res.file_url,
name: res.file_name,
size: stats.size,
content_type: 'application/pdf', //todo
};
});
uploads = await Promise.all(attachmentPromises);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle potential errors in attachment processing more robustly.

-                        throw new Error(`tcg_attachment not found for uuid ${uuid}`);
+                        this.logger.error(`Attachment not found for uuid ${uuid}. Skipping attachment.`);
+                        return null;

This change logs an error and skips the attachment if it is not found, rather than throwing an error, which could stop the processing of other attachments.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let uploads = [];
const uuids = commentData.attachment as any[];
if (uuids && uuids.length > 0) {
const attachmentPromises = uuids.map(async (uuid) => {
const res = await this.prisma.tcg_attachments.findUnique({
where: {
id_tcg_attachment: uuid.extra,
},
});
if (!res) {
throw new Error(`tcg_attachment not found for uuid ${uuid}`);
}
// Assuming you want to construct the right binary attachment here
// For now, we'll just return the URL
const stats = fs.statSync(res.file_url);
return {
url: res.file_url,
name: res.file_name,
size: stats.size,
content_type: 'application/pdf', //todo
};
});
uploads = await Promise.all(attachmentPromises);
}
let uploads = [];
const uuids = commentData.attachment as any[];
if (uuids && uuids.length > 0) {
const attachmentPromises = uuids.map(async (uuid) => {
const res = await this.prisma.tcg_attachments.findUnique({
where: {
id_tcg_attachment: uuid.extra,
},
});
if (!res) {
this.logger.error(`Attachment not found for uuid ${uuid}. Skipping attachment.`);
return null;
}
// Assuming you want to construct the right binary attachment here
// For now, we'll just return the URL
const stats = fs.statSync(res.file_url);
return {
url: res.file_url,
name: res.file_name,
size: stats.size,
content_type: 'application/pdf', //todo
};
});
uploads = await Promise.all(attachmentPromises);
}

url: res.file_url,
name: res.file_name,
size: stats.size,
content_type: 'application/pdf', //todo
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider specifying the content type dynamically based on the file type.

-                        content_type: 'application/pdf', //todo
+                        content_type: this.determineContentType(res.file_url),

This change replaces the hardcoded content type with a dynamic method that determines the content type based on the file extension, improving flexibility and correctness.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
content_type: 'application/pdf', //todo
content_type: this.determineContentType(res.file_url),

Comment on lines +304 to +306
if (ticket.project_id) {
data = { ...data, collections: [ticket.project_id] }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure that the collections field is handled correctly when saving tickets.

-            data = { ...data, collections: [ticket.project_id] }
+            data = { ...data, collections: ticket.project_id ? [ticket.project_id] : [] }

This change adds a conditional check to ensure that the collections field is only populated if project_id is present, preventing potential issues with null values.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (ticket.project_id) {
data = { ...data, collections: [ticket.project_id] }
}
if (ticket.project_id) {
data = { ...data, collections: ticket.project_id ? [ticket.project_id] : [] }
}

@@ -298,6 +298,7 @@ export class SyncService implements OnModuleInit {
if (comment.creator_type) {
data = { ...data, creator_type: comment.creator_type };
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure that the opts object is correctly handled when saving comments.

+            if (Object.keys(opts).length === 0) throw new Error('Creator type is invalid or not provided.');

This change adds a check to ensure that the opts object, which depends on the creator_type, is not empty before proceeding to save the comment, preventing issues with invalid or missing creator types.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (Object.keys(opts).length === 0) throw new Error('Creator type is invalid or not provided.');

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

Out of diff range and nitpick comments (1)
packages/api/src/ticketing/ticket/services/ticket.service.ts (1)

Line range hint 71-71: Consider optimizing database queries within addTicket to reduce the number of calls, especially for checks that could be combined.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d3a0199 and 7f12892.
Files selected for processing (7)
  • packages/api/src/ticketing/comment/services/gitlab/index.ts (1 hunks)
  • packages/api/src/ticketing/comment/services/gitlab/mappers.ts (1 hunks)
  • packages/api/src/ticketing/comment/sync/sync.service.ts (5 hunks)
  • packages/api/src/ticketing/ticket/services/gitlab/index.ts (1 hunks)
  • packages/api/src/ticketing/ticket/services/gitlab/mappers.ts (1 hunks)
  • packages/api/src/ticketing/ticket/services/ticket.service.ts (1 hunks)
  • packages/api/src/ticketing/ticket/sync/sync.service.ts (4 hunks)
Files skipped from review as they are similar to previous changes (6)
  • packages/api/src/ticketing/comment/services/gitlab/index.ts
  • packages/api/src/ticketing/comment/services/gitlab/mappers.ts
  • packages/api/src/ticketing/comment/sync/sync.service.ts
  • packages/api/src/ticketing/ticket/services/gitlab/index.ts
  • packages/api/src/ticketing/ticket/services/gitlab/mappers.ts
  • packages/api/src/ticketing/ticket/sync/sync.service.ts
Additional comments not posted (2)
packages/api/src/ticketing/ticket/services/ticket.service.ts (2)

Line range hint 71-71: Ensure that the remote_data parameter is consistently used or documented if its usage is conditional.

Verification successful

The usage of the remote_data parameter in the addTicket method of ticket.service.ts has been verified. It is consistently used and appropriately documented as an optional parameter. The parameter is involved in conditional checks and database operations, aligning with its intended usage.

  • Location: ticket.service.ts, method addTicket
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `remote_data` parameter in `addTicket` method.

# Test: Search for the parameter usage. Expect: Consistent usage or conditional documentation.
rg --type typescript $'remote_data' packages/api/src/ticketing/ticket/services/ticket.service.ts

Length of output: 130



Script:

#!/bin/bash
# Description: Re-verify the usage of `remote_data` parameter in `addTicket` method by correcting the previous script error.

# Test: Search for the parameter usage. Expect: Consistent usage or conditional documentation.
rg 'remote_data' packages/api/src/ticketing/ticket/services/ticket.service.ts

Length of output: 744


471-471: Validate the transformation logic in getTickets to ensure that the field mappings are correctly converted to the desired format.

Verification successful

The search results confirm the presence and usage of fieldMappingsMap within the getTickets method in the ticket.service.ts file. The code snippets show that fieldMappingsMap is initialized as a new Map, and mappings are set based on the slug of an attribute and associated data. The map is then converted into an array of objects, which likely represents the transformed data structure.

This indicates that the transformation logic for field mappings is implemented as expected, converting the mappings into a desired format using a map and array conversion. This aligns with the original review comment's concern about validating the transformation logic.

Given this information, the transformation logic appears to be correctly implemented, and the field mappings are being converted to the desired format as per the snippets provided.

The transformation logic in `getTickets` for handling field mappings appears to be correctly implemented. The usage of `fieldMappingsMap` to map and convert data is evident and aligns with expected practices for data transformation in TypeScript:

- **Initialization and Mapping**: A new `Map` is created, and mappings are set based on attributes and data.
- **Conversion to Array**: The map is converted into an array of objects, which likely represents the final transformed structure.

This confirms that the field mappings are being correctly converted to the desired format.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the transformation logic for field mappings in `getTickets`.

# Test: Check the transformation logic and ensure it matches the expected format.
rg --type typescript $'fieldMappingsMap' packages/api/src/ticketing/ticket/services/ticket.service.ts

Length of output: 135



Script:

#!/bin/bash
# Description: Re-verify the transformation logic for field mappings in `getTickets`.

# Corrected Test: Check the transformation logic and ensure it matches the expected format.
rg 'fieldMappingsMap' packages/api/src/ticketing/ticket/services/ticket.service.ts

Length of output: 411

@@ -468,6 +468,7 @@ export class TicketService {
completed_at: ticket.completed_at || null,
priority: ticket.priority || '',
assigned_to: ticket.assigned_to || [],
collections: ticket.collections || [],
Copy link
Contributor

Choose a reason for hiding this comment

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

The method getTickets should handle cases where data is not present or is outdated. Consider adding explicit error handling or data validation steps.

+ if (!tickets) {
+   throw new Error('No tickets found for the given criteria');
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
collections: ticket.collections || [],
collections: ticket.collections || [],

Complete the implementation of updateTicket method or remove it if it's not needed. Currently, it lacks functionality.

+ // Implementation needed for updating tickets

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
collections: ticket.collections || [],
collections: ticket.collections || [],
// Implementation needed for updating tickets

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7f12892 and e144944.
Files selected for processing (1)
  • packages/shared/src/utils.ts (148 hunks)
Files not summarized due to errors (1)
  • packages/shared/src/utils.ts: Error: Message exceeds token limit
Additional comments not posted (1)
packages/shared/src/utils.ts (1)

394-402: The gitlab provider configuration has been added and marked as active. Ensure that the scopes and urls are correctly configured and tested, as these are critical for the integration's functionality.

Comment on lines +111 to +116
},
'accelo': {
scopes: '',
urls: {
docsUrl: 'https://api.accelo.com/docs/#introduction',
authBaseUrl: '/oauth2/v0/authorize',
authBaseUrl: '/oauth2/v0/authorize',
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure that the authBaseUrl for the 'accelo' provider starts with a valid protocol (http or https). Relative URLs might lead to runtime errors when constructing full URLs.

Comment on lines +2164 to +2172
name: providerName,
urls: {
docsUrl: config.urls.docsUrl,
apiUrl: config.urls.apiUrl,
authBaseUrl: config.urls.authBaseUrl,
},
scopes: config.scopes,
logoPath: config.logoPath,
description: config.description,
Copy link
Contributor

Choose a reason for hiding this comment

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

The function providersArray should include error handling or logging to manage cases where the provider or vertical does not exist. This would improve debugging and maintainability.

Would you like me to add error handling or logging to this function?

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: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e144944 and 96d022b.
Files selected for processing (3)
  • apps/client-ts/src/components/Connection/columns.tsx (2 hunks)
  • apps/client-ts/src/components/Events/columns.tsx (2 hunks)
  • packages/shared/src/utils.ts (148 hunks)
Files not summarized due to errors (1)
  • packages/shared/src/utils.ts: Error: Message exceeds token limit
Files skipped from review due to trivial changes (1)
  • apps/client-ts/src/components/Events/columns.tsx
Additional comments not posted (5)
apps/client-ts/src/components/Connection/columns.tsx (3)

13-13: Import of getLogoURL is correctly placed and used in the app column definition.


116-116: The use of getLogoURL to dynamically fetch logos based on the provider enhances the UI's adaptability and maintainability.


116-116: The dynamic rendering of the app logo and name in the app column is well-implemented, enhancing the visual appeal and informational value of the table.

packages/shared/src/utils.ts (2)

111-116: Ensure that the authBaseUrl for the 'accelo' provider starts with a valid protocol (http or https).

This issue was previously flagged and remains valid. Relative URLs might lead to runtime errors when constructing full URLs.


2164-2172: Consider adding error handling or logging to manage cases where the provider or vertical does not exist.

This would improve debugging and maintainability. Would you like me to add error handling or logging to this function?

Comment on lines +17 to +23
customPropertiesUrl?: string;
authStrategy?: AuthStrategy;
urls: {
docsUrl: string;
apiUrl: string;
authBaseUrl?: string; // url used to authorize an application on behalf of the user (only when authStrategy is oauth2)
customPropertiesUrl?: string;
customPropertiesUrl?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure consistent handling of customPropertiesUrl across different provider configurations.

It's important to ensure that the customPropertiesUrl is consistently handled across all provider configurations. Consider adding validation or a default value to manage cases where this property might be omitted.

@rajesh-jonnalagadda
Copy link
Contributor

rajesh-jonnalagadda commented May 11, 2024

@mit-27 I think you have missed the below issues.

  1. For every request, the response we will get is paginated data. (which is limited to 20 only).
  2. Sometimes we are getting server 500 internal error which needs a re-try mechanism that is not handled.
    I have worked on the pagination and re-try mechanism as part of contributing to this feature. If you agree I can take your branch and cherry-pick my pagination changes into your branch(if not needed refer to this link. https://docs.gitlab.com/ee/api/rest/index.html#keyset-based-pagination)

@mit-27
Copy link
Contributor Author

mit-27 commented May 11, 2024

Hi @rajeshj11,thank you for addressing the issues. However, we will handle pagination later, and we have also created an issue for it. If you would like to work on it, feel free to pick it up once it is merged.

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 96d022b and 7cb9863.
Files selected for processing (1)
  • packages/api/src/@core/connections/ticketing/services/gitlab/gitlab.service.ts (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/api/src/@core/connections/ticketing/services/gitlab/gitlab.service.ts

@naelob naelob merged commit d2ee451 into panoratech:main May 13, 2024
10 of 13 checks passed
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.

feat: Add Gitlab integration to ticketing vertical
4 participants