* Static method to get the singleton instance of the `AuthenticatedGitClient`, * creating it if it has not yet been created.
()
| 164 | private static _authenticatedInstance: Promise<AuthenticatedGitClient> | null = null; |
| 165 | /** The previously configured user type. */ |
| 166 | private static _userType: 'user' | 'bot'; |
| 167 | |
| 168 | /** |
| 169 | * Static method to get the singleton instance of the `AuthenticatedGitClient`, |
| 170 | * creating it if it has not yet been created. |
| 171 | */ |
| 172 | static override async get(): Promise<AuthenticatedGitClient> { |
| 173 | if (AuthenticatedGitClient._token === null) { |
| 174 | throw new Error('No instance of `AuthenticatedGitClient` has been configured.'); |
| 175 | } |
| 176 | |
| 177 | // If there is no cached authenticated instance, create one and cache the promise |
| 178 | // immediately. This avoids constructing a client twice accidentally when e.g. waiting |
| 179 | // for the configuration to be loaded. |
| 180 | if (AuthenticatedGitClient._authenticatedInstance === null) { |
| 181 | AuthenticatedGitClient._authenticatedInstance = (async ( |
| 182 | token: string, |
| 183 | userType: UserType, |
| 184 | tokenEnvironmentVariable: TokenEnvironmentVariable | null, |
| 185 | ) => { |
| 186 | return new AuthenticatedGitClient( |
| 187 | token, |
| 188 | userType, |
| 189 | await getConfig([assertValidGithubConfig]), |
| 190 | undefined, |
| 191 | tokenEnvironmentVariable, |
no test coverage detected