Skip to content

Commit

Permalink
feat: create dismiss stale reviews functionality (#22)
Browse files Browse the repository at this point in the history
- create core functionality of dismiss stale review
  • Loading branch information
Balvajs authored Aug 29, 2023
1 parent dac8586 commit 1c5fb4d
Show file tree
Hide file tree
Showing 24 changed files with 27,025 additions and 33 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ jobs:
- uses: actions/checkout@v3

- uses: ./
with:
dry-run: true
53 changes: 47 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,67 @@
## dismiss-stale-reviews

Description
Action for dismissing stale code reviews based on CODEOWNERS.

GitHub has a branch protection rule that enables `dismissing all reviews when new commits are pushed`:
![GitHub branch protection rule for dismissing all reviews when new commits are pushed](/docs/github-default-dismiss-approvals.png)

However, in most cases, we want to treat reviews as stale only if the approver is the codeowner of files changed in the new commits.

This action checks all approvals upon every commit push and removes reviews only from codeowners of changed files.
![Stale reviews dismissed based on ownership](/docs/dismiss-reviews-based-on-ownership.png)

## Edge cases

There are some situations when it can’t be decided what should be dismissed. In those situations, the action defaults to GitHub’s default behavior - dismissing all reviews.

##### 1. Some of the changed files don’t have an owner

The behavior in this case can be changed by input `no-owner-action`, which accepts either `dismiss-all` or `dismiss-none`. The default is `dismiss-all`.

##### 2. The action isn’t able to find changes in the last commit because of a force push

The action is not able to work with force pushes. The behavior in this case can be changed by input `force-push-action`, which accepts either `dismiss-all` or `dismiss-none`. The default is `dismiss-all`.

## Usage

```yaml
name: 'dismiss-stale-reviews'
on:
schedule:
- cron: '0 0 * * 1'
pull_request:

jobs:
dismiss-stale-reviews:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# the git history must be fetched until merge-base commit of pull-request
fetch-depth: 0

# in case you use team handles in your CODEOWNERS file, you need to get a GitHub App token with advanced permissions:
# repository contents: read
# repository pull requests: write
# organization members: read
#
# for more info on how to create GitHub App check tibdex/github-app-token action
- uses: tibdex/github-app-token@v1
id: get-token
with:
app_id: ${{ secrets.MANAGE_REVIEWS_BOT_ID }}
private_key: ${{ secrets.MANAGE_REVIEWS_BOT_PEM }}

- uses: balvajs/dismiss-stale-reviews@v1
with:
token: ${{ steps.get-token.outputs.token }}
```
## Inputs
| INPUT | TYPE | DEFAULT | DESCRIPTION |
| ----- | ---- | ------- | ----------- |
| | | | |
| INPUT | TYPE | DEFAULT | DESCRIPTION |
| ----------------- | -------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| token | string | `"${{ github.token }}"` | GitHub token with permissions to read organization. Default is github.token |
| ignore-files | string[] | `[]` | List of file patterns that should be ignored -> no review will be dismissed based on these files changes. The list is new line separated |
| no-owner-action | enum | `"dismiss-all"` | What should happen if some file doesn't have owner. Valid options are `"dismiss-all"` and `"dismiss-none"`. |
| force-push-action | enum | `"dismiss-all"` | What should happen if the git diff couldn't be resolved due to force push. Valid options are `"dismiss-all"` and `"dismiss-none"`. |

\* required
34 changes: 15 additions & 19 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
name: Cleanup stale branches
description: Simple action for deleting stale branches
name: Dismiss stale PR reviews based on ownership
description: Dismiss all reviews that are stale. The staleness is decided based on changed files and Codeowners file.
author: Balvajs
branding:
icon: git-branch
color: orange
icon: 'git-pull-request'
color: 'yellow'

inputs:
days-to-delete:
ignore-files:
required: false
description: Number of days without activity after which the branch will be deleted. Default is 90 days.
default: '90'

dry-run:
required: false
description: If set to true, the action will only log the branches that would be deleted, but will not delete them. Default is true.
default: 'true'

repository:
required: false
description: Repository name and owner in format owner/repo. Default is current repository.
default: ${{ github.repository }}

description: List of file patterns that should be ignored -> no review will be dismissed based on these files changes. The list is new line separated
token:
required: false
description: GitHub token. Default is github.token
description: GitHub token with permissions to read organization. Default is github.token
default: ${{ github.token }}
no-owner-action:
required: false
description: What should happen if some file doesn't have owner. Valid options are `"dismiss-all"` and `"dismiss-none"`
default: dismiss-all
force-push-action:
required: false
description: What should happen if the git diff couldn't be resolved due to force push. Valid options are `"dismiss-all"` and `"dismiss-none"`
default: dismiss-all

runs:
using: 'node16'
Expand Down
2 changes: 1 addition & 1 deletion codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
schema: schema.idl,
documents: '**/*.ts',
documents: 'src/**/*.ts',
emitLegacyCommonJSImports: false,
generates: {
'/': {
Expand Down
Loading

0 comments on commit 1c5fb4d

Please sign in to comment.