-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AI 요약 기능 도입을 위한 사이드바뷰 도입 및 엔진 호출방식 변경 #754
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8bb2969
feat/#635 사이드바 기본 기능 구현
mdgarden 80aa5f3
engine 싱글톤화 및 API 호출 예시 작성
mdgarden 2f19927
Merge branch 'main' of https://github.com/githru/githru-vscode-ext in…
mdgarden d2a1bdc
fix: 라이브러리로써 올바르게 import될 수 있도록 수정
mdgarden f499f50
fix: 타입 에러 수정
mdgarden 2ed9590
feat: 사이드바 아이콘 추가
mdgarden 46578dd
typo: 버튼 명 수정
mdgarden be6bd99
Merge branch 'epic/ai-summary' of https://github.com/githru/githru-vs…
mdgarden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,2 @@ | ||
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 { getCurrentUserCommitSummary, getLatestCommitSummary } from "./summary"; | ||
|
||
type AnalysisEngineArgs = { | ||
isDebugMode?: boolean; | ||
gitLog: string; | ||
owner: string; | ||
repo: string; | ||
baseBranchName: string; | ||
auth?: string; | ||
}; | ||
|
||
export class AnalysisEngine { | ||
private gitLog!: string; | ||
|
||
private isDebugMode?: boolean; | ||
|
||
private octokit!: PluginOctokit; | ||
|
||
private baseBranchName!: string; | ||
|
||
constructor(args: AnalysisEngineArgs) { | ||
this.insertArgs(args); | ||
} | ||
|
||
private insertArgs = (args: AnalysisEngineArgs) => { | ||
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); | ||
}; | ||
|
||
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); | ||
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); | ||
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, | ||
csmDict, | ||
}; | ||
}; | ||
|
||
public updateArgs = (args: AnalysisEngineArgs) => { | ||
if (container.isRegistered("OctokitOptions")) container.clearInstances(); | ||
this.insertArgs(args); | ||
}; | ||
} | ||
|
||
export default AnalysisEngine; | ||
export type { AnalysisEngineArgs } from "./engine"; | ||
export { AnalysisEngine } from "./engine"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { AnalysisEngine } from "@githru-vscode-ext/analysis-engine"; | ||
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<string> { | ||
const engine = AnalysisEngine.getInstance(); | ||
try { | ||
const summary = await engine.geminiCommitSummary(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. epic에 머지되면 여기에 각각 함수 부르게 하면 되겠군요! 👍 |
||
console.log("Commit summary:", summary); | ||
} catch (error) { | ||
console.error("Error getting commit summary:", error); | ||
} | ||
return `API ${apiNumber} 호출 결과`; | ||
} | ||
|
||
private _getHtmlForWebview(webview: vscode.Webview) { | ||
return ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>API Caller</title> | ||
</head> | ||
<body> | ||
<button onclick="callApi(1)">Call AI Analyze 1</button> | ||
<button onclick="callApi(2)">Call AI Analyze 2</button> | ||
<button onclick="callApi(3)">Call AI Analyze 3</button> | ||
<div id="result"></div> | ||
|
||
<script> | ||
const vscode = acquireVsCodeApi(); | ||
|
||
function callApi(apiNumber) { | ||
vscode.postMessage({ type: 'apiCall', apiNumber }); | ||
} | ||
|
||
window.addEventListener('message', event => { | ||
const message = event.data; | ||
switch (message.type) { | ||
case 'apiResult': | ||
document.getElementById('result').innerText = message.result; | ||
break; | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> | ||
`; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(질문) 요 로고 이미지는 vscode 패키지 안에 올려두지 않아도 동작이 되는 장치가 있는 걸까요?? diff에 이미지는 없는 것 같아서 여쭤봅니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기존에 vscode 패키지안에 있던 로고입니다!