-
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
[engine/AI] 현재 author가 작성한 커밋이 있다면 최신 10개 커밋 요약하기 #718
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
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="; | ||
const API_KEY = process.env.GEMENI_API_KEY || ""; | ||
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. (궁금) || "" 을 붙인건 API_KEY가 없어도 fetch를 가능하게 하기 위함인건가요? 혹시 empty string일 때 동작을 하지 않는 케이스라면 따로 처리를 하는게 좋을 수도 있어서 여쭤봤습니다~ 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. 요거 타입 추가해서 null 케이스 처리코드 없도록 수정하겠습니다! |
||
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[]) { | ||
const commitMessages = csmNodes.map((csmNode) => csmNode.message.split('\n')[0]).join(', '); | ||
async function getSummary(csmNodes: CommitRaw[]) { | ||
const commitMessages = csmNodes.map((csmNode) => csmNode.message.split("\n")[0]).join(", "); | ||
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. SEPERATOR 들은 따로 변수로 빼도 좋을 것 같습니다! 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. 넵 수정하겠습니다! |
||
|
||
console.log("commitMessages: ", commitMessages); | ||
try { | ||
const response = await fetch(apiUrl + apiKey, { | ||
const response = await fetch(API_URL + API_KEY, { | ||
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. AI에 직접적으로 API를 쏘는 부분은 별도로 함수 분리하면 좋을 것 같습니다! |
||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
contents: [{parts: [{text: `${prompt} \n${commitMessages}`}]}], | ||
contents: [{ parts: [{ text: `${prompt} \n${commitMessages}` }] }], | ||
}), | ||
}); | ||
|
||
|
@@ -29,6 +33,32 @@ 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 }) => isNonMergeCommit(message)); | ||
|
||
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) && isNonMergeCommit(message) | ||
) | ||
?.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. | ||
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. 여기도 커맨드마다 프롬프트가 달라지므로 향후 프롬프트들을 어떻게 관리해야할지 고민해봐야할 것 같습니다 ㅠ |
||
|
||
Procedure: | ||
|
@@ -53,4 +83,4 @@ Output format: | |
- {prefix (if any)}:{commit summary3} | ||
‘’ | ||
|
||
Commits:` | ||
Commits:`; |
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.
변수명이 직관적이라 좋은 것 같아요!!👍👍👍👍👍👍‼️
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.
한번 분석을 하고 끝나면 engine의 역할과는 달리, 향후 밖으로 쏘는 API를 가정하고 만들고 있기 때문에 AnalysisEngine클래스안에 어떻게 들어가야할지는 고민이 많이 되네요🤔 목요일에 자세하게 얘기해봅시다!!