diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 41edaf59d5a..2a5392b2b68 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -15,3 +15,7 @@ Fixes # - [ ] Add new public functions/methods/classes to `doc/api/index.rst`. - [ ] Write detailed docstrings for all functions/methods. - [ ] If adding new functionality, add an example to docstrings or tutorials. + +**Notes** + +- You can write `/format` in the first line of a comment to lint the code automatically diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml new file mode 100644 index 00000000000..c0a320ec204 --- /dev/null +++ b/.github/workflows/format-command.yml @@ -0,0 +1,47 @@ +name: format-command +on: + repository_dispatch: + types: [format-command] +jobs: + format: + runs-on: ubuntu-latest + steps: + # Generate token from GenericMappingTools bot + - uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + + # Checkout the pull request branch + - uses: actions/checkout@v2 + with: + token: ${{ steps.generate-token.outputs.token }} + repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} + ref: ${{ github.event.client_payload.pull_request.head.ref }} + + # Setup Python environment + - uses: actions/setup-python@v1 + + # Install formatting tools + - name: Install formatting tools + run: pip install black blackdoc flake8 + + # Run "make format" and commit the change to the PR branch + - name: Commit to the PR branch if any changes + run: | + make format + if [[ $(git ls-files -m) ]]; then + git config --global user.name 'actions-bot' + git config --global user.email '58130806+actions-bot@users.noreply.github.com' + git commit -am "[format-command] fixes" + git push + fi + + - name: Add reaction + uses: peter-evans/create-or-update-comment@v1 + with: + token: ${{ steps.generate-token.outputs.token }} + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} + comment-id: ${{ github.event.client_payload.github.payload.comment.id }} + reaction-type: hooray diff --git a/.github/workflows/slash-command-dispatch.yml b/.github/workflows/slash-command-dispatch.yml new file mode 100644 index 00000000000..85a489ac211 --- /dev/null +++ b/.github/workflows/slash-command-dispatch.yml @@ -0,0 +1,24 @@ +name: Slash Command Dispatch +on: + issue_comment: + types: [created] + # Add "edited" type for test purposes. Where possible, avoid using to prevent processing unnecessary events. + # types: [created, edited] +jobs: + slashCommandDispatch: + runs-on: ubuntu-latest + steps: + # Generate token from GenericMappingTools bot + - uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + + - name: Slash Command Dispatch + uses: peter-evans/slash-command-dispatch@v2 + with: + token: ${{ steps.generate-token.outputs.token }} + commands: | + format + issue-type: pull-request diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8c6ac9362f5..539ef51da3b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -255,9 +255,10 @@ Before committing, run it to automatically format your code: make format ``` -Don't worry if you forget to do it. -Our continuous integration systems will warn us and you can make a new commit with the -formatted code. +Don't worry if you forget to do it. Our continuous integration systems will +warn us and you can make a new commit with the formatted code. +Even better, you can just write `/format` in the first line of any comment in a +Pull Request to lint the code automatically. We also use [flake8](http://flake8.pycqa.org/en/latest/) and [pylint](https://www.pylint.org/) to check the quality of the code and quickly catch