ewolfe / prlint

GitHub App for linting pull request meta data

Home Page:https://github.com/apps/prlint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PRLint

GitHub App for linting pull requests

Uptime Robot status Greenkeeper badge Build Status Test Coverage All Contributors Join the community on Spectrum

The Problem

You want your pull requests to have a consistent convention for titles, descriptions, branch names, labels, milestones, and more.

This Solution

PRLint will let you run regular expressions against your pull request meta data. You can then enable PRLint status checks to pass before a pull request can be merged.

Screenshots

Success

Error

Example Rules

.github/prlint.json

{
  "title": [
    {
      "pattern": "^(build|ci|docs|feat|fix|perf|refactor|style|test):\\s",
      "message": "Your title needs to be prefixed with a topic"
    }
  ],
  "body": [
    {
      "pattern": "JIRA-\\d{1,4}",
      "flags": ["i"],
      "message": "You need a JIRA ticket in your description"
    },
    {
      "pattern": ".{1,}",
      "message": "You need literally anything in your description"
    }
  ],
  "head.ref": [
    {
      "pattern": "^(build|ci|docs|feat|fix|perf|refactor|style|test)/",
      "message": "Your branch name is invalid"
    }
  ],
  "assignee.login": [
    {
      "pattern": ".+",
      "message": "You need to assign someone"
    }
  ],
  "requested_teams.0.id": [
    {
      "pattern": "2691982",
      "message": "The product team needs to be added as a reviewer"
    }
  ],
  "additions": [
    {
      "pattern": "0|^[1-9]$|^[1-9]\\d$",
      "message": "Your PR is too big (over 99 additions)"
    }
  ],
  "labels.0.name": [
    {
      "pattern": "bug|enhancement|question",
      "message": "Please add a label"
    }
  ]
}

You can check anything listed in the pull request object

Install

  1. Install via https://github.com/apps/prlint
  2. Add this file .github/prlint.json to the root of your project:
{
  "title": [
    {
      "pattern": "^(build|ci|docs|feat|fix|perf|refactor|style|test)((.+))?:\\s.+",
      "message": "Your title needs to be prefixed with a topic"
    }
  ]
}
  1. Test it by opening a pull request with the title "chore: add prlint"

Demo

Usage

Keys:

The top level keys are keys that the GitHub API exposes when a pull request is opened, edited, etc.

You can use anything listed in the sample response object here sample response object here

To target a nested object, you can use dot notation encoded within the key string. i.e.:

{
  "assignee.login": [
    {
      "pattern": "octocat"
    }
  ]
}

Values:

The top level values are where you get to define your validation rules. You can have multiples rules, so we expect an array (even if you only have a single validation rule).

  • Each item in the array needs to be an object:
  • pattern: javascript Regular Expression
    • Special characters must be escaped i.e. If you want to check for a whitespace, use "pattern": "\\s" vs "pattern": "\s"
  • flags: optional array of strings used in the Regular Expression
    • For example, this can be used to make your regex case insensitive
  • message: optional string for customizing the error message on the pull request page

Credits

License

MIT

Contributors

Thanks goes to these wonderful people (emoji key):

Hrusikesh Panda
Hrusikesh Panda

🚇 ⚠️ 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

About

GitHub App for linting pull request meta data

https://github.com/apps/prlint

License:MIT License


Languages

Language:JavaScript 99.6%Language:Shell 0.4%