From 327bc716e1dc3374d33e1b3c0d88150f6f359117 Mon Sep 17 00:00:00 2001 From: Daniel D'Avella Date: Thu, 14 Mar 2024 11:43:41 -0400 Subject: [PATCH] Add docs for configuring github actions to format --- docs/configuring.md | 83 +++++++++++++++++++++++++++++++++++++++++++++ docs/faqs.md | 4 +++ 2 files changed, 87 insertions(+) diff --git a/docs/configuring.md b/docs/configuring.md index e7bf8ec..1d6cec7 100644 --- a/docs/configuring.md +++ b/docs/configuring.md @@ -66,3 +66,86 @@ jobs: ``` Please contact us at help@pixee.ai with any questions, or if you would like more options for automatic assignment. + +## Configuring Automatic Formatting + +Many projects enforce a consistent code style by using automatic code formatters. This section contains instructions for configuring GitHub Actions to automatically format PRs that are created by Pixeebot. + +### Python + +The most popular Python code formatter is [Black](https://black.readthedocs.io/en/stable/). To automatically format PRs created by Pixeebot using Black, add the following GitHub action workflow to your repository: + +```yaml +name: Format Pixeebot PRs + +on: + pull_request: + types: [opened, synchronize] + +jobs: + apply-black: + if: github.event.pull_request.user.login == 'pixeebot[bot]' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install black + run: pip install black + + - name: Apply black formatting + run: black . + + - name: Commit and push changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: ":art: Apply formatting" +``` + +This action can be added to your repository by creating a `.github/workflows/pixeebot-autoformat-black.yml` file with the above content. + +Note that it may be necessary to pin the version of Black to ensure that the formatting is consistent with your project's style. Depending on your project's configuration it may also be necessary to pass additional arguments to the `black` command to ensure that the correct settings are used. + +### Java + +For Java projects it is common to use a tool such as [Spotless](https://github.com/diffplug/spotless) to enforce code formatting. To automatically format PRs created by Pixeebot using Gradle to apply Spotless, add the following GitHub action workflow to your repository: + +```yaml +name: Format Pixeebot PRs + +on: + pull_request: + types: [opened, synchronize] + +jobs: + spotless-apply: + if: github.event.pull_request.user.login == 'pixeebot[bot]' + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + + - name: "Setup JDK" + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + + - name: 🐘Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: 🎨 Run spotless via Gradle + run: ./gradlew spotlessApply + + - name: Commit and push changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: ":art: Apply formatting" +``` diff --git a/docs/faqs.md b/docs/faqs.md index f4df150..bd14c96 100644 --- a/docs/faqs.md +++ b/docs/faqs.md @@ -27,3 +27,7 @@ Each party agrees to hold data and confidential information of the other party i ### Where can I learn more and discuss Pixeebot? Users can join the Pixee community [on Slack](https://join.slack.com/t/openpixee/shared_invite/zt-1pnk7jqdd-kfwilrfG7Ov4M8rorfOnUA). This channel can be used to engage with peers who are also interested in Pixee. Feel free to email us at help@pixee.ai with any questions or comments. + +### How can I Automatic Formatting to Pixeebot PRs? + +See our [Configuration](configuring.md#configuring-automatic-formatting) page for more information on how to enable automatic formatting of PRs generated by Pixeebot.