Skip to content

Commit

Permalink
fix(vscode, engine): error handing while crawling pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ytaek committed Sep 29, 2023
1 parent 2973b25 commit 332cb05
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
22 changes: 19 additions & 3 deletions packages/analysis-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
10 changes: 6 additions & 4 deletions packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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, {
Expand Down
4 changes: 4 additions & 0 deletions packages/vscode/src/setting-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions packages/vscode/src/webview-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<ClusterNode[]>(`${ANALYZE_DATA_KEY}_${baseBranchName}`);
// Disable Cache temporarily
// const storedAnalyzedData = context.workspaceState.get<ClusterNode[]>(`${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);
}

Expand Down

0 comments on commit 332cb05

Please sign in to comment.