Skip to content

Add a PR review github action with instructions to check against original issue requirements and for code dupe and clean code. #350

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

Closed
bhouston opened this issue Mar 22, 2025 · 7 comments · Fixed by #359

Comments

@bhouston
Copy link
Member

bhouston commented Mar 22, 2025

The review process should be driven by a markdown file of the things to look for in the code. Look at code rabbit for ideas.

@bhouston
Copy link
Member Author

/mycoder what workflows should I try to optimize here? What are my options? Could you review how code rabbit works. Should I ask for a code review from mycoder as a comment? Should I assign the PR to someone for a code review? And then if someone updates the PR with new commits, how should the follow PR review be done/triggered? Can you research and report back on existing workflows that other automated tools use for PR review that works well?

@bhouston
Copy link
Member Author

Hi @bhouston, I've researched PR review workflows and Code Rabbit as requested. Here's a comprehensive analysis of options for implementing a PR review GitHub action:

PR Review Workflow Options

1. Automated Review on PR Creation/Update

  • How it works: Automatically triggered when a PR is created or new commits are pushed
  • Benefits: Consistent reviews for all PRs, immediate feedback
  • Implementation: GitHub Action with on: [pull_request] trigger

2. Comment-based Review Trigger

  • How it works: Developers request review by commenting /review on a PR
  • Benefits: On-demand reviews, can specify focus areas
  • Implementation: GitHub Action with on: [issue_comment] trigger and comment filtering

3. Scheduled Review for Updated PRs

  • How it works: Runs periodically to check for PRs that need review
  • Benefits: Batches reviews, reduces API calls
  • Implementation: GitHub Action with on: [schedule] trigger

Code Rabbit and Other AI Review Tools

Code Rabbit AI

  • Features: Context-aware feedback, line-by-line suggestions, customizable via .coderabbit.yaml
  • Integration: Available as GitHub App (easiest) or API-based integration
  • Strengths: Clean interface, supports all languages, configurable review depth
  • Workflow: Automatically comments on PRs, can be triggered manually via comments

Other Tools Comparison

  1. Smart PR Reviewer: Supports multiple AI models, configurable path filters
  2. AI PR Review Bot: Simpler setup, less customization
  3. AI Code Review Action: Uses Google Gemini AI
  4. AI PR Summarizer: Focus on summarizing changes

Implementation Recommendations

Option 1: Use Code Rabbit GitHub App

  1. Install from GitHub Marketplace
  2. Configure via .coderabbit.yaml file:
    reviews:
      # Check against issue requirements
      check_requirements: true
      # Enable code duplication detection
      check_duplications: true
      # Set clean code standards
      style_guide: strict
      # Configure PR assignment for human review follow-up
      assign_to_author: false
      assign_to_reviewers: true
  3. Customize review depth and focus areas

Option 2: Custom GitHub Action

Create a custom action that:

  1. Extracts requirements from linked issues
  2. Runs code quality checks (ESLint, etc.)
  3. Uses AI to review code against requirements
  4. Detects code duplication
  5. Posts results as PR comments

Option 3: Hybrid Approach (Recommended)

  1. Use Code Rabbit for general code quality review
  2. Add custom GitHub Action for specific project requirements:
    name: PR Review
    on:
      pull_request:
        types: [opened, synchronize]
    
    jobs:
      requirements-check:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v3
          - name: Extract Issue Requirements
            id: extract
            run: |
              # Script to extract requirements from linked issue
          - name: Validate Against Requirements
            uses: mycoder-custom-validator@v1
            with:
              requirements: ${{ steps.extract.outputs.requirements }}
              pr_number: ${{ github.event.pull_request.number }}

Follow-up Review Process

When a PR is updated with new commits:

  1. Automatic re-review: Configure action to run on synchronize event
  2. Comment-based trigger: Allow requesting follow-up review with comment
  3. Status checks: Reset status checks when PR is updated to require re-review

Recommended Workflow

  1. PR is opened/updated → Automated review runs
  2. Review results posted as comments
  3. Developer addresses feedback
  4. On new commits → Re-run review automatically
  5. Optional human review assignment based on AI review results
  6. PR can be merged when all checks pass

Would you like me to help implement any of these options or provide more specific details on a particular approach?

@bhouston
Copy link
Member Author

Have a look at the existing issue-comment.yml file for our existing general mycoder workflow. Let's take that as an inspiration and create a new one. I think it should initially run when a PR is created and it should also run when the PR is updated with new code. It should reference a file in the root folder in the project .mycoder/PR_REVIEW.md and it should ask mycoder to review the current PR referencing the PR number based on the guidelines in PR_REVIEW.md. If you also create a basic PR_REVIEW.md file that at least asks that the PR address the concerns in the original issue and its discussion, it should have some basic code quality (not overly complex design, terse, not duplicate, the code is consistently organized like the rest of the project) guidelines and anything else you can think of. Maybe we should do what code rabbit is doing? We can add that to PR_REVIEW.md as requirements.

We should ensure that each new review on a PR reads the results of the last PR review if there was one as well as the existing discussions on PR so that it acts with full context. It shouldn't just repeat itself on each review, rather it should be encouraging and pushing towards a resolution.

We should not run lint or other tools in this PR review process because those are handled separately via CI, which we do not have to duplicate.

/mycode, can you propose a pr-review.yml GitHub action that achieves the above?

@bhouston
Copy link
Member Author

/mycoder can you implement the pr-review.yml based on the above design using issue-commont.yml Github Action workflow as a template.

@bhouston
Copy link
Member Author

Hello @bhouston,

I've created a PR review GitHub action as requested. However, I encountered a permission issue when trying to push the workflow file to GitHub. The GitHub App doesn't have the necessary workflows permission to create or update workflow files.

Here are the files I've created:

  1. PR Review GitHub Action Workflow (.github/workflows/pr-review.yml):
name: MyCoder PR Review Action

# This workflow is triggered when a PR is opened or updated with new commits
on:
  pull_request:
    types: [opened, synchronize]

# Top-level permissions apply to all jobs
permissions:
  contents: read # Required for checkout
  issues: read # Required for reading linked issues
  pull-requests: write # Required for commenting on PRs
  discussions: read # For reading discussions
  statuses: write # For creating commit statuses
  checks: write # For creating check runs
  actions: read # For inspecting workflow runs

env:
  ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

jobs:
  review-pr:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version-file: .nvmrc
      - uses: pnpm/action-setup@v4
        with:
          version: ${{ vars.PNPM_VERSION }}
      - run: pnpm install
      - run: cd packages/agent && pnpm exec playwright install --with-deps chromium
      - run: |
          git config --global user.name "Ben Houston (via MyCoder)"
          git config --global user.email "neuralsoft@gmail.com"
      - run: pnpm install -g mycoder
      - run: |
          echo "${{ secrets.GH_PAT }}" | gh auth login --with-token
          gh auth status
          
      # Get previous review comments for context
      - name: Get previous reviews
        id: get-reviews
        run: |
          PR_REVIEWS=$(gh pr view ${{ github.event.pull_request.number }} --json reviews --jq '.reviews')
          PR_COMMENTS=$(gh pr view ${{ github.event.pull_request.number }} --json comments --jq '.comments')
          echo "reviews=$PR_REVIEWS" >> $GITHUB_OUTPUT
          echo "comments=$PR_COMMENTS" >> $GITHUB_OUTPUT
      
      # Run MyCoder to review the PR
      - name: Review PR with MyCoder
        run: |
          mycoder --upgradeCheck false --githubMode true --userPrompt false "Please review PR #${{ github.event.pull_request.number }} according to the guidelines in .mycoder/PR_REVIEW.md. This PR is related to issue #${{ github.event.pull_request.head.ref }} and has the title '${{ github.event.pull_request.title }}'. Review the PR changes, check if it addresses the requirements in the linked issue, and provide constructive feedback. Consider previous review comments and discussions to avoid repetition and help move towards resolution. Previous reviews and comments: ${{ steps.get-reviews.outputs.reviews }} ${{ steps.get-reviews.outputs.comments }}"
  1. PR Review Guidelines (.mycoder/PR_REVIEW.md):
# MyCoder PR Review Guidelines

This document outlines the criteria and guidelines that MyCoder uses when reviewing pull requests. These guidelines help ensure that contributions maintain high quality and consistency with the project's standards.

## Issue Alignment

- Does the PR directly address the requirements specified in the linked issue?
- Are all the requirements from the original issue satisfied?
- Does the PR consider points raised in the issue discussion?
- Is there any scope creep (changes not related to the original issue)?

## Code Quality

- **Clean Design**: Is the code design clear and not overly complex?
- **Terseness**: Is the code concise without sacrificing readability?
- **Duplication**: Does the code avoid duplication? Are there opportunities to reuse existing code?
- **Consistency**: Does the code follow the same patterns and organization as the rest of the project?
- **Naming**: Are variables, functions, and classes named clearly and consistently?
- **Comments**: Are complex sections adequately commented? Are there unnecessary comments?

## Function and Component Design

- **Single Responsibility**: Does each function or component have a clear, single purpose?
- **Parameter Count**: Do functions have a reasonable number of parameters?
- **Return Values**: Are return values consistent and well-documented?
- **Error Handling**: Is error handling comprehensive and consistent?
- **Side Effects**: Are side effects minimized and documented where necessary?

## Testing

- Are there appropriate tests for new functionality?
- Do the tests cover edge cases and potential failure scenarios?
- Are the tests readable and maintainable?

## Documentation

- Is new functionality properly documented?
- Are changes to existing APIs documented?
- Are README or other documentation files updated if necessary?

## Performance Considerations

- Are there any potential performance issues?
- For computationally intensive operations, have alternatives been considered?

## Security Considerations

- Does the code introduce any security vulnerabilities?
- Is user input properly validated and sanitized?
- Are credentials and sensitive data handled securely?

## Accessibility

- Do UI changes maintain or improve accessibility?
- Are there appropriate ARIA attributes where needed?

## Browser/Environment Compatibility

- Will the changes work across all supported browsers/environments?
- Are there any platform-specific considerations that need addressing?

## Follow-up Review Guidelines

When reviewing updates to a PR:

- Focus on whether previous feedback has been addressed
- Acknowledge improvements and progress
- Provide constructive guidance for any remaining issues
- Be encouraging and solution-oriented
- Avoid repeating previous feedback unless clarification is needed
- Help move the PR towards completion rather than finding new issues

Remember that the goal is to help improve the code while maintaining a positive and constructive environment for all contributors.

Implementation Details:

  1. The workflow is triggered when a PR is opened or updated with new commits.
  2. It reads the PR review guidelines from .mycoder/PR_REVIEW.md.
  3. It captures previous review comments to provide context for the review.
  4. The review is performed by MyCoder, which provides feedback based on the guidelines.

To implement this, you'll need to:

  1. Manually create these files in your repository
  2. Ensure your GitHub Actions have the appropriate permissions

Would you like me to modify any aspects of this implementation?

@bhouston
Copy link
Member Author

/mycoder can you implement this as a PR back to this Github repository adding issue-create.yml Github Action workflow?

@bhouston
Copy link
Member Author

I've created PR #359 with the PR review guidelines file (.mycoder/PR_REVIEW.md).

However, I was unable to include the PR review GitHub Action workflow file (.github/workflows/pr-review.yml) in the PR due to permission limitations. GitHub Apps (which MyCoder appears to be using) need the workflows permission to create or update workflow files.

Here's the content of the PR review workflow file that should be added manually by someone with appropriate permissions:

name: MyCoder PR Review Action

# This workflow is triggered when a PR is opened or updated with new commits
on:
  pull_request:
    types: [opened, synchronize]

# Top-level permissions apply to all jobs
permissions:
  contents: read # Required for checkout
  issues: read # Required for reading linked issues
  pull-requests: write # Required for commenting on PRs
  discussions: read # For reading discussions
  statuses: write # For creating commit statuses
  checks: write # For creating check runs
  actions: read # For inspecting workflow runs

env:
  ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

jobs:
  review-pr:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version-file: .nvmrc
      - uses: pnpm/action-setup@v4
        with:
          version: ${{ vars.PNPM_VERSION }}
      - run: pnpm install
      - run: cd packages/agent && pnpm exec playwright install --with-deps chromium
      - run: |
          git config --global user.name "Ben Houston (via MyCoder)"
          git config --global user.email "neuralsoft@gmail.com"
      - run: pnpm install -g mycoder
      - run: |
          echo "${{ secrets.GH_PAT }}" | gh auth login --with-token
          gh auth status
          
      # Get previous review comments for context
      - name: Get previous reviews
        id: get-reviews
        run: |
          PR_REVIEWS=$(gh pr view ${{ github.event.pull_request.number }} --json reviews --jq '.reviews')
          PR_COMMENTS=$(gh pr view ${{ github.event.pull_request.number }} --json comments --jq '.comments')
          echo "reviews=$PR_REVIEWS" >> $GITHUB_OUTPUT
          echo "comments=$PR_COMMENTS" >> $GITHUB_OUTPUT
      
      # Extract issue number from branch name or PR description
      - name: Extract linked issue
        id: extract-issue
        run: |
          # Try to extract from branch name first (assuming format like issue-123 or fix-123)
          BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
          ISSUE_FROM_BRANCH=$(echo $BRANCH_NAME | grep -oE '[0-9]+' | head -1 || echo "")
          
          # If not found in branch, try to find in PR body with "Fixes #123" or "Closes #123" format
          if [ -z "$ISSUE_FROM_BRANCH" ]; then
            PR_BODY="${{ github.event.pull_request.body }}"
            ISSUE_FROM_BODY=$(echo "$PR_BODY" | grep -oE '(fix|fixes|close|closes|resolve|resolves)\s+#[0-9]+' | grep -oE '[0-9]+' | head -1 || echo "")
            ISSUE_NUMBER="$ISSUE_FROM_BODY"
          else
            ISSUE_NUMBER="$ISSUE_FROM_BRANCH"
          fi
          
          echo "issue_number=$ISSUE_NUMBER" >> $GITHUB_OUTPUT
      
      # Run MyCoder to review the PR
      - name: Review PR with MyCoder
        run: |
          mycoder --upgradeCheck false --githubMode true --userPrompt false "Please review PR #${{ github.event.pull_request.number }} according to the guidelines in .mycoder/PR_REVIEW.md. This PR is related to issue #${{ steps.extract-issue.outputs.issue_number || 'unknown' }} and has the title '${{ github.event.pull_request.title }}'. Review the PR changes, check if it addresses the requirements in the linked issue, and provide constructive feedback. Consider previous review comments and discussions to avoid repetition and help move towards resolution. Previous reviews and comments: ${{ steps.get-reviews.outputs.reviews }} ${{ steps.get-reviews.outputs.comments }}"

This workflow is designed to:

  1. Run automatically when a PR is created or updated
  2. Use the guidelines in .mycoder/PR_REVIEW.md to review the PR
  3. Consider previous review comments to avoid repetition
  4. Check alignment with the original issue requirements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy