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: