Skip to content

Commit

Permalink
Merge branch 'githru:main' into Fake
Browse files Browse the repository at this point in the history
  • Loading branch information
KyuTae98 committed Sep 30, 2023
2 parents 35a229e + 6cc69f0 commit a825ba7
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "githru-vscode-ext",
"version": "0.5.0",
"version": "0.6.0",
"description": "githru-vscode-ext root package.json",
"scripts": {
"build:all": "npm run build --workspaces",
Expand Down
2 changes: 1 addition & 1 deletion packages/analysis-engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@githru-vscode-ext/analysis-engine",
"version": "0.5.0",
"version": "0.6.0",
"description": "analysis-engine module for githru",
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down
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
4 changes: 2 additions & 2 deletions packages/view/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@githru-vscode-ext/view",
"version": "0.5.0",
"version": "0.6.0",
"description": "view module for githru",
"engines": {
"node": ">=16",
Expand Down Expand Up @@ -47,7 +47,7 @@
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.22.15",
"@babel/runtime": "^7.18.9",
"@githru-vscode-ext/analysis-engine": "^0.5.0",
"@githru-vscode-ext/analysis-engine": "^0.6.0",
"@playwright/test": "^1.37.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@svgr/webpack": "^8.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/view/src/components/Detail/Detail.hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const useToggleHook = (init = false): UseToggleHook => {
};

export const useCommitListHide = (commitNodeListInCluster: CommitNode[]) => {
const list = getSummaryCommitList(commitNodeListInCluster);
const strech = commitNodeListInCluster.slice(0, commitNodeListInCluster.length - 5).reverse();
const list = getSummaryCommitList(commitNodeListInCluster).reverse();
const strech = commitNodeListInCluster.slice(5, commitNodeListInCluster.length).reverse();
const [toggle, handleToggle] = useToggleHook();
const commitNodeList = toggle ? [...list, ...strech] : list;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { fakeFirstClusterNode, fakeSecondClusterNode, fakePrev } from "../../../tests/fakeAsset";
import {
fakeFirstClusterNode,
fakeSecondClusterNode,
fakePrev,
} from "../../../tests/fakeAsset";

import { selectedDataUpdater } from "./VerticalClusterList.util";

const EmptyArrayAddSelectedDataUpdater = selectedDataUpdater(fakeFirstClusterNode, 0);
const EmptyArrayAddSelectedDataUpdater = selectedDataUpdater(
fakeFirstClusterNode,
0,
);
const PrevAddSelectedDataUpdater = selectedDataUpdater(fakeFirstClusterNode, 5);
const RemoveSelectedDataUpdater = selectedDataUpdater(fakeSecondClusterNode, 1);

Expand Down
6 changes: 6 additions & 0 deletions packages/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ Calling out known issues can help limit users opening duplicate issues against y

## Release Notes

### 0.6.0
- branch selector
- reset github auth
- error handling for pr/auth
- e2e test

### 0.5.0
- login by github auth
- fix minor ui issues
Expand Down
9 changes: 7 additions & 2 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/githru/githru-vscode-ext",
"type": "git"
},
"version": "0.5.0",
"version": "0.6.0",
"engines": {
"vscode": "^1.67.0"
},
Expand Down Expand Up @@ -52,6 +52,11 @@
"command": "githru.command.login.github",
"title": "Login with Github",
"category": "Githru"
},
{
"command": "githru.command.reset.github_auth",
"title": "Reset GitHub Authentication saved previously",
"category": "Githru"
}
],
"configuration": {
Expand Down Expand Up @@ -84,7 +89,7 @@
"test": "node ./out/test/runTest.js"
},
"dependencies": {
"@githru-vscode-ext/analysis-engine": "^0.5.0",
"@githru-vscode-ext/analysis-engine": "^0.6.0",
"@octokit/rest": "^20.0.1",
"node-fetch": "^3.3.2"
},
Expand Down
1 change: 1 addition & 0 deletions packages/vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export const COMMAND_PREFIX = "githru.command";
export const COMMAND_LAUNCH = `${COMMAND_PREFIX}.launch`;
export const COMMAND_RELOAD = `${COMMAND_PREFIX}.reload`;
export const COMMAND_LOGIN_WITH_GITHUB = `${COMMAND_PREFIX}.login.github`;
export const COMMAND_RESET_GITHUB_AUTH = `${COMMAND_PREFIX}.reset.github_auth`;
19 changes: 13 additions & 6 deletions packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AnalysisEngine } from "@githru-vscode-ext/analysis-engine";
import * as vscode from "vscode";

import { COMMAND_LAUNCH, COMMAND_LOGIN_WITH_GITHUB } from "./commands";
import { COMMAND_LAUNCH, COMMAND_LOGIN_WITH_GITHUB, COMMAND_RESET_GITHUB_AUTH } from "./commands";
import { Credentials } from "./credentials";
import { GithubTokenUndefinedError, WorkspacePathUndefinedError } from "./errors/ExtensionError";
import { getGithubToken, setGithubToken } from "./setting-repository";
import { deleteGithubToken, 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 Expand Up @@ -104,7 +106,12 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.commands.executeCommand(COMMAND_LAUNCH);
});

subscriptions.concat([disposable, loginWithGithub]);
const resetGithubAuth = vscode.commands.registerCommand(COMMAND_RESET_GITHUB_AUTH, async () => {
await deleteGithubToken(secrets);
vscode.window.showInformationMessage(`Github Authentication reset.`);
});

subscriptions.concat([disposable, loginWithGithub, resetGithubAuth]);

myStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, -10);
myStatusBarItem.text = "githru";
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
2 changes: 1 addition & 1 deletion packages/vscode/src/utils/git.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export async function getGitConfig(

export const getRepo = (gitRemoteConfig: string) => {
const gitRemoteConfigPattern =
/(?:https?|git)(?::\/\/(?:\w+@)?|@)(?:github\.com)(?:\/|:)(?:(?<owner>.+?)\/(?<repo>.+?))(?:\.git|\/)?$/m;
/(?:https?|git)(?::\/\/(?:\w+@)?|@)(?:github\.com)(?:\/|:)(?:(?<owner>.+?)\/(?<repo>.+?))(?:\.git|\/)?(\S*)$/m;
const gitRemote = gitRemoteConfig.match(gitRemoteConfigPattern)?.groups;
if (!gitRemote) {
throw new Error("git remote config should be: [https?://|git@]${domain}/${owner}/${repo}.git");
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 a825ba7

Please sign in to comment.