From b6473342535f64310788987f2667ca7e90df4cd1 Mon Sep 17 00:00:00 2001 From: choisohyun Date: Mon, 9 Sep 2024 22:59:29 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20=ED=98=84=EC=9E=AC=20user=20?= =?UTF-8?q?=EA=B8=B0=EC=A4=80=EC=9C=BC=EB=A1=9C=20AI=20=EC=9A=94=EC=95=BD?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=ED=95=A8=EC=88=98=EB=A1=9C?= =?UTF-8?q?=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/analysis-engine/src/index.ts | 10 ++++++---- packages/analysis-engine/src/summary.ts | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/analysis-engine/src/index.ts b/packages/analysis-engine/src/index.ts index f6de204b..1149d621 100644 --- a/packages/analysis-engine/src/index.ts +++ b/packages/analysis-engine/src/index.ts @@ -7,7 +7,7 @@ import { buildCSMDict } from "./csm"; import getCommitRaws from "./parser"; import { PluginOctokit } from "./pluginOctokit"; import { buildStemDict } from "./stem"; -import { getSummary } from "./summary"; +import { getCurrentUserCommitSummary, getLatestCommitSummary } from "./summary"; type AnalysisEngineArgs = { isDebugMode?: boolean; @@ -75,9 +75,11 @@ export class AnalysisEngine { if (this.isDebugMode) console.log("stemDict: ", stemDict); const csmDict = buildCSMDict(commitDict, stemDict, this.baseBranchName, pullRequests); if (this.isDebugMode) console.log("csmDict: ", csmDict); - const nodes = stemDict.get(this.baseBranchName)?.nodes?.map(({commit}) => commit); - const geminiCommitSummary = await getSummary(nodes ? nodes?.slice(-10) : []); - if (this.isDebugMode) console.log("GeminiCommitSummary: ", geminiCommitSummary); + const latestCommitSummary = await getLatestCommitSummary(stemDict, this.baseBranchName); + if (this.isDebugMode) console.log("latestCommitSummary: ", latestCommitSummary); + + const currentUserCommitSummary = await getCurrentUserCommitSummary(stemDict, this.baseBranchName, this.octokit); + if (this.isDebugMode) console.log("currentUserCommitSummary: ", currentUserCommitSummary); return { isPRSuccess, diff --git a/packages/analysis-engine/src/summary.ts b/packages/analysis-engine/src/summary.ts index 2b91fe4f..7c880fdc 100644 --- a/packages/analysis-engine/src/summary.ts +++ b/packages/analysis-engine/src/summary.ts @@ -1,4 +1,5 @@ -import type { CommitRaw } from "./types"; +import type PluginOctokit from "./pluginOctokit"; +import type { CommitRaw, StemDict } from "./types"; const apiKey = process.env.GEMENI_API_KEY || ''; const apiUrl = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key="; @@ -29,6 +30,19 @@ export async function getSummary(csmNodes: CommitRaw[]) { } } +export async function getLatestCommitSummary(stemDict: StemDict, baseBranchName: string) { + const nodes = stemDict.get(baseBranchName)?.nodes?.map(({commit}) => commit); + + return await getSummary(nodes ? nodes?.slice(-10) : []) +} + +export async function getCurrentUserCommitSummary(stemDict: StemDict, baseBranchName: string, octokit: PluginOctokit) { + const { data } = await octokit.rest.users.getAuthenticated(); + const currentUserNodes = stemDict.get(baseBranchName)?.nodes?.filter(({commit}) => commit.author.name === data.login || commit.author.name === data.name)?.map(({commit}) => commit); + + return await getSummary(currentUserNodes ? currentUserNodes?.slice(-10) : []) +} + const prompt = `Proceed with the task of summarising the contents of the commit message provided. Procedure: From 982c89e6f0ab0f03a899f0b0f2b0e783bc2886c8 Mon Sep 17 00:00:00 2001 From: choisohyun Date: Wed, 11 Sep 2024 21:23:45 +0900 Subject: [PATCH 2/9] =?UTF-8?q?fix:=20summary=20filter=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/analysis-engine/src/summary.ts | 28 ++++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/analysis-engine/src/summary.ts b/packages/analysis-engine/src/summary.ts index 7c880fdc..1b541370 100644 --- a/packages/analysis-engine/src/summary.ts +++ b/packages/analysis-engine/src/summary.ts @@ -1,12 +1,13 @@ import type PluginOctokit from "./pluginOctokit"; import type { CommitRaw, StemDict } from "./types"; -const apiKey = process.env.GEMENI_API_KEY || ''; +const apiKey = process.env.GEMENI_API_KEY || ""; const apiUrl = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key="; export async function getSummary(csmNodes: CommitRaw[]) { - const commitMessages = csmNodes.map((csmNode) => csmNode.message.split('\n')[0]).join(', '); + const commitMessages = csmNodes.map((csmNode) => csmNode.message.split("\n")[0]).join(", "); + console.log("commitMessages: ", commitMessages); try { const response = await fetch(apiUrl + apiKey, { method: "POST", @@ -14,7 +15,7 @@ export async function getSummary(csmNodes: CommitRaw[]) { "Content-Type": "application/json", }, body: JSON.stringify({ - contents: [{parts: [{text: `${prompt} \n${commitMessages}`}]}], + contents: [{ parts: [{ text: `${prompt} \n${commitMessages}` }] }], }), }); @@ -31,16 +32,27 @@ export async function getSummary(csmNodes: CommitRaw[]) { } export async function getLatestCommitSummary(stemDict: StemDict, baseBranchName: string) { - const nodes = stemDict.get(baseBranchName)?.nodes?.map(({commit}) => commit); + const nodes = stemDict + .get(baseBranchName) + ?.nodes?.map(({ commit }) => commit) + .filter(({ message }) => !message.includes("Merge branch") && !message.includes("Merge pull request")); - return await getSummary(nodes ? nodes?.slice(-10) : []) + return await getSummary(nodes ? nodes?.slice(-10) : []); } export async function getCurrentUserCommitSummary(stemDict: StemDict, baseBranchName: string, octokit: PluginOctokit) { const { data } = await octokit.rest.users.getAuthenticated(); - const currentUserNodes = stemDict.get(baseBranchName)?.nodes?.filter(({commit}) => commit.author.name === data.login || commit.author.name === data.name)?.map(({commit}) => commit); + const currentUserNodes = stemDict + .get(baseBranchName) + ?.nodes?.filter( + ({ commit: { author, message } }) => + (author.name === data.login || author.name === data.name) && + !message.includes("Merge branch") && + !message.includes("Merge pull request") + ) + ?.map(({ commit }) => commit); - return await getSummary(currentUserNodes ? currentUserNodes?.slice(-10) : []) + return await getSummary(currentUserNodes ? currentUserNodes?.slice(-10) : []); } const prompt = `Proceed with the task of summarising the contents of the commit message provided. @@ -67,4 +79,4 @@ Output format: - {prefix (if any)}:{commit summary3} ‘’ -Commits:` +Commits:`; From 91b5a22d756818db909cb37cad1545617827ad84 Mon Sep 17 00:00:00 2001 From: choisohyun Date: Thu, 12 Sep 2024 22:18:18 +0900 Subject: [PATCH 3/9] =?UTF-8?q?refactor:=20merge=20commit=20=ED=8C=90?= =?UTF-8?q?=EB=B3=84=ED=95=98=EB=8A=94=20=ED=95=A8=EC=88=98=EC=99=80=20?= =?UTF-8?q?=EC=83=81=EC=88=98=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/analysis-engine/src/summary.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/analysis-engine/src/summary.ts b/packages/analysis-engine/src/summary.ts index 1b541370..66d7f5bd 100644 --- a/packages/analysis-engine/src/summary.ts +++ b/packages/analysis-engine/src/summary.ts @@ -1,15 +1,17 @@ import type PluginOctokit from "./pluginOctokit"; import type { CommitRaw, StemDict } from "./types"; -const apiKey = process.env.GEMENI_API_KEY || ""; -const apiUrl = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key="; +const API_KEY = process.env.GEMENI_API_KEY || ""; +const API_URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key="; +const MERGE_BRANCH = "Merge branch"; +const MERGE_PULL_REQUEST = "Merge pull request"; -export async function getSummary(csmNodes: CommitRaw[]) { +async function getSummary(csmNodes: CommitRaw[]) { const commitMessages = csmNodes.map((csmNode) => csmNode.message.split("\n")[0]).join(", "); console.log("commitMessages: ", commitMessages); try { - const response = await fetch(apiUrl + apiKey, { + const response = await fetch(API_URL + API_KEY, { method: "POST", headers: { "Content-Type": "application/json", @@ -31,11 +33,15 @@ export async function getSummary(csmNodes: CommitRaw[]) { } } +function isNonMergeCommit(message: string) { + return !message.includes(MERGE_BRANCH) && !message.includes(MERGE_PULL_REQUEST); +} + export async function getLatestCommitSummary(stemDict: StemDict, baseBranchName: string) { const nodes = stemDict .get(baseBranchName) ?.nodes?.map(({ commit }) => commit) - .filter(({ message }) => !message.includes("Merge branch") && !message.includes("Merge pull request")); + .filter(({ message }) => isNonMergeCommit(message)); return await getSummary(nodes ? nodes?.slice(-10) : []); } @@ -46,9 +52,7 @@ export async function getCurrentUserCommitSummary(stemDict: StemDict, baseBranch .get(baseBranchName) ?.nodes?.filter( ({ commit: { author, message } }) => - (author.name === data.login || author.name === data.name) && - !message.includes("Merge branch") && - !message.includes("Merge pull request") + (author.name === data.login || author.name === data.name) && isNonMergeCommit(message) ) ?.map(({ commit }) => commit); From 8bb29695ebaea3b927d70f358de0389e6e746249 Mon Sep 17 00:00:00 2001 From: Madang Garden Date: Wed, 18 Sep 2024 17:15:54 +0900 Subject: [PATCH 4/9] =?UTF-8?q?feat/#635=20=EC=82=AC=EC=9D=B4=EB=93=9C?= =?UTF-8?q?=EB=B0=94=20=EA=B8=B0=EB=B3=B8=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/package.json | 21 +++++++++++- packages/vscode/src/extension.ts | 5 +++ packages/vscode/src/sidebar.ts | 59 ++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 packages/vscode/src/sidebar.ts diff --git a/packages/vscode/package.json b/packages/vscode/package.json index 4f383b53..e162dd65 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -28,7 +28,8 @@ "visual analytics" ], "activationEvents": [ - "*" + "*", + "onView:mySidebar" ], "main": "./dist/extension.js", "contributes": { @@ -68,6 +69,24 @@ "description": "Insert your primary color." } } + }, + "viewsContainers": { + "activitybar": [ + { + "id": "mySidebarView", + "title": "My Sidebar", + "icon": "path/to/icon.svg" + } + ] + }, + "views": { + "mySidebarView": [ + { + "type": "webview", + "id": "mySidebar", + "name": "My Sidebar" + } + ] } }, "scripts": { diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index e1c6357f..5afa2914 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -5,6 +5,7 @@ import { COMMAND_LAUNCH, COMMAND_LOGIN_WITH_GITHUB, COMMAND_RESET_GITHUB_AUTH } import { Credentials } from "./credentials"; import { GithubTokenUndefinedError, WorkspacePathUndefinedError } from "./errors/ExtensionError"; import { deleteGithubToken, getGithubToken, setGithubToken } from "./setting-repository"; +import { SidebarProvider } from "./sidebar"; import { mapClusterNodesFrom } from "./utils/csm.mapper"; import { findGit, @@ -25,6 +26,10 @@ function normalizeFsPath(fsPath: string) { } export async function activate(context: vscode.ExtensionContext) { + const provider = new SidebarProvider(context.extensionUri); + + context.subscriptions.push(vscode.window.registerWebviewViewProvider("mySidebar", provider)); + const { subscriptions, extensionPath, secrets } = context; const credentials = new Credentials(); let currentPanel: vscode.WebviewPanel | undefined = undefined; diff --git a/packages/vscode/src/sidebar.ts b/packages/vscode/src/sidebar.ts new file mode 100644 index 00000000..d5c3d16f --- /dev/null +++ b/packages/vscode/src/sidebar.ts @@ -0,0 +1,59 @@ +import type * as vscode from "vscode"; + +export class SidebarProvider implements vscode.WebviewViewProvider { + constructor(private readonly _extensionUri: vscode.Uri) {} + + resolveWebviewView(webviewView: vscode.WebviewView) { + webviewView.webview.options = { + enableScripts: true, + }; + + webviewView.webview.html = this._getHtmlForWebview(webviewView.webview); + + webviewView.webview.onDidReceiveMessage(async (data) => { + const result = await this.callApi(data.apiNumber); + webviewView.webview.postMessage({ type: "apiResult", result }); + }); + } + + private async callApi(apiNumber: number): Promise { + // 여기에 실제 API 호출 로직을 구현합니다. + return `API ${apiNumber} 호출 결과`; + } + + private _getHtmlForWebview(webview: vscode.Webview) { + return ` + + + + + + API Caller + + + + + +
+ + + + + `; + } +} From 80aa5f3da54fe87992aae635d60f9edec82c5426 Mon Sep 17 00:00:00 2001 From: Madang Garden Date: Sun, 29 Sep 2024 22:23:44 +0900 Subject: [PATCH 5/9] =?UTF-8?q?engine=20=EC=8B=B1=EA=B8=80=ED=86=A4?= =?UTF-8?q?=ED=99=94=20=EB=B0=8F=20API=20=ED=98=B8=EC=B6=9C=20=EC=98=88?= =?UTF-8?q?=EC=8B=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/analysis-engine/src/index.ts | 55 +++++++++++++++++++-------- packages/vscode/src/extension.ts | 3 +- packages/vscode/src/sidebar.ts | 9 ++++- 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/packages/analysis-engine/src/index.ts b/packages/analysis-engine/src/index.ts index f6de204b..563e3bf7 100644 --- a/packages/analysis-engine/src/index.ts +++ b/packages/analysis-engine/src/index.ts @@ -8,6 +8,7 @@ import getCommitRaws from "./parser"; import { PluginOctokit } from "./pluginOctokit"; import { buildStemDict } from "./stem"; import { getSummary } from "./summary"; +import type { CommitNode } from "./types"; type AnalysisEngineArgs = { isDebugMode?: boolean; @@ -19,19 +20,24 @@ type AnalysisEngineArgs = { }; export class AnalysisEngine { + private static instance: AnalysisEngine | null = null; private gitLog!: string; - private isDebugMode?: boolean; - private octokit!: PluginOctokit; - private baseBranchName!: string; + private nodes?: CommitNode[]; + private isInitialized: boolean = false; + + private constructor() {} - constructor(args: AnalysisEngineArgs) { - this.insertArgs(args); + public static getInstance(): AnalysisEngine { + if (!AnalysisEngine.instance) { + AnalysisEngine.instance = new AnalysisEngine(); + } + return AnalysisEngine.instance; } - private insertArgs = (args: AnalysisEngineArgs) => { + public initialize(args: AnalysisEngineArgs): void { const { isDebugMode, gitLog, owner, repo, auth, baseBranchName } = args; this.gitLog = gitLog; this.baseBranchName = baseBranchName; @@ -46,9 +52,22 @@ export class AnalysisEngine { }, }); this.octokit = container.resolve(PluginOctokit); - }; + this.isInitialized = true; + } + + private checkInitialization() { + if (!this.isInitialized) { + throw new Error("AnalysisEngine is not initialized. Call initialize() first."); + } + } + + public async analyzeGit() { + this.checkInitialization(); + + if (!this.gitLog) { + throw new Error("AnalysisEngine is not initialized. Call initialize() first."); + } - public analyzeGit = async () => { let isPRSuccess = true; if (this.isDebugMode) console.log("baseBranchName: ", this.baseBranchName); @@ -75,20 +94,26 @@ export class AnalysisEngine { if (this.isDebugMode) console.log("stemDict: ", stemDict); const csmDict = buildCSMDict(commitDict, stemDict, this.baseBranchName, pullRequests); if (this.isDebugMode) console.log("csmDict: ", csmDict); - const nodes = stemDict.get(this.baseBranchName)?.nodes?.map(({commit}) => commit); - const geminiCommitSummary = await getSummary(nodes ? nodes?.slice(-10) : []); - if (this.isDebugMode) console.log("GeminiCommitSummary: ", geminiCommitSummary); + this.nodes = stemDict.get(this.baseBranchName)?.nodes; return { isPRSuccess, csmDict, }; - }; + } - public updateArgs = (args: AnalysisEngineArgs) => { + public updateArgs(args: AnalysisEngineArgs) { if (container.isRegistered("OctokitOptions")) container.clearInstances(); - this.insertArgs(args); - }; + this.initialize(args); + } + + public async geminiCommitSummary() { + this.checkInitialization(); + if (!this.nodes) { + throw new Error("No commits available. Run analyzeGit() first."); + } + return await getSummary(this.nodes.slice(-10).map(({ commit }) => commit)); + } } export default AnalysisEngine; diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 5afa2914..9a463e0f 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -87,7 +87,8 @@ export async function activate(context: vscode.ExtensionContext) { const { owner, repo: initialRepo } = getRepo(gitConfig); webLoader.setGlobalOwnerAndRepo(owner, initialRepo); const repo = initialRepo[0]; - const engine = new AnalysisEngine({ + const engine = AnalysisEngine.getInstance(); + engine.initialize({ isDebugMode: true, gitLog, owner, diff --git a/packages/vscode/src/sidebar.ts b/packages/vscode/src/sidebar.ts index d5c3d16f..ac58a34d 100644 --- a/packages/vscode/src/sidebar.ts +++ b/packages/vscode/src/sidebar.ts @@ -1,3 +1,4 @@ +import AnalysisEngine from "@githru-vscode-ext/analysis-engine"; import type * as vscode from "vscode"; export class SidebarProvider implements vscode.WebviewViewProvider { @@ -17,7 +18,13 @@ export class SidebarProvider implements vscode.WebviewViewProvider { } private async callApi(apiNumber: number): Promise { - // 여기에 실제 API 호출 로직을 구현합니다. + const engine = AnalysisEngine.getInstance(); + try { + const summary = await engine.geminiCommitSummary(); + console.log("Commit summary:", summary); + } catch (error) { + console.error("Error getting commit summary:", error); + } return `API ${apiNumber} 호출 결과`; } From d2a1bdc58caab2b38ac5e022bc081328f5c95eec Mon Sep 17 00:00:00 2001 From: Madang Garden Date: Thu, 3 Oct 2024 23:03:03 +0900 Subject: [PATCH 6/9] =?UTF-8?q?fix:=20=EB=9D=BC=EC=9D=B4=EB=B8=8C=EB=9F=AC?= =?UTF-8?q?=EB=A6=AC=EB=A1=9C=EC=8D=A8=20=EC=98=AC=EB=B0=94=EB=A5=B4?= =?UTF-8?q?=EA=B2=8C=20import=EB=90=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/analysis-engine/src/engine.ts | 119 ++++++++++++++++++++++++ packages/analysis-engine/src/index.ts | 122 +------------------------ 2 files changed, 123 insertions(+), 118 deletions(-) create mode 100644 packages/analysis-engine/src/engine.ts diff --git a/packages/analysis-engine/src/engine.ts b/packages/analysis-engine/src/engine.ts new file mode 100644 index 00000000..110b6416 --- /dev/null +++ b/packages/analysis-engine/src/engine.ts @@ -0,0 +1,119 @@ +import "reflect-metadata"; + +import { container } from "tsyringe"; + +import { buildCommitDict } from "./commit.util"; +import { buildCSMDict } from "./csm"; +import getCommitRaws from "./parser"; +import { PluginOctokit } from "./pluginOctokit"; +import { buildStemDict } from "./stem"; +import { getSummary } from "./summary"; +import type { CommitNode } from "./types"; + +export type AnalysisEngineArgs = { + isDebugMode?: boolean; + gitLog: string; + owner: string; + repo: string; + baseBranchName: string; + auth?: string; +}; + +export class AnalysisEngine { + private static instance: AnalysisEngine | null = null; + private gitLog!: string; + private isDebugMode?: boolean; + private octokit!: PluginOctokit; + private baseBranchName!: string; + private nodes?: CommitNode[]; + private isInitialized: boolean = false; + + private constructor() {} + + public static getInstance(): AnalysisEngine { + if (!AnalysisEngine.instance) { + AnalysisEngine.instance = new AnalysisEngine(); + } + return AnalysisEngine.instance; + } + + public initialize(args: AnalysisEngineArgs): void { + const { isDebugMode, gitLog, owner, repo, auth, baseBranchName } = args; + this.gitLog = gitLog; + this.baseBranchName = baseBranchName; + this.isDebugMode = isDebugMode; + container.register("OctokitOptions", { + useValue: { + owner, + repo, + options: { + auth, + }, + }, + }); + this.octokit = container.resolve(PluginOctokit); + this.isInitialized = true; + } + + private checkInitialization() { + if (!this.isInitialized) { + throw new Error("AnalysisEngine is not initialized. Call initialize() first."); + } + } + + public async analyzeGit() { + this.checkInitialization(); + + if (!this.gitLog) { + throw new Error("AnalysisEngine is not initialized. Call initialize() first."); + } + + 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); + 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); + this.nodes = stemDict.get(this.baseBranchName)?.nodes; + + return { + isPRSuccess, + csmDict, + }; + } + + public updateArgs(args: AnalysisEngineArgs) { + if (container.isRegistered("OctokitOptions")) container.clearInstances(); + this.initialize(args); + } + + public async geminiCommitSummary() { + this.checkInitialization(); + if (!this.nodes) { + throw new Error("No commits available. Run analyzeGit() first."); + } + return await getSummary(this.nodes.slice(-10).map(({ commit }) => commit)); + } +} + +export default AnalysisEngine; diff --git a/packages/analysis-engine/src/index.ts b/packages/analysis-engine/src/index.ts index 563e3bf7..87008f4c 100644 --- a/packages/analysis-engine/src/index.ts +++ b/packages/analysis-engine/src/index.ts @@ -1,119 +1,5 @@ -import "reflect-metadata"; - -import { container } from "tsyringe"; - -import { buildCommitDict } from "./commit.util"; -import { buildCSMDict } from "./csm"; -import getCommitRaws from "./parser"; -import { PluginOctokit } from "./pluginOctokit"; -import { buildStemDict } from "./stem"; -import { getSummary } from "./summary"; -import type { CommitNode } from "./types"; - -type AnalysisEngineArgs = { - isDebugMode?: boolean; - gitLog: string; - owner: string; - repo: string; - baseBranchName: string; - auth?: string; -}; - -export class AnalysisEngine { - private static instance: AnalysisEngine | null = null; - private gitLog!: string; - private isDebugMode?: boolean; - private octokit!: PluginOctokit; - private baseBranchName!: string; - private nodes?: CommitNode[]; - private isInitialized: boolean = false; - - private constructor() {} - - public static getInstance(): AnalysisEngine { - if (!AnalysisEngine.instance) { - AnalysisEngine.instance = new AnalysisEngine(); - } - return AnalysisEngine.instance; - } - - public initialize(args: AnalysisEngineArgs): void { - const { isDebugMode, gitLog, owner, repo, auth, baseBranchName } = args; - this.gitLog = gitLog; - this.baseBranchName = baseBranchName; - this.isDebugMode = isDebugMode; - container.register("OctokitOptions", { - useValue: { - owner, - repo, - options: { - auth, - }, - }, - }); - this.octokit = container.resolve(PluginOctokit); - this.isInitialized = true; - } - - private checkInitialization() { - if (!this.isInitialized) { - throw new Error("AnalysisEngine is not initialized. Call initialize() first."); - } - } - - public async analyzeGit() { - this.checkInitialization(); +export type { AnalysisEngineArgs } from "./engine"; +export { AnalysisEngine } from "./engine"; - if (!this.gitLog) { - throw new Error("AnalysisEngine is not initialized. Call initialize() first."); - } - - 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); - 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); - this.nodes = stemDict.get(this.baseBranchName)?.nodes; - - return { - isPRSuccess, - csmDict, - }; - } - - public updateArgs(args: AnalysisEngineArgs) { - if (container.isRegistered("OctokitOptions")) container.clearInstances(); - this.initialize(args); - } - - public async geminiCommitSummary() { - this.checkInitialization(); - if (!this.nodes) { - throw new Error("No commits available. Run analyzeGit() first."); - } - return await getSummary(this.nodes.slice(-10).map(({ commit }) => commit)); - } -} - -export default AnalysisEngine; +// If you want to ensure 'reflect-metadata' is imported at the entry point +import "reflect-metadata"; From f499f50132083c6c8ac0d912bcc9ef4377b512e0 Mon Sep 17 00:00:00 2001 From: Madang Garden Date: Sat, 5 Oct 2024 18:01:51 +0900 Subject: [PATCH 7/9] =?UTF-8?q?fix:=20=ED=83=80=EC=9E=85=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/analysis-engine/src/index.ts | 3 --- packages/vscode/src/sidebar.ts | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/analysis-engine/src/index.ts b/packages/analysis-engine/src/index.ts index 87008f4c..0755f0f7 100644 --- a/packages/analysis-engine/src/index.ts +++ b/packages/analysis-engine/src/index.ts @@ -1,5 +1,2 @@ export type { AnalysisEngineArgs } from "./engine"; export { AnalysisEngine } from "./engine"; - -// If you want to ensure 'reflect-metadata' is imported at the entry point -import "reflect-metadata"; diff --git a/packages/vscode/src/sidebar.ts b/packages/vscode/src/sidebar.ts index ac58a34d..7e633e63 100644 --- a/packages/vscode/src/sidebar.ts +++ b/packages/vscode/src/sidebar.ts @@ -1,4 +1,4 @@ -import AnalysisEngine from "@githru-vscode-ext/analysis-engine"; +import { AnalysisEngine } from "@githru-vscode-ext/analysis-engine"; import type * as vscode from "vscode"; export class SidebarProvider implements vscode.WebviewViewProvider { From 2ed9590219e80da0d5927aa9f73e407fa4d5a99f Mon Sep 17 00:00:00 2001 From: Madang Garden Date: Sat, 5 Oct 2024 18:02:06 +0900 Subject: [PATCH 8/9] =?UTF-8?q?feat:=20=EC=82=AC=EC=9D=B4=EB=93=9C?= =?UTF-8?q?=EB=B0=94=20=EC=95=84=EC=9D=B4=EC=BD=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/package.json | 14 +++++++------- packages/vscode/src/extension.ts | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/vscode/package.json b/packages/vscode/package.json index e162dd65..9b21f085 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -29,7 +29,7 @@ ], "activationEvents": [ "*", - "onView:mySidebar" + "onView:githruSidebar" ], "main": "./dist/extension.js", "contributes": { @@ -73,18 +73,18 @@ "viewsContainers": { "activitybar": [ { - "id": "mySidebarView", - "title": "My Sidebar", - "icon": "path/to/icon.svg" + "id": "githruSidebarView", + "title": "Githru Sidebar", + "icon": "images/logo.png" } ] }, "views": { - "mySidebarView": [ + "githruSidebarView": [ { "type": "webview", - "id": "mySidebar", - "name": "My Sidebar" + "id": "githruSidebar", + "name": "Githru Sidebar" } ] } diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 9a463e0f..866e94e6 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -28,7 +28,7 @@ function normalizeFsPath(fsPath: string) { export async function activate(context: vscode.ExtensionContext) { const provider = new SidebarProvider(context.extensionUri); - context.subscriptions.push(vscode.window.registerWebviewViewProvider("mySidebar", provider)); + context.subscriptions.push(vscode.window.registerWebviewViewProvider("githruSidebar", provider)); const { subscriptions, extensionPath, secrets } = context; const credentials = new Credentials(); From 46578dd1eeaeabfdd52801a1d0f6d440a93ec629 Mon Sep 17 00:00:00 2001 From: Madang Garden Date: Sat, 5 Oct 2024 19:13:36 +0900 Subject: [PATCH 9/9] =?UTF-8?q?typo:=20=EB=B2=84=ED=8A=BC=20=EB=AA=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/sidebar.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/vscode/src/sidebar.ts b/packages/vscode/src/sidebar.ts index 7e633e63..4da291f0 100644 --- a/packages/vscode/src/sidebar.ts +++ b/packages/vscode/src/sidebar.ts @@ -38,9 +38,9 @@ export class SidebarProvider implements vscode.WebviewViewProvider { API Caller - - - + + +