Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes formatting feature #29

Merged
merged 13 commits into from
Jan 10, 2021
89 changes: 1 addition & 88 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,6 @@ jobs:
exit 1
fi

test-check-format:
name: runner / black-format (github-check-format)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
github_token: ${{ secrets.github_token }}
reporter: github-check
level: info
format: true
workdir: ./testdata/
- name: Check if formatting was successful
run: |
changed_files=$(git status --porcelain | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
exit 1
else
echo "Changes detected!"
fi

test-pr-check:
if: github.event_name == 'pull_request'
name: runner / black-format (github-pr-check)
Expand All @@ -60,38 +38,6 @@ jobs:
reporter: github-pr-check
level: warning
workdir: ./testdata/
- name: Check if code is left untouched (not formatted)
run: |
changed_files=$(git status --porcelain | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
else
echo "Changes detected!"
exit 1
fi

test-pr-check-format:
if: github.event_name == 'pull_request'
name: runner / black-format (github-pr-check-format)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-check
level: warning
format: true
workdir: ./testdata/
- name: Check if formatting was successful
run: |
changed_files=$(git status --porcelain | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
exit 1
else
echo "Changes detected!"
fi

test-pr-review:
if: github.event_name == 'pull_request'
Expand All @@ -105,37 +51,4 @@ jobs:
reporter: github-pr-review
level: error
reviewdog_flags: -filter-mode=file -fail-on-error
workdir: ./testdata/
- name: Check if code is left untouched (not formatted)
run: |
changed_files=$(git status --porcelain | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
else
echo "Changes detected!"
exit 1
fi

test-pr-review-format:
if: github.event_name == 'pull_request'
name: runner / black-format (github-pr-review-format)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: error
reviewdog_flags: -filter-mode=file -fail-on-error
format: true
workdir: ./testdata/
- name: Check if formatting was successful
run: |
changed_files=$(git status --porcelain | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
exit 1
else
echo "Changes detected!"
fi
workdir: ./testdata/
178 changes: 48 additions & 130 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,85 +1,19 @@
# Black action

[![Test](https://github.com/rickstaa/action-black/workflows/Test/badge.svg)](https://github.com/rickstaa/action-black/actions?query=workflow%3ATest)
[![reviewdog](https://github.com/rickstaa/action-black/workflows/reviewdog/badge.svg)](https://github.com/rickstaa/action-black/actions?query=workflow%3Areviewdog)
[![depup](https://github.com/rickstaa/action-black/workflows/depup/badge.svg)](https://github.com/rickstaa/action-black/actions?query=workflow%3Adepup)
[![release](https://github.com/rickstaa/action-black/workflows/release/badge.svg)](https://github.com/rickstaa/action-black/actions?query=workflow%3Arelease)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/rickstaa/action-black?logo=github\&sort=semver)](https://github.com/rickstaa/action-black/releases)
[![Test](https://github.com/reviewdog/action-black/workflows/Test/badge.svg)](https://github.com/reviewdog/action-black/actions?query=workflow%3ATest)
[![reviewdog](https://github.com/reviewdog/action-black/workflows/reviewdog/badge.svg)](https://github.com/reviewdog/action-black/actions?query=workflow%3Areviewdog)
[![depup](https://github.com/reviewdog/action-black/workflows/depup/badge.svg)](https://github.com/reviewdog/action-black/actions?query=workflow%3Adepup)
[![release](https://github.com/reviewdog/action-black/workflows/release/badge.svg)](https://github.com/reviewdog/action-black/actions?query=workflow%3Arelease)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/reviewdog/action-black?logo=github\&sort=semver)](https://github.com/reviewdog/action-black/releases)
[![action-bumpr supported](https://img.shields.io/badge/bumpr-supported-ff69b4?logo=github\&link=https://github.com/haya14busa/action-bumpr)](https://github.com/haya14busa/action-bumpr)

![github-pr-check demo](https://user-images.githubusercontent.com/17570430/102082175-c6773780-3e11-11eb-9af9-d7ee07ca353a.png)

This action runs the [black formatter](https://github.com/psf/black) with reviewdog on pull requests to improve code review experience. It can be used to format your code and/or annotate possible changes that would be made during this formatting.
This action runs the [black formatter](https://github.com/psf/black) with reviewdog on pull requests to improve code review experience.

## Inputs
## Quick start

```yaml
inputs:
workdir:
description: "Working directory relative to the root directory. Defaults to '.'."
required: false
default: "."
format:
description: |
If true, black format files and commit are creatable (use other Action).
Defaults to 'false'.
required: false
default: "false"
fail_on_error:
description: |
Exit code when black formatting errors are found [true, false]. Defaults to 'false'.
required: false
default: "false"
black_flags:
description: "Additional black flags."
required: false
default: ""
# Reviewdog related inputs
annotate:
description: "Annotate black changes using reviewdog. Defaults to 'true'."
required: false
default: "true"
github_token:
description: "The automatically created secret github action token."
required: true
default: ${{ github.token }}
tool_name:
description: "Tool name to use for reviewdog reporter. Defaults to 'black-format'."
required: false
default: "black-format"
level:
description: "Report level for reviewdog [info, warning, error]. Defaults to 'error'."
required: false
default: "error"
reporter:
description: |
Reporter of reviewdog command [github-pr-check, github-pr-review, github-check].
Defaults to 'github-pr-check'.
required: false
default: "github-pr-check"
filter_mode:
description: |
Filtering mode for the reviewdog command [added, diff_context, file, nofilter].
Default is added.
required: false
default: "added"
reviewdog_flags:
description: "Additional reviewdog flags."
required: false
default: ""
```

## Outputs

```yml
outputs:
is_formatted:
description: "Whether the files were formatted using the black formatter."
```

## Basic usage

In it's simplest form this action can be used to annotate the changes the black formatter would make if it was run on the code.
In it's simplest form this action can be used to annotate the changes the [black](https://github.com/psf/black) formatter would make if it was run on the code.

```yaml
name: reviewdog
Expand All @@ -100,64 +34,48 @@ jobs:
level: warning
```

## Advanced use cases
## Inputs

This action can be combined with [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) or [stefanzweifel/git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action) to also apply the annotated changes to the repository.
### `github_token`

### Commit changes
**Required**. The [GITHUB_TOKEN](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow). Must be in form of `github_token: ${{ secrets.github_token }}`. Defaults to `${{ github.token }}`.

```yaml
name: reviewdog
on: [pull_request]
jobs:
name: runner / black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Check files using black formatter
uses: reviewdog/action-black@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-check
level: error
fail_on_error: true
format: true
- name: Commit black formatting results
if: failure()
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: ":art: Format Python code with psf/black push"
```
### `workdir`

### Create pull request
**Optional**. The directory to run remark-lint in. Defaults to `.`.

```yaml
name: reviewdog
on: [pull_request]
jobs:
name: runner / black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check files using black formatter
uses: reviewdog/action-black@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-check
level: error
fail_on_error: true
format: true
- name: Create Pull Request
if: failure()
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Format Python code with psf/black push"
commit-message: ":art: Format Python code with psf/black"
body: |
There appear to be some python formatting errors in ${{ github.sha }}. This pull request
uses the [psf/black](https://github.com/psf/black) formatter to fix these issues.
branch: actions/black
```
#### `black_flags`

**Optional**. Additional black flags. Defaults to `""`.

| :warning: | Because this action uses the black output to create the annotations, it does not work with the black `--quiet` flag.|
|-----------|---------------------------------------------------------------------------------------------------------------------|

#### `tool_name`

**Optional**. Tool name to use for reviewdog reporter. Defaults to `remark-lint`.

### `level`

**Optional**. Report level for reviewdog `[info, warning, error]`. It's same as `-level` flag of reviewdog. Defaults to `error`.

### `reporter`

**Optional**. Reporter of reviewdog command `[github-pr-check, github-pr-review, github-check]`.
Default is github-pr-check. github-pr-review can use Markdown and add a link to rule page in reviewdog reports.

### `filter_mode`

**Optional**. Filtering mode for the reviewdog command `[added, diff_context, file, nofilter]`. Defaults to `added`.

#### `fail_on_error`

**Optional**. Exit code for when reviewdog when errors are found `[true, false]`. Defaults to `false`.

### `reviewdog_flags`

**Optional**. Additional reviewdog flags. Defaults to `""`.

## Format your code

This action is meant to annotate any possible changes that would need to be made to make your code adhere to the [black formatting guidelines](github.com/psf/black). It does not apply these changes to your codebase. If you also want to apply the changes to your repository, you can use the [reviewdog/action-suggester](https://github.com/reviewdog/action-suggester). You can find examples of how this is done can be found in [rickstaa/action-black](https://github.com/rickstaa/action-black/)
38 changes: 10 additions & 28 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,42 @@ description: "🐶 Run black formatter with reviewdog on pull requests to improv
author: "Rick Staa"
inputs:
workdir:
description: "Working directory relative to the root directory. Defaults to '.'."
description: "Working directory relative to the root directory."
required: false
default: "."
format:
description: |
If true, black format files and commit are creatable (use other Action).
Defaults to 'false'.
required: false
default: "false"
fail_on_error:
description: |
Exit code when black formatting errors are found [true, false]. Defaults to 'false'.
required: false
default: "false"
black_flags:
description: "Additional black flags."
required: false
default: ""
# Reviewdog related inputs
annotate:
description: "Annotate black changes using reviewdog. Defaults to 'true'."
required: false
default: "true"
github_token:
description: "The automatically created secret github action token."
description: "GITHUB_TOKEN."
required: true
default: ${{ github.token }}
tool_name:
description: "Tool name to use for reviewdog reporter. Defaults to 'black-format'."
description: "Tool name to use for reviewdog reporter."
required: false
default: "black-format"
level:
description: "Report level for reviewdog [info, warning, error]. Defaults to 'error'."
description: "Report level for reviewdog [info, warning, error]."
required: false
default: "error"
reporter:
description: |
Reporter of reviewdog command [github-pr-check, github-pr-review, github-check].
Defaults to 'github-pr-check'.
description: "Reporter of reviewdog command [github-pr-check, github-pr-review, github-check]."
required: false
default: "github-pr-check"
filter_mode:
description: |
Filtering mode for the reviewdog command [added, diff_context, file, nofilter].
Default is added.
description: "Filtering mode for the reviewdog command [added, diff_context, file, nofilter]."
required: false
default: "added"
fail_on_error:
description: "Exit code for reviewdog when errors are found [true, false]."
required: false
default: "false"
reviewdog_flags:
description: "Additional reviewdog flags."
required: false
default: ""
outputs:
is_formatted:
description: "Whether the files were formatted using the black formatter."
runs:
using: "docker"
image: "Dockerfile"
Expand Down
Loading