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
69 changes: 0 additions & 69 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 @@ -70,29 +48,6 @@ jobs:
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'
name: runner / black-format (github-pr-review)
Expand All @@ -114,28 +69,4 @@ jobs:
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
171 changes: 47 additions & 124 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,75 +9,9 @@

![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

```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
## Quick start

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.

Expand All @@ -100,64 +34,53 @@ 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**. Must be in form of `github_token: ${{ secrets.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
```
### `format`

**Optional**. If true, remark-lint format files and commit are creatable (use other Action). Defaults to `false`.

#### `fail_on_error`

**Optional**. Exit code for when remark-lint errors are found \[`true`, `false`]. Defaults to `false`.

#### `black_flags`

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

### `annotate`

**Optional**. Annotate remark-lint changes using reviewdog. Defaults to `true`.

#### `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"`.

### `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/)
13 changes: 0 additions & 13 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ inputs:
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'.
Expand All @@ -22,10 +16,6 @@ inputs:
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
Expand Down Expand Up @@ -54,9 +44,6 @@ inputs:
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