Skip to content

Commit

Permalink
ci: add require multiple reviewers action (#204)
Browse files Browse the repository at this point in the history
Requires a specified number of reviewers for certain important files,
the files are to be provided as an `important-files-path` var.

See `README.md` for more details
https://github.com/dequelabs/axe-api-team-public/pull/204/files#diff-db32ad4c1ae8b5f09def402ee7d7876046a269ae8c7b5bfb42567d703807902b

**NOTE:** this version doesn't account for edge cases like accounting
for approvals from people who requested changes, e.g. if a PR requires 2
reviewers, 1 reviewer requested changes but other 2 reviewers approved
the PR, the action will pass.

1. This would show a `Tests / require-multiple-reviewers` check that
would fail until a required number of reviewers approves a PR that uses
the action.
2. Also shows annotations on the files that are important. Annotations
remain on the files for information purposes and are not removed.

**Changes requested:**
<img width="842" alt="Tests / require-multiple-reviewers` fails since
the PR requires 1 reviewer and changes are requested"
src="https://github.com/user-attachments/assets/f9f49afa-6a23-4839-a374-f92eb9d387de"
/>

**Changes approved:**
<img width="842" alt="Tests / require-multiple-reviewers` passes since
the PR requires 1 reviewer and it's approved by 1 reviewer"
src="https://github.com/user-attachments/assets/ee1bfdd5-9f9d-405c-9f42-89409c7ecd41"
/>

**Annotations:**
<img width="1354" alt="`Annotation on an important file 'The file
important.txt is important and requires at least 1 reviewers.'"
src="https://github.com/user-attachments/assets/9f9a273a-8830-4ae1-9c3c-1625f7c2d542"
/>

Ref: dequelabs/axe-linter#1632
  • Loading branch information
zlayaAvocado authored Jan 2, 2025
1 parent be80cd6 commit da003bd
Show file tree
Hide file tree
Showing 20 changed files with 33,439 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto eol=lf

**/dist/** -diff linguist-generated=true
50 changes: 50 additions & 0 deletions .github/actions/require-multiple-reviewers-v1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# require-multiple-reviewers-v1

A GitHub Action that requires multiple reviewers for important files

## Inputs

| Name | Required | Description | Default |
| ---------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `token` | Yes | A GitHub token with the [required permissions](#permissions) | NA |
| `number-of-reviewers` | Yes | The number of reviewers required. | 2 |
| `important-files-path` | Yes | The path to the file containing a list of important files. It should comply with [gitignore syntax](https://git-scm.com/docs/gitignore). | NA |

## Example usage

```yaml
name: Require multiple reviewers

# This must be both pull_request and pull_request_review.
# pull_request - for when the PR is initially created (or files are changed)
# pull_request_review - for when the count of reviews on a PR changes
on:
pull_request:
pull_request_review:

jobs:
require-multiple-reviewers:
runs-on: ubuntu-latest
timeout-minutes: 2
permissions:
pull-requests: read
contents: read
checks: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Require two reviewers for important files
uses: dequelabs/axe-api-team-public/.github/actions/require-multiple-reviewers-v1@main
with:
token: ${{ github.token }}
number-of-reviewers: 2
important-files-path: .github/important-files.txt
```
## Permissions
This action requires the following permission scopes:
- `pull-requests: read` - To get pull request reviews.
- `contents: read` - To read the contents of the repository, including the changed and important files.
- `checks: write` - To create and update check runs with the results of the action.
19 changes: 19 additions & 0 deletions .github/actions/require-multiple-reviewers-v1/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Require multiple reviewers
description: Require multiple reviewers for important files

# Define your inputs here.
inputs:
token:
description: 'A GitHub token with the required permissions'
required: true
number-of-reviewers:
description: 'The number of reviewers required.'
required: true
default: '2'
important-files-path:
description: 'The path to the file containing a list of important files (gitignore syntax supported).'
required: true

runs:
using: node20
main: dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit da003bd

Please sign in to comment.