| 37 | import { CustomError } from "../../utils/custom-error"; |
| 38 | |
| 39 | export class GitLabService implements GitProvider { |
| 40 | private clientId: string; |
| 41 | private clientSecret: string; |
| 42 | private redirectUri: string; |
| 43 | private auth: OAuthTokens; |
| 44 | public readonly name = EnumGitProvider.GitLab; |
| 45 | public readonly domain = "gitlab.com"; |
| 46 | private logger: ILogger; |
| 47 | private gitlab: InstanceType<typeof Gitlab<true>>; |
| 48 | private isTokenRefreshed = false; |
| 49 | |
| 50 | constructor( |
| 51 | private readonly providerOrganizationProperties: OAuthProviderOrganizationProperties, |
| 52 | private readonly providerConfiguration: GitLabConfiguration, |
| 53 | logger: ILogger |
| 54 | ) { |
| 55 | this.logger = logger.child({ |
| 56 | metadata: { |
| 57 | className: GitLabService.name, |
| 58 | }, |
| 59 | }); |
| 60 | |
| 61 | const { accessToken, refreshToken, expiresAt, tokenType, scopes } = |
| 62 | providerOrganizationProperties; |
| 63 | |
| 64 | this.auth = { accessToken, refreshToken, expiresAt, tokenType, scopes }; |
| 65 | |
| 66 | const { clientId, clientSecret, redirectUri } = this.providerConfiguration; |
| 67 | if (!clientId || !clientSecret || !redirectUri) { |
| 68 | this.logger.error( |
| 69 | "Missing GitLab configuration (clientId, clientSecret, redirectUri)" |
| 70 | ); |
| 71 | throw new Error( |
| 72 | "Missing GitLab configuration (clientId, clientSecret, redirectUri)" |
| 73 | ); |
| 74 | } |
| 75 | this.clientId = clientId; |
| 76 | this.clientSecret = clientSecret; |
| 77 | this.redirectUri = redirectUri; |
| 78 | |
| 79 | this.gitlab = new Gitlab({ |
| 80 | oauthToken: this.auth.accessToken, |
| 81 | camelize: true, |
| 82 | }); |
| 83 | } |
| 84 | getAuthData(): Promise<OAuthTokens> { |
| 85 | return Promise.resolve(this.auth); |
| 86 | } |
| 87 | isAuthDataRefreshed(): Promise<boolean> { |
| 88 | return Promise.resolve(this.isTokenRefreshed); |
| 89 | } |
| 90 | |
| 91 | async init(): Promise<void> { |
| 92 | this.logger.info("GitLabService initialized"); |
| 93 | } |
| 94 | |
| 95 | getGitInstallationUrl(amplicationWorkspaceId: string): Promise<string> { |
| 96 | const scope = "api"; |
nothing calls this directly
no outgoing calls
no test coverage detected