Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vscode): Add private method 'ensureOctokitInstance' to resolve Octokit's common logic. #562

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
bbanderson marked this conversation as resolved.
Show resolved Hide resolved
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);
bbanderson marked this conversation as resolved.
Show resolved Hide resolved
}
}

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> {
bbanderson marked this conversation as resolved.
Show resolved Hide resolved
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>;
bbanderson marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading