| 57 | }; |
| 58 | |
| 59 | export class GithubService implements GitProvider { |
| 60 | private app: App; |
| 61 | private appId: string; |
| 62 | private privateKey: string; |
| 63 | private gitInstallationUrl: string; |
| 64 | private installationId: string; |
| 65 | private octokit: Octokit; |
| 66 | public readonly name = EnumGitProvider.Github; |
| 67 | public readonly domain = "github.com"; |
| 68 | constructor( |
| 69 | private readonly providerOrganizationProperties: GitHubProviderOrganizationProperties, |
| 70 | private readonly providerConfiguration: GitHubConfiguration, |
| 71 | private readonly logger: ILogger |
| 72 | ) {} |
| 73 | |
| 74 | getAuthData(): Promise<OAuthTokens | null> { |
| 75 | return Promise.resolve(null); |
| 76 | } |
| 77 | |
| 78 | isAuthDataRefreshed(): Promise<boolean> { |
| 79 | return Promise.resolve(false); |
| 80 | } |
| 81 | |
| 82 | async init(): Promise<void> { |
| 83 | const { |
| 84 | appId, |
| 85 | privateKey: envPrivateKey, |
| 86 | installationUrl, |
| 87 | } = this.providerConfiguration; |
| 88 | |
| 89 | this.gitInstallationUrl = installationUrl; |
| 90 | this.appId = appId; |
| 91 | this.privateKey = envPrivateKey; |
| 92 | this.installationId = this.providerOrganizationProperties.installationId; |
| 93 | |
| 94 | if (!appId || !envPrivateKey || !installationUrl) { |
| 95 | this.logger.error("Missing Github configuration"); |
| 96 | throw new Error("Missing Github configuration"); |
| 97 | } |
| 98 | |
| 99 | const privateKey = this.getFormattedPrivateKey(this.privateKey); |
| 100 | this.app = new App({ |
| 101 | appId: this.appId, |
| 102 | privateKey, |
| 103 | }); |
| 104 | |
| 105 | if (this.installationId) { |
| 106 | this.octokit = await this.getInstallationOctokit(this.installationId); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | async getCloneUrl({ owner, repositoryName }: CloneUrlArgs): Promise<string> { |
| 111 | const token = await this.getToken(); |
| 112 | return `https://x-access-token:${token}@${this.domain}/${owner}/${repositoryName}.git`; |
| 113 | } |
| 114 | |
| 115 | async getAmplicationBotIdentity(): Promise<Bot | null> { |
| 116 | const data: { |
nothing calls this directly
no outgoing calls
no test coverage detected