Skip to content

Commit

Permalink
feat: 현재 user 기준으로 AI 요약 추가 및 함수로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
choisohyun committed Sep 9, 2024
1 parent 3eab981 commit b647334
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/analysis-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 15 additions & 1 deletion packages/analysis-engine/src/summary.ts
Original file line number Diff line number Diff line change
@@ -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=";
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b647334

Please sign in to comment.