diff --git a/packages/vscode/src/credentials.ts b/packages/vscode/src/credentials.ts index 2b85add5..158401c8 100644 --- a/packages/vscode/src/credentials.ts +++ b/packages/vscode/src/credentials.ts @@ -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) { @@ -48,25 +48,22 @@ export class Credentials { ); } - async getOctokit(): Promise { + /** Octokit 인스턴스가 없다면, 인증 세션을 새로 만듦으로써, Octokit 인스턴스가 항상 존재하도록 보장한다. */ + private async getOctokitInstance(): Promise { if (this.octokit) { return this.octokit; + } else { + const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone: true }); + this.octokit = await this.createOctokit(session); + return this.octokit; } + } - 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 { + return this.getOctokitInstance(); } async getAuth(): Promise { - if (this.octokit) { - return this.octokit.auth() as Promise; - } - - 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; + return (await this.getOctokitInstance()).auth() as Promise; } } diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 2fc0c8e6..c5da7b41 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -4,7 +4,7 @@ import * as vscode from "vscode"; import { COMMAND_LAUNCH, COMMAND_LOGIN_WITH_GITHUB, COMMAND_RESET_GITHUB_AUTH } from "./commands"; import { Credentials } from "./credentials"; import { GithubTokenUndefinedError, WorkspacePathUndefinedError } from "./errors/ExtensionError"; -import { deleteGithubToken, getGithubToken, setGithubToken, } from "./setting-repository"; +import { deleteGithubToken, getGithubToken, setGithubToken } from "./setting-repository"; import { mapClusterNodesFrom } from "./utils/csm.mapper"; import { findGit, @@ -18,7 +18,7 @@ import { import WebviewLoader from "./webview-loader"; let myStatusBarItem: vscode.StatusBarItem; -const projectName = 'githru'; +const projectName = "githru"; function normalizeFsPath(fsPath: string) { return fsPath.replace(/\\/g, "/"); @@ -58,12 +58,11 @@ export async function activate(context: vscode.ExtensionContext) { const fetchBranches = async () => await getBranches(gitPath, currentWorkspacePath); const fetchCurrentBranch = async () => { - let branchName; try { - branchName = await getCurrentBranchName(gitPath, currentWorkspacePath) + branchName = await getCurrentBranchName(gitPath, currentWorkspacePath); } catch (error) { - console.error(error); + console.error(error); } if (!branchName) {