From b6473342535f64310788987f2667ca7e90df4cd1 Mon Sep 17 00:00:00 2001 From: choisohyun Date: Mon, 9 Sep 2024 22:59:29 +0900 Subject: [PATCH 1/3] =?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/3] =?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/3] =?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);