@@ -28,7 +28,17 @@ abstract class BaseSummarizer(protected val config: AIProviderConfig) : AISummar
2828 if (commit.changes.isNotEmpty()) {
2929 append(" Changed files:\n " )
3030 commit.changes.forEach { change ->
31- append(" - ${change.path} (${change.changeType.name} , +${change.additions} , -${change.deletions} )\n " )
31+ val processedDiff = DiffProcessor .processDiff(change.diff)
32+ val changeSummary = DiffProcessor .generateChangeSummary(change.diff)
33+
34+ append(" - ${change.path} (${change.changeType.name} , $changeSummary )\n " )
35+
36+ if (processedDiff.isNotEmpty()) {
37+ append(" Key changes:\n " )
38+ processedDiff.lines().forEach { line ->
39+ append(" $line \n " )
40+ }
41+ }
3242 }
3343 }
3444 }
@@ -58,22 +68,132 @@ abstract class BaseSummarizer(protected val config: AIProviderConfig) : AISummar
5868 */
5969 protected fun buildPRPrompt (commits : List <Commit >, title : String? ): String {
6070 val commitsText = formatCommitsForPrompt(commits)
71+ val changesSummary = generateChangesSummaryForPR(commits)
6172 val language = locale.languageName
6273
6374 return """
64- Please generate a PR description based on the following git commits.
75+ Please generate a comprehensive PR description based on the following git commits and code changes .
6576 ${title?.let { " PR Title: $it " } ? : " " }
6677
6778 Focus on:
68- 1. Changes made
69- 2. Impact of changes
70- 3. Testing done
71- 4. Additional notes
79+ 1. Overview of changes made (based on actual code changes below)
80+ 2. Technical implementation details
81+ 3. Impact and benefits of these changes
82+ 4. Breaking changes (if any)
83+ 5. Testing considerations
7284
7385 IMPORTANT: Please provide the response in $language language.
86+ Use the actual code changes to provide specific details about what was modified.
7487
75- Commits:
88+ ## Changes Summary
89+ $changesSummary
90+
91+ ## Detailed Commits
92+ $commitsText
93+ """ .trimIndent()
94+ }
95+
96+ /* *
97+ * PR용 변경사항 요약 생성
98+ */
99+ private fun generateChangesSummaryForPR (commits : List <Commit >): String {
100+ val allChanges = commits.flatMap { it.changes }
101+ val filesByType = allChanges.groupBy { getFileType(it.path) }
102+
103+ val summary = StringBuilder ()
104+
105+ // 파일 타입별 변경 통계
106+ summary.append(" ### Files Changed by Type\n " )
107+ filesByType.forEach { (fileType, changes) ->
108+ val fileCount = changes.size
109+ val meaningfulChanges = changes.count { DiffProcessor .processDiff(it.diff).isNotEmpty() }
110+ summary.append(" - **$fileType **: $fileCount files ($meaningfulChanges with meaningful changes)\n " )
111+ }
112+
113+ // 주요 변경사항 하이라이트
114+ summary.append(" \n ### Key Changes\n " )
115+ allChanges.forEach { change ->
116+ val processedDiff = DiffProcessor .processDiff(change.diff)
117+ if (processedDiff.isNotEmpty()) {
118+ val changeSummary = DiffProcessor .generateChangeSummary(change.diff)
119+ summary.append(" **${change.path} ** (${change.changeType.name} ): $changeSummary \n " )
120+
121+ // 핵심 변경사항 몇 줄만 보여주기
122+ val keyLines = processedDiff.lines().take(3 )
123+ if (keyLines.isNotEmpty()) {
124+ summary.append(" ```\n " )
125+ keyLines.forEach { summary.append(" $it \n " ) }
126+ if (processedDiff.lines().size > 3 ) {
127+ summary.append(" ... (${processedDiff.lines().size - 3 } more lines)\n " )
128+ }
129+ summary.append(" ```\n\n " )
130+ }
131+ }
132+ }
133+
134+ return summary.toString()
135+ }
136+
137+ /* *
138+ * 파일 확장자를 기반으로 파일 타입 결정
139+ */
140+ private fun getFileType (filePath : String ): String {
141+ return when (filePath.substringAfterLast(' .' , " " )) {
142+ " kt" -> " Kotlin"
143+ " java" -> " Java"
144+ " js" , " ts" -> " JavaScript/TypeScript"
145+ " py" -> " Python"
146+ " go" -> " Go"
147+ " rs" -> " Rust"
148+ " cpp" , " c" , " h" -> " C/C++"
149+ " md" -> " Documentation"
150+ " yml" , " yaml" -> " Configuration"
151+ " json" -> " JSON"
152+ " xml" -> " XML"
153+ " gradle" , " kts" -> " Build Script"
154+ " properties" -> " Properties"
155+ else -> " Other"
156+ }
157+ }
158+
159+ /* *
160+ * 템플릿 기반 PR 초안 생성 (기본 구현)
161+ */
162+ override suspend fun generatePRDraftWithTemplate (commits : List <Commit >, template : String ): String {
163+ return callAIModel(buildPRPromptWithTemplate(commits, template))
164+ }
165+
166+ /* *
167+ * 템플릿 기반 PR 초안용 프롬프트 생성
168+ */
169+ protected fun buildPRPromptWithTemplate (commits : List <Commit >, template : String ): String {
170+ val commitsText = formatCommitsForPrompt(commits)
171+ val changesSummary = generateChangesSummaryForPR(commits)
172+ val language = locale.languageName
173+
174+ return """
175+ Please generate a comprehensive PR description based on the following git commits and code changes.
176+ You MUST follow the provided template structure exactly and fill in detailed, meaningful content.
177+
178+ TEMPLATE TO FOLLOW:
179+ $template
180+
181+ INSTRUCTIONS:
182+ 1. Use the exact template structure and sections
183+ 2. Fill each section with detailed, technical information based on the actual code changes
184+ 3. Be specific about what was changed, why it was changed, and the impact
185+ 4. Include technical implementation details where relevant
186+ 5. For checklists, mark items as checked [x] or unchecked [ ] based on the changes
187+ 6. Write in $language language
188+ 7. DO NOT include template variable syntax like {{}} in your response
189+
190+ ## Changes Summary
191+ $changesSummary
192+
193+ ## Detailed Commits
76194 $commitsText
195+
196+ Generate the PR description following the template structure above.
77197 """ .trimIndent()
78198 }
79199
0 commit comments