Skip to content

feat(config): Add support for coding guidelines from config in modified-files #31

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

Open
wants to merge 1 commit into
base: vidy/revu-config-file
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 8 additions & 5 deletions __tests__/populate-template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ describe('populateTemplate', () => {
})

// Verify the template was populated with all required sections
expect(result).toContain('Project Path:')
expect(result).toContain('Git diff:')
expect(result).toContain('Modified Files Content:')
expect(result).toContain('Repo path:')
expect(result).toContain('## Modified Files')
expect(result).toContain('## Git Diff')
expect(result).toContain('## Coding Guidelines')

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

it('should use custom template path when provided', async () => {
Expand Down
12 changes: 9 additions & 3 deletions src/prompt-strategies/modified-files-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs/promises'
import Handlebars from 'handlebars'
import * as path from 'path'
import { getCodingGuidelines } from '../config-handler.ts'
import { extractDiffFromRepo } from '../extract-diff.ts'
import { cleanUpRepository, prepareRepository } from '../repo-utils.ts'
import type { PromptStrategy } from './prompt-strategy.ts'
Expand Down Expand Up @@ -56,12 +57,17 @@ export const modifiedFilesPromptStrategy: PromptStrategy = async (
const template = Handlebars.compile(templateContent)

const repoName = repositoryUrl.split('/').pop()?.replace('.git', '') || ''
const absolutePath = path.join(process.cwd(), repoName)
const localRepoPath = path.join(process.cwd(), repoName)

// Get coding guidelines from configuration
const codingGuidelines = await getCodingGuidelines(repoPath)

// Populate the template with the data
const result = template({
absolute_code_path: absolutePath, // Use the actual repository path where files are located
local_repo_path: localRepoPath, // Use the actual repository path where files are located
git_diff_branch: diff,
modified_files: modifiedFilesContent
modified_files: modifiedFilesContent,
coding_guidelines: codingGuidelines
})

return result
Expand Down
75 changes: 26 additions & 49 deletions templates/modified-files-prompt.hbs
Original file line number Diff line number Diff line change
@@ -1,66 +1,43 @@
Project Path: {{ absolute_code_path }}
You are an expert code review assistant. Your task is to review a pull request while following the guidelines below.

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

{{#if git_diff_branch}}
Git diff:
```
{{git_diff_branch}}
```
{{/if}}
Repo path: {{local_repo_path}}

## Modified Files

Modified Files Content:
{{#each modified_files}}
File: {{@key}}
### {{@key}}
```
{{this}}
{{{this}}}
```

{{/each}}

Please analyze the changes and provide feedback in the following format:

```markdown
# Pull Request Analysis
## Git Diff

## Overview
- Brief summary of what the PR is trying to achieve
- Assessment of whether the changes effectively solve the intended problem

## Code Quality Review
### Strengths
- Highlight good practices and well-implemented aspects
- Note any particularly elegant or efficient solutions
```diff
{{{git_diff_branch}}}
```

### Areas for Improvement
- Identify potential code smells or anti-patterns
- Suggest specific refactoring opportunities
- Point out any missing error handling or edge cases
- Note any performance considerations
## Instructions

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

## Best Practices Evaluation
- Check adherence to project conventions and standards
- Review test coverage and quality
- Assess documentation completeness and clarity
- Evaluate maintainability and readability
## Coding Guidelines

## Recommendations
- Provide specific, actionable suggestions for improvement
- Prioritize recommendations by importance
- Include code examples where helpful
{{coding_guidelines}}

## Additional Notes
- Any other relevant observations or concerns
- Impact on other parts of the codebase
- Potential future considerations
```
## Important Notes

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.
- Focus on significant issues rather than minor style or convention concerns.
- Provide clear, educational explanations for each comment, not just identifying the problem.
- Avoid commenting on code that has not been modified in the pull request.