Skip to content

Commit ddd4388

Browse files
committed
feat(config): Add support for coding guidelines from config in modified-files
vidy-br: coding-guidelines-in-modified-files
1 parent 061060c commit ddd4388

File tree

3 files changed

+43
-57
lines changed

3 files changed

+43
-57
lines changed

__tests__/populate-template.test.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,16 @@ describe('populateTemplate', () => {
7272
})
7373

7474
// Verify the template was populated with all required sections
75-
expect(result).toContain('Project Path:')
76-
expect(result).toContain('Git diff:')
77-
expect(result).toContain('Modified Files Content:')
75+
expect(result).toContain('Repo path:')
76+
expect(result).toContain('## Modified Files')
77+
expect(result).toContain('## Git Diff')
78+
expect(result).toContain('## Coding Guidelines')
7879

7980
// Verify the content structure
80-
expect(result).toMatch(/Project Path: .+/)
81-
expect(result).toMatch(/Git diff:\n```\n.+\n```/s)
81+
expect(result).toMatch(/Repo path: .+/)
82+
expect(result).toMatch(/## Modified Files\n\n###.+\n```\n.+\n```/s)
83+
expect(result).toMatch(/## Git Diff\n\n```diff\n.+\n```/s)
84+
expect(result).toMatch(/## Coding Guidelines\n\n(\d+\..+\n)+/s)
8285
}, 60000) // Increase timeout since we're doing git operations
8386

8487
it('should use custom template path when provided', async () => {

src/prompt-strategies/modified-files-strategy.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from 'fs/promises'
22
import Handlebars from 'handlebars'
33
import * as path from 'path'
4+
import { getCodingGuidelines } from '../config-handler.ts'
45
import { extractDiffFromRepo } from '../extract-diff.ts'
56
import { cleanUpRepository, prepareRepository } from '../repo-utils.ts'
67
import type { PromptStrategy } from './prompt-strategy.ts'
@@ -56,12 +57,17 @@ export const modifiedFilesPromptStrategy: PromptStrategy = async (
5657
const template = Handlebars.compile(templateContent)
5758

5859
const repoName = repositoryUrl.split('/').pop()?.replace('.git', '') || ''
59-
const absolutePath = path.join(process.cwd(), repoName)
60+
const localRepoPath = path.join(process.cwd(), repoName)
61+
62+
// Get coding guidelines from configuration
63+
const codingGuidelines = await getCodingGuidelines(repoPath)
64+
6065
// Populate the template with the data
6166
const result = template({
62-
absolute_code_path: absolutePath, // Use the actual repository path where files are located
67+
local_repo_path: localRepoPath, // Use the actual repository path where files are located
6368
git_diff_branch: diff,
64-
modified_files: modifiedFilesContent
69+
modified_files: modifiedFilesContent,
70+
coding_guidelines: codingGuidelines
6571
})
6672

6773
return result

templates/modified-files-prompt.hbs

+26-49
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,43 @@
1-
Project Path: {{ absolute_code_path }}
1+
You are an expert code review assistant. Your task is to review a pull request while following the guidelines below.
22

3-
I want you to analyze this pull request and provide constructive feedback focusing on code quality, security, and best practices.
4-
I will provide you with the git diff, modified files content, and pull request template.
3+
## Context
54

6-
{{#if git_diff_branch}}
7-
Git diff:
8-
```
9-
{{git_diff_branch}}
10-
```
11-
{{/if}}
5+
Repo path: {{local_repo_path}}
126

7+
## Modified Files
138

14-
Modified Files Content:
159
{{#each modified_files}}
16-
File: {{@key}}
10+
### {{@key}}
1711
```
18-
{{this}}
12+
{{{this}}}
1913
```
2014

2115
{{/each}}
2216

23-
Please analyze the changes and provide feedback in the following format:
24-
25-
```markdown
26-
# Pull Request Analysis
17+
## Git Diff
2718

28-
## Overview
29-
- Brief summary of what the PR is trying to achieve
30-
- Assessment of whether the changes effectively solve the intended problem
31-
32-
## Code Quality Review
33-
### Strengths
34-
- Highlight good practices and well-implemented aspects
35-
- Note any particularly elegant or efficient solutions
19+
```diff
20+
{{{git_diff_branch}}}
21+
```
3622

37-
### Areas for Improvement
38-
- Identify potential code smells or anti-patterns
39-
- Suggest specific refactoring opportunities
40-
- Point out any missing error handling or edge cases
41-
- Note any performance considerations
23+
## Instructions
4224

43-
## Security Assessment
44-
- Identify any security implications or vulnerabilities
45-
- Review authentication/authorization concerns if applicable
46-
- Check for proper input validation and data sanitization
47-
- Assess handling of sensitive data
25+
1. Analyze the modified code and git differences to understand the changes made.
26+
2. Provide thorough critique by identifying:
27+
- Code quality issues (readability, maintainability)
28+
- Potential bugs
29+
- Performance issues
30+
- Security concerns
31+
- Design problems
32+
- Opportunities for improvement
33+
3. We use coding guidelines and best practices that will be listed below. Please ensure your comments align with these guidelines.
4834

49-
## Best Practices Evaluation
50-
- Check adherence to project conventions and standards
51-
- Review test coverage and quality
52-
- Assess documentation completeness and clarity
53-
- Evaluate maintainability and readability
35+
## Coding Guidelines
5436

55-
## Recommendations
56-
- Provide specific, actionable suggestions for improvement
57-
- Prioritize recommendations by importance
58-
- Include code examples where helpful
37+
{{coding_guidelines}}
5938

60-
## Additional Notes
61-
- Any other relevant observations or concerns
62-
- Impact on other parts of the codebase
63-
- Potential future considerations
64-
```
39+
## Important Notes
6540

66-
Please analyze the git diff thoroughly to understand the changes. Focus on providing constructive feedback that will help improve code quality, security, and maintainability. Be specific in your recommendations and include examples where appropriate. Consider both immediate improvements and longer-term implications of the changes.
41+
- Focus on significant issues rather than minor style or convention concerns.
42+
- Provide clear, educational explanations for each comment, not just identifying the problem.
43+
- Avoid commenting on code that has not been modified in the pull request.

0 commit comments

Comments
 (0)