-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #421 from mit-27/gitlab-connector
Gitlab Connector
- Loading branch information
Showing
40 changed files
with
1,555 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
packages/api/src/ticketing/collection/services/gitlab/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.