Skip to content

Commit

Permalink
feat(vscode): Add private method 'ensureOctokitInstance' to resolve O…
Browse files Browse the repository at this point in the history
…ctokit's common logic.
  • Loading branch information
bbanderson committed Jul 26, 2024
1 parent b38016a commit 576d35a
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions packages/vscode/src/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Credentials {
this.octokit = undefined;
}

registerListeners(context: vscode.ExtensionContext): void {
private registerListeners(context: vscode.ExtensionContext): void {
context.subscriptions.push(
vscode.authentication.onDidChangeSessions(async (e) => {
if (e.provider.id === GITHUB_AUTH_PROVIDER_ID) {
Expand All @@ -48,25 +48,21 @@ export class Credentials {
);
}

async getOctokit(): Promise<Octokit.Octokit> {
if (this.octokit) {
return this.octokit;
/** Octokit 인스턴스가 없다면, 인증 세션을 새로 만듦으로써, Octokit 인스턴스가 항상 존재하도록 보장한다. */
private async ensureOctokitInstance(): Promise<void> {
if (!this.octokit) {
const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone: true });
this.octokit = await this.createOctokit(session);
}
}

const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone: true });
this.octokit = await this.createOctokit(session);

return this.octokit;
async getOctokit(): Promise<Octokit.Octokit> {
await this.ensureOctokitInstance();
return this.octokit!;
}

async getAuth(): Promise<OctokitAuth> {
if (this.octokit) {
return this.octokit.auth() as Promise<OctokitAuth>;
}

const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone: true });
this.octokit = await this.createOctokit(session);

return this.octokit.auth() as Promise<OctokitAuth>;
await this.ensureOctokitInstance();
return this.octokit!.auth() as Promise<OctokitAuth>;
}
}

0 comments on commit 576d35a

Please sign in to comment.