-
Notifications
You must be signed in to change notification settings - Fork 200
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
Gitlab Connector #421
Changes from all commits
1632ad6
b8a3976
0ed466b
b612011
41e8104
0dbf755
d0746fc
cbc2f56
f2404a2
3143f5c
e3c2d16
6d88d1c
d3a0199
7f12892
e144944
96d022b
7cb9863
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -103,4 +103,62 @@ export class Utils { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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) return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return res.id_tcg_collection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
throw new Error(error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+107
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
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); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+122
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
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); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+136
to
+149
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
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); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+151
to
+163
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -68,6 +68,7 @@ export class CollectionService { | |||||||||
remote_data?: boolean, | ||||||||||
): Promise<UnifiedCollectionOutput[]> { | ||||||||||
try { | ||||||||||
console.log("In collection service : ", integrationId) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logging statement in - console.log("In collection service : ", integrationId)
+ if (process.env.DEBUG_MODE === 'true') {
+ console.log("In collection service : ", integrationId);
+ } Committable suggestion
Suggested change
|
||||||||||
const collections = await this.prisma.tcg_collections.findMany({ | ||||||||||
where: { | ||||||||||
remote_platform: integrationId.toLowerCase(), | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { LoggerService } from '@@core/logger/logger.service'; | ||
import { PrismaService } from '@@core/prisma/prisma.service'; | ||
import { EncryptionService } from '@@core/encryption/encryption.service'; | ||
import { TicketingObject } from '@ticketing/@lib/@types'; | ||
import { ApiResponse } from '@@core/utils/types'; | ||
import axios from 'axios'; | ||
import { ActionType, handleServiceError } from '@@core/utils/errors'; | ||
import { ServiceRegistry } from '../registry.service'; | ||
import { ICollectionService } from '@ticketing/collection/types'; | ||
import { GitlabCollectionInput, GitlabCollectionOutput } from './types'; | ||
import { DesunifyReturnType } from '@@core/utils/types/desunify.input'; | ||
|
||
@Injectable() | ||
export class GitlabService implements ICollectionService { | ||
constructor( | ||
private prisma: PrismaService, | ||
private logger: LoggerService, | ||
private cryptoService: EncryptionService, | ||
private registry: ServiceRegistry, | ||
) { | ||
this.logger.setContext( | ||
TicketingObject.collection.toUpperCase() + ':' + GitlabService.name, | ||
); | ||
this.registry.registerService('gitlab', this); | ||
} | ||
|
||
async syncCollections( | ||
linkedUserId: string, | ||
): Promise<ApiResponse<GitlabCollectionOutput[]>> { | ||
try { | ||
const connection = await this.prisma.connections.findFirst({ | ||
where: { | ||
id_linked_user: linkedUserId, | ||
provider_slug: 'gitlab', | ||
vertical: 'ticketing', | ||
}, | ||
}); | ||
|
||
// It fetches all project from gitlab | ||
// const resp = await axios.get(`${connection.account_url}/projects`, { | ||
// headers: { | ||
// 'Content-Type': 'application/json', | ||
// Authorization: `Bearer ${this.cryptoService.decrypt( | ||
// connection.access_token, | ||
// )}`, | ||
// }, | ||
// }); | ||
|
||
const currentUser = await axios.get(`${connection.account_url}/user`, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${this.cryptoService.decrypt( | ||
connection.access_token, | ||
)}`, | ||
}, | ||
}) | ||
|
||
const resp = await axios.get(`${connection.account_url}/users/${currentUser.data.id}/projects`, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${this.cryptoService.decrypt( | ||
connection.access_token, | ||
)}`, | ||
}, | ||
}) | ||
|
||
this.logger.log(`Synced gitlab collections !`); | ||
|
||
// console.log("In index of gitlab", JSON.stringify(resp.data)) | ||
|
||
|
||
return { | ||
data: resp.data, | ||
message: 'Gitlab collections retrieved', | ||
statusCode: 200, | ||
}; | ||
} catch (error) { | ||
handleServiceError( | ||
error, | ||
this.logger, | ||
'Gitlab', | ||
TicketingObject.collection, | ||
ActionType.GET, | ||
); | ||
} | ||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
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.
Committable suggestion