Code Monkey home page Code Monkey logo

prator's Introduction

Pull Request Auto Reviewer (GitHub Action)

action example

This script is for public repositories. For private ones use a simplified version of it.

Add review comments to your pull requests based on changes in 3 steps:

  1. Add rules for the action script (more info):
- prependMsg: "🗯️ [pull-request-auto-reviewer](https://github.com/marketplace/actions/pull-request-auto-reviewer):"
- checks:
    - paths: "**/*.js"
      message: |
        ### As you changed javascript file(s) tick the following checks:

        - [ ] unit/integration tests are added
        - [ ] no performance implications
        - [ ] relevant documentation is added/updated
    - paths: "package-lock.json"
      message: |
        ### Since you've added/updated dependencies, pay attention to this:

        - [ ] clear reasoning for adding or updating the dependency is provided
        - [ ] no security implications or concerns related to the dependency
  1. Add artifact uploading config (more info):
name: Auto Review Prepare
on:
  pull_request:
    branches:
      - main
      - master
jobs:
  prepare:
    name: Prepare
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 2
      - name: Save PR number
        run: echo "${{ github.event.pull_request.number }}" > pr_number.txt
      - name: Generate Diff
        run: |
          git fetch origin ${{ github.event.pull_request.base.ref }}
          git diff --name-only origin/${{ github.event.pull_request.base.ref }}..${{ github.sha }} > pr_files_diff.txt
      - name: Create artifact folder
        run: mkdir -p pr_diff && mv pr_number.txt pr_files_diff.txt pr_diff/
      - name: Upload PR details as artifact
        uses: actions/upload-artifact@v4
        with:
          name: pr-diff
          path: pr_diff/
  1. Add artifact downloading and code analysis config (more info)
name: Auto Review Comment
on:
  workflow_run:
    workflows:
      - Auto-review Diff Prepare
    types:
      - completed
permissions:
  pull-requests: write
jobs:
  auto-review:
    name: Review
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the repository
        uses: actions/checkout@v4
      - name: Download PR diff from auto review prepare step
        uses: actions/download-artifact@v4
        with:
          name: pr-diff
          path: pr_diff/
          repository: ${{ github.repository_owner }}/${{ github.event.repository.name }}
          run-id: ${{ github.event.workflow_run.id }}
          github-token: ${{ secrets.GITHUB_TOKEN }}
      - name: Analyze changes
        uses: pshergie/prator@v1
        id: auto-review-action
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          rules-path: path-to-your-rules-file

Add rules for the action script

For this step you need to create a YAML file with the rules that are going to be utilized by the action script. There you need to specify 2 params:

  • prependMsg is a message that is prepended to every message of GitHub actions bot. Leave empty if not needed.
  • checks contains a list of paths and message keys. paths is dedicated to specify path(s) of changes that would trigger posting of a followed message as a pull request comment. In case of multiple paths they should be separated by a comma. message could be a simple string or markdown. All messages will be combined into a single comment.

Add artifact uploading config

Since posting comments on GitHub requires write permission you need two create 2 workflows. One to collect PR changes and upload as artifact (this step) and another to download them and apply the script (next step). There's an optional artifact-path parameter if you want a different path to the artifact (make sure that this change is reflected in the download artifact config). The default value is pr_diff/

Add artifact downloading and code analysis config

In this step create a workflow that downloads the artifact and applies the script. pull-requests: write permission is needed for the GitHub actions bot to be able to post a comment in a PR. It's also important to provide 2 params that are being consumed by the action script:

  • token: your GitHub token
  • rules-path: a path to the file with rules that you have specified earlier (for instance .github/auto-review-rules.yml)

Note: The workflow executes from the main/master branch and is not visible in the PR checks.

prator's People

Contributors

pshergie avatar

Stargazers

Stanislav Sysoev avatar Mehdi avatar Zdorovtsev Viktor avatar Sam Bulatov avatar Maksim Baranov avatar Andrei Vakulski avatar  avatar Pavel Kalashnikov avatar Dmitry Davydov avatar Marcis Bergmanis avatar Greg Zhang avatar absinthe avatar Jonas Galvez avatar Alex Wilson avatar bin avatar Mikhail Gorbunov avatar Andrey Sitnik avatar Kristóf Poduszló avatar 樊小书生 avatar Zhazha_JiaYiZhen avatar afc163 avatar  avatar Alexey avatar

Watchers

 avatar

Forkers

ai

prator's Issues

Add file adding check

Someting like:

  - added: 'scripts/*.ts'
    message: 'Don’t forget to add docs to any script'

Add check that file was not added

Use case:

I want to add “Add tests” message if user change core/*.ts but don’t change anything in core/test/*.test.ts

So I suggest something like:

    - paths: 'core/*.ts'
      missed: 'core/test/*.test.ts'
      message: |
        - [ ] Don’t rush. Check all changes in PR again.
        - [ ] Run `pnpm test`.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.