GitHub Action
Check pull request body, diff and files
Originally based on the actions TS template, it checks for the presence of a word in the body or diff in a PR, as well as certain conditions on the PR: number of files changed, and number of lines changed.
It uses the GitHub API, so you'll need to provide a token. Don't worry, that's built-in.
You would need to put this in a file in the .github/workflows
directory
name: "Check PR for word"
on: [pull_request]
jobs:
check_pr:
runs-on: ubuntu-latest
steps:
- name: Check PR
uses: JJ/github-pr-contains-action@releases/v7
with:
github-token: ${{github.token}}
bodyDoesNotContain: "Delete|this"
bodyContains: 'Test'
diffContains: ';'
diffDoesNotContain: "TODO|to do"
filesChanged: 1
linesChanged: 1
The bodyContains
variable will include the string that we want the body of the PR to include, such as checked items in a checklist; obviously bodyDoesNotContain
will hold the opposite, what we don't want to see in the PR body. Any of them can have a |
separated list of words or expressions. The PR will check it contains any of the words in bodyContains
and none of the words in bodyDoesnotContain
.
Same patterm for diff(Contains|DoesNotContain)
. Can be a word or list of words you want in the diff (for instance, you want it to always change code so it contains a statement terminator) or don't want in the diff (for instance, you don't want it to include TODOs because people never ever do them).
These strings are unwittingly converted into regular expressions, so any regular expression will also work;
[]()+?*
are escaped so that things such as[.]
work with the literal meaning.
They can be left empty if no check wants to be done.
An example is used as .github/workflows/check-PRs-here.yaml in this repository as well as this one, which is the one I use for testing.
Any suggestion, bug report, etc, is appreciated. Please use issues.
There are several forks of this action, with additional features:
- PR content checker by @jsoares includes
diffDoesNotContain
- Francisco Giordano's
pr-content-checker
v0
: proof of concept, published to marketplacev1
: Adds several more checksv2
: Adds check for strings to avoid and creates issues for errors.v3
: Changes packaging, upgrades modules, deletes unneeded files.v4
: Solves a number of issues.v5
: Will not usediffContains
if it's an empty stringv6
: can use words or regular expressions inbodyContains
/bodyDoesNotContain
v7
: includes more "rexified" characters:*,?,+
v8
: addsdiffDoesNotContain
and extends regex testing to diff tests.
This is a modification of the original template, and is released under the MIT license.