GitHub App for linting pull requests
You want your pull requests to have a consistent convention for titles, descriptions, branch names, labels, milestones, and more.
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.
.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 via https://github.com/apps/prlint
- 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"
}
]
}
- Test it by opening a pull request with the title "chore: add prlint"
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"
}
]
}
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"
- Special characters must be escaped
i.e. If you want to check for a whitespace, use
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
- “Dust Bunny” icon by Erika Kim from the Noun Project.
MIT
Thanks goes to these wonderful people (emoji key):
Hrusikesh Panda 🚇 |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!