From 332cb05b7c263fe29fe48a611c9ab98d8f3e66f1 Mon Sep 17 00:00:00 2001 From: "ytaek.kim" Date: Fri, 29 Sep 2023 23:43:35 +0900 Subject: [PATCH] fix(vscode, engine): error handing while crawling pull requests --- packages/analysis-engine/src/index.ts | 22 +++++++++++++++++++--- packages/vscode/src/extension.ts | 10 ++++++---- packages/vscode/src/setting-repository.ts | 4 ++++ packages/vscode/src/webview-loader.ts | 20 ++++++++++---------- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/packages/analysis-engine/src/index.ts b/packages/analysis-engine/src/index.ts index 0f882e37..612589ca 100644 --- a/packages/analysis-engine/src/index.ts +++ b/packages/analysis-engine/src/index.ts @@ -48,18 +48,34 @@ export class AnalysisEngine { }; public analyzeGit = async () => { + let isPRSuccess = true; if (this.isDebugMode) console.log("baseBranchName: ", this.baseBranchName); + const commitRaws = getCommitRaws(this.gitLog); if (this.isDebugMode) console.log("commitRaws: ", commitRaws); + const commitDict = buildCommitDict(commitRaws); - const pullRequests = await this.octokit.getPullRequests(); - if (this.isDebugMode) console.log("pullRequests: ", pullRequests); + if (this.isDebugMode) console.log("commitDict: ", commitDict); + + const pullRequests = await this.octokit.getPullRequests().catch((err) => { + console.error(err); + isPRSuccess = false; + return []; + }).then((pullRequests) => { + console.log("success, pr = ", pullRequests); + return pullRequests; + }); + if (this.isDebugMode) console.log("pullRequests: ", pullRequests, ); + const stemDict = buildStemDict(commitDict, this.baseBranchName); if (this.isDebugMode) console.log("stemDict: ", stemDict); const csmDict = buildCSMDict(commitDict, stemDict, this.baseBranchName, pullRequests); if (this.isDebugMode) console.log("csmDict: ", csmDict); - return csmDict; + return { + isPRSuccess, + csmDict + }; }; public updateArgs = (args: AnalysisEngineArgs) => { diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index b902b0b4..e569263b 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 } from "./commands"; import { Credentials } from "./credentials"; import { GithubTokenUndefinedError, WorkspacePathUndefinedError } from "./errors/ExtensionError"; -import { getGithubToken, setGithubToken } from "./setting-repository"; +import { getGithubToken, setGithubToken, } from "./setting-repository"; import { mapClusterNodesFrom } from "./utils/csm.mapper"; import { findGit, @@ -69,9 +69,11 @@ export async function activate(context: vscode.ExtensionContext) { auth: githubToken, baseBranchName, }); - const csmDict = await engine.analyzeGit(); - const clusterNodes = mapClusterNodesFrom(csmDict); - return clusterNodes; + + const { isPRSuccess, csmDict } = await engine.analyzeGit(); + if (isPRSuccess) console.log("crawling PR failed"); + + return mapClusterNodesFrom(csmDict); }; const webLoader = new WebviewLoader(extensionPath, context, { diff --git a/packages/vscode/src/setting-repository.ts b/packages/vscode/src/setting-repository.ts index 21ff129d..a82726b4 100644 --- a/packages/vscode/src/setting-repository.ts +++ b/packages/vscode/src/setting-repository.ts @@ -13,6 +13,10 @@ export const setGithubToken = async (secrets: vscode.SecretStorage, newGithubTok return await secrets.store(SETTING_PROPERTY_NAMES.GITHUB_TOKEN, newGithubToken); }; +export const deleteGithubToken = async (secrets: vscode.SecretStorage) => { + return await secrets.delete(SETTING_PROPERTY_NAMES.GITHUB_TOKEN); +} + export const setPrimaryColor = (color: string) => { const configuration = vscode.workspace.getConfiguration(); configuration.update(SETTING_PROPERTY_NAMES.PRIMARY_COLOR, color); diff --git a/packages/vscode/src/webview-loader.ts b/packages/vscode/src/webview-loader.ts index 5cdca944..53ae8133 100644 --- a/packages/vscode/src/webview-loader.ts +++ b/packages/vscode/src/webview-loader.ts @@ -2,7 +2,7 @@ import * as path from "path"; import * as vscode from "vscode"; import { getPrimaryColor, setPrimaryColor } from "./setting-repository"; -import type { ClusterNode } from "./utils/NodeTypes.temps"; +import type { ClusterNode } from "./types/Node"; const ANALYZE_DATA_KEY = "memento_analyzed_data"; @@ -31,18 +31,18 @@ export default class WebviewLoader implements vscode.Disposable { if (command === "fetchAnalyzedData" || command === "refresh") { const baseBranchName = (payload && JSON.parse(payload)) ?? (await fetchCurrentBranch()); - const storedAnalyzedData = context.workspaceState.get(`${ANALYZE_DATA_KEY}_${baseBranchName}`); + // Disable Cache temporarily + // const storedAnalyzedData = context.workspaceState.get(`${ANALYZE_DATA_KEY}_${baseBranchName}`); + // if (!storedAnalyzedData) { + + const analyzedData = await fetchClusterNodes(baseBranchName); + context.workspaceState.update(`${ANALYZE_DATA_KEY}_${baseBranchName}`, analyzedData); + const resMessage = { - command, - payload: storedAnalyzedData, + command, + payload: analyzedData, }; - if (!storedAnalyzedData) { - const analyzedData = await fetchClusterNodes(baseBranchName); - context.workspaceState.update(`${ANALYZE_DATA_KEY}_${baseBranchName}`, analyzedData); - resMessage.payload = analyzedData; - } - await this.respondToMessage(resMessage); }