Skip to content
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

[engine/AI] 현재 author가 작성한 커밋이 있다면 최신 10개 커밋 요약하기 #718

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Comment on lines +78 to +81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수명이 직관적이라 좋은 것 같아요!!👍👍👍👍👍👍‼️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한번 분석을 하고 끝나면 engine의 역할과는 달리, 향후 밖으로 쏘는 API를 가정하고 만들고 있기 때문에 AnalysisEngine클래스안에 어떻게 들어가야할지는 고민이 많이 되네요🤔 목요일에 자세하게 얘기해봅시다!!

if (this.isDebugMode) console.log("currentUserCommitSummary: ", currentUserCommitSummary);

return {
isPRSuccess,
Expand Down
36 changes: 31 additions & 5 deletions packages/analysis-engine/src/summary.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import type { CommitRaw } from "./types";
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(", ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SEPERATOR 들은 따로 변수로 빼도 좋을 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 수정하겠습니다!


console.log("commitMessages: ", commitMessages);
try {
const response = await fetch(apiUrl + apiKey, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
contents: [{parts: [{text: `${prompt} \n${commitMessages}`}]}],
contents: [{ parts: [{ text: `${prompt} \n${commitMessages}` }] }],
}),
});

Expand All @@ -29,6 +31,30 @@ export async function getSummary(csmNodes: CommitRaw[]) {
}
}

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"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(궁금) 혹시 Merge branch와 Merge pull request를 상수를 만들어 관리하는 건 별로일까용?? 아래쪽에도 똑같이 쓰이는 것 같아서 여쭤보았습니다!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니다! 상수/함수로 분리시켜보았습니다! 91b5a22


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: { 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) : []);
}

const prompt = `Proceed with the task of summarising the contents of the commit message provided.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 커맨드마다 프롬프트가 달라지므로 향후 프롬프트들을 어떻게 관리해야할지 고민해봐야할 것 같습니다 ㅠ


Procedure:
Expand All @@ -53,4 +79,4 @@ Output format:
- {prefix (if any)}:{commit summary3}
‘’

Commits:`
Commits:`;