{"id":15650602,"url":"https://github.com/jj/github-pr-contains-action","last_synced_at":"2025-04-06T02:07:19.137Z","repository":{"id":41971345,"uuid":"206760179","full_name":"JJ/github-pr-contains-action","owner":"JJ","description":"Action that checks whether the body or diff in a PR contains a certain word.","archived":false,"fork":false,"pushed_at":"2025-02-19T13:36:38.000Z","size":22746,"stargazers_count":38,"open_issues_count":13,"forks_count":36,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T01:05:34.080Z","etag":null,"topics":["github","github-actions","hacktoberfest","hacktoberfest2021","hacktoberfest2023"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JJ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-06T09:27:23.000Z","updated_at":"2025-03-18T13:14:11.000Z","dependencies_parsed_at":"2024-04-19T18:50:20.166Z","dependency_job_id":"4f0565a5-bf2e-4c3b-9fc7-21aef8529b22","html_url":"https://github.com/JJ/github-pr-contains-action","commit_stats":{"total_commits":204,"total_committers":2,"mean_commits":102.0,"dds":0.08333333333333337,"last_synced_commit":"19bc4c512594375f8bf7a33fb1107a287f577334"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":"actions/typescript-action","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JJ%2Fgithub-pr-contains-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JJ%2Fgithub-pr-contains-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JJ%2Fgithub-pr-contains-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JJ%2Fgithub-pr-contains-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JJ","download_url":"https://codeload.github.com/JJ/github-pr-contains-action/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423512,"owners_count":20936626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github","github-actions","hacktoberfest","hacktoberfest2021","hacktoberfest2023"],"created_at":"2024-10-03T12:35:11.520Z","updated_at":"2025-04-06T02:07:19.114Z","avatar_url":"https://github.com/JJ.png","language":"TypeScript","readme":"# A GitHub action that checks pull requests description and contents [![Basic installation and build checks](https://github.com/JJ/github-pr-contains-action/actions/workflows/install-build-checks.yml/badge.svg)](https://github.com/JJ/github-pr-contains-action/actions/workflows/install-build-checks.yml)[![Check correct version in README](https://github.com/JJ/github-pr-contains-action/actions/workflows/check-v.yml/badge.svg)](https://github.com/JJ/github-pr-contains-action/actions/workflows/check-v.yml)\n\nThis GitHub action checks for the presence/absence of a string or group of\nstrings in the body of the pull request or diff, as well as certain conditions\nin the PR: number of files changed, and number of lines changed.\n\nIt uses the GitHub API, so you'll need to provide a token. Don't worry, that's\nbuilt-in.\n\n## Using this action\n\nYou would need to put this in a YAML file (`check-pr.yml`, for instance) in the\n`.github/workflows` directory:\n\n```yaml\nname: \"Check PR content\"\non: [pull_request]\n\njobs:\n  check_pr:\n    runs-on: ubuntu-latest\n    steps:\n    - name: Check PR\n      uses: JJ/github-pr-contains-action@releases/v14.1\n      with:\n        github-token: ${{github.token}}\n        bodyDoesNotContain: \"Delete|this\"\n        bodyContains: 'Test'\n        diffContains: ';'\n        diffDoesNotContain: \"TODO|to do\"\n        filesChanged: 1\n        linesChanged: 1\n        waivedUsers: \"SomeOne|dependabot[bot]\"\n```\n\nThe `pull_request` event is needed, because it will use its payload.\n\nThe `bodyContains` variable will include the string that we want the body of the\nPR to include, such as checked items in a checklist; obviously\n`bodyDoesNotContain` will hold the opposite, what we don't want to see in the PR\nbody. Any of them can have a `|` separated list of words or expressions. The PR\nwill check it contains _any_ of the words in `bodyContains` and _none_ of the\nwords in `bodyDoesNotContain`.\n\nSame pattern for `diff(Contains|DoesNotContain)`. Can be a word or list of words\nyou want in the diff (for instance, you want it to _always_ change code so it\ncontains a statement terminator) or don't want in the diff (for instance, you\ndon't want it to include TODOs because people never ever _do_ them). If you want\nto allow check marks, remember to use an expression such as `[x]|[X]`, since\nboth are admissible as such in a body.\n\n\u003e These strings are unwittingly converted into regular expressions, so any\n\u003e regular expression will also work; `[]()+?*` are escaped so that things such\n\u003e as `[.]` work with the literal meaning. They can be left empty if you don't\n\u003e need that specific check. This also implies that all these regex marks will\n\u003e not be used as such, so avoid using things such as `[xX]` to indicate\n\u003e alternatives.\n\nFinally, `waivedUsers` is a `|`-separated string of the users that will be\nspared from running these checks; if the PR is triggered by one of those users,\nit will exit with a warning and with a green status. By default, it has the\nvalue `\"dependabot[bot]\"`. If you want to edit more and want to keep dependabot\nPRs from failing, add it to your list.\n\nIf you want to see an example, it is used as\n[.github/workflows/check-PRs-here.yaml](.github/workflows/check-PRs-here.yaml)\nin this repository as well as [this one, which is the one I use for\ntesting](.github/workflows/pr.yaml).\n\nYou might want to qualify possible events that trigger this action; for intance, this way:\n\n```yaml\n  pull_request:\n    types:\n      [opened, edited, assigned, closed, synchronize, review_requested, ready_for_review]\n```\n\nThis will skip diff checks every single push, for instance. Please remember that\n_this action will only work in pull requests_, since it checks the pull request\nobject payload. It will simply skip any check (with a warning) if it is not\ntriggered by a `pull_request` or `pull_request_target` event.\n\nFor instance, you might want to use a GitHub action such as [this\none](.github/workflows/contributors.yaml) for the `CONTRIBUTORS.md` file:\n\n``` yaml\nname: \"Check contributors file additions\"\non:\n  pull_request:\n    types: [opened, edited]\n    paths:\n      - CONTRIBUTORS.md\n\njobs:\n  check_pr:\n    name: \"Checks contributors\"\n    runs-on: ubuntu-latest\n    steps:\n      - name: Check that any new contributor links to their github page\n        uses: JJ/github-pr-contains-action@releases/v14.1\n        with:\n          github-token: ${{github.token}}\n          linesChanged: 1\n          filesChanged: 1\n          diffContains: \"github.com/\"\n          waivedUsers: \"dependabot[bot]|CompanyBigWig\"\n```\n\nThis action would check that there's only a single file modified (because why\nwould you need to change another, if all you want is to add your name to the\ncontributors' file), a single line is changed (because you're only one, right?)\nand that it includes a link to your GitHub profile by forcing the diff to\ncontain that string. It would also allow the company's big wig to add however\nmany they want, with or without links to their profiles.\n\n### Working with action outputs\n\nThis action produces two outputs: `diff`, containing effectively the diff\nincluded in the PR, and `numberOfFiles`, with the list of files that have been\nincluded in the PR. You can use that, for instance, this way:\n\n```yaml\n      - name: Info PR\n        env:\n          NUMBER_OF_FILES : ${{ steps.dev_check_pr.outputs.numberOfFiles }}\n        run: |\n          echo \"::warning::We got files: $NUMBER_OF_FILES\"\n      - name: Fail if too big\n        if: ${{ steps.dev_check_pr.outputs.numberOfFiles \u003e 3 }}\n        env:\n          NUMBER_OF_FILES : ${{ steps.dev_check_pr.outputs.numberOfFiles }}\n        run: |\n          echo \"::error::Too many files, there are $NUMBER_OF_FILES, should be at most 3\"\n          exit 1\n```\n\nto show the number of files present in the PR, as well as to fail if there are\ntoo many files (to enforce keeping PRs small, for instance).\n\nThe `diff` output might contain a huge amount of information, which might make\nit a bit hard to deal with via environment variables. Dealing with it otherwise,\nvia `github-script`, is probably fine.\n\n\n\n## Contributing to development\n\nAny suggestion, bug report, etc, is appreciated. Please check out or create an\n[issue](https://github.com/JJ/github-pr-contains-action/issues) before\ncontributing a PR, if possible.\n\n## Developing and testing\n\nGitHub actions are notoriously hard to test in any other way than actually\nrunning them, so this repository is set up for local tests in a `dev` branch;\ncreate that branch and work with it until you're satisfied and merge it to\n`main`.\n\n\u003e I write this as much for myself as for any other purpose...\n\n## See also\n\nThere are several forks of this action, with additional features:\n\n- [PR content checker by @jsoares](https://github.com/jsoares/gh-pr-content-checker/)\n- [Francisco Giordano's `pr-content-checker`](https://github.com/francesco-giordano/gh-pr-content-checker)\n- [Pablo Statsig's `pr-content-checker`](https://github.com/pablo-statsig/gh-pr-content-checker/)\n\n## History\n\n\u003e Tags for every release are preceded by `releases/`\n\n- `v0`: proof of concept, published to marketplace\n- `v1`: Adds several more checks\n- `v2`: Adds check for strings to avoid and creates issues for errors.\n- `v3`: Changes packaging, upgrades modules, deletes unneeded files.\n- `v4`: Solves a number of issues.\n- `v5`: Will not use `diffContains` if it's an empty string\n- `v6`: can use words or regular expressions in `bodyContains`/ `bodyDoesNotContain`\n- `v7`: includes more \"rexified\" characters: `*,?,+`\n- `v8`: adds `diffDoesNotContain` and extends regex testing to diff tests.\n- `v9`: adds some informative messages, disables API calls for private repositories.\n- `v10`: Skips checks if not in a pull request; adds information to prevent this use too.\n- `v11`: Adds a configuration variable that skips users, with dependabot skipped by default (or passed through).\n- `v12`: Make it compatible with private repos. Upgrade to latest github API.\n- `v13`: Fixes the use of `waivedUsers` which didn't actually work.\n- `v14`: Eliminates setting of environment variables, documents using action\n  output.\n- `v14.1`: Refrains from doing diff stuff if no variable related to diff has\n  been set\n\n## License\n\n(c) JJ Merelo, 2021-2024. Released under the MIT license. Read\n[LICENSE](LICENSE) for more details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjj%2Fgithub-pr-contains-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjj%2Fgithub-pr-contains-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjj%2Fgithub-pr-contains-action/lists"}