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