|
1 | | -# poe-command-processor |
2 | | -A github action to execute poe commands and commit the result (if applicable) back to the repo. Designed with slash commands in mind. |
| 1 | +# Poe Command Processor |
| 2 | + |
| 3 | +A GitHub Action to execute [Poe the Poet](https://github.com/nat-n/poethepoet) commands in your repository, designed for use with slash commands in PR comments. This action can automatically commit changes back to the pull request branch or create a new PR if needed. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- ✅ Runs any Poe command in your repository. |
| 8 | +- ✅ Supports triggering via slash commands in PR and issue comments. |
| 9 | +- ✅ Can auto-commit changes to the PR branch, or open a new PR if no PR exists. |
| 10 | +- ✅ Posts status updates and results as comments on the originating comment. |
| 11 | +- ✅ Infers commands from comment bodies for seamless gitops/chatops workflows. |
| 12 | + |
| 13 | +## Inputs |
| 14 | + |
| 15 | +| Name | Description | Required | Default | |
| 16 | +|----------------|-----------------------------------------------------------------------------|----------|----------| |
| 17 | +| `command` | Poe command to run. If not provided, inferred from the body of the specified `comment-id`. | false | | |
| 18 | +| `pr` | Pull Request number. | false | | |
| 19 | +| `comment-id` | Comment ID (for reply chaining and command inference). | false | | |
| 20 | +| `github-token` | GitHub Token. Required for CI to run after commits are pushed. | false | | |
| 21 | +| `no-commit` | Disable auto-commit step. | false | `false` | |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +### Basic Example |
| 26 | + |
| 27 | +```yaml |
| 28 | +- name: Run Poe Command |
| 29 | + uses: ajsteers/poe-command-processor@v1 |
| 30 | + with: |
| 31 | + command: "lint" |
| 32 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + pr: ${{ github.event.pull_request.number }} |
| 34 | +``` |
| 35 | +
|
| 36 | +### Slash Command Example |
| 37 | +
|
| 38 | +This action is designed to work with slash commands in PR comments. If you omit the `command` input and provide a `comment-id`, the action will extract the command from the comment body. |
| 39 | + |
| 40 | +```yaml |
| 41 | +- name: Run Poe Command from Comment |
| 42 | + uses: ajsteers/poe-command-processor@v1 |
| 43 | + with: |
| 44 | + comment-id: ${{ github.event.comment.id }} |
| 45 | + pr: ${{ github.event.issue.number }} |
| 46 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 47 | +``` |
| 48 | + |
| 49 | +If the comment body is `/poe lint`, the action will run `poe lint`. |
| 50 | + |
| 51 | +### Auto-Commit and PR Creation |
| 52 | + |
| 53 | +- If changes are made and `no-commit` is not set to `true`, the action will auto-commit changes to the PR branch. |
| 54 | +- If no PR is provided, the action will create a new draft PR with the results. |
| 55 | +- Status and result comments are posted back to the PR or issue thread. |
| 56 | + |
| 57 | +## Requirements |
| 58 | + |
| 59 | +- Your repository must use [Poe the Poet](https://github.com/nat-n/poethepoet) and have a valid `pyproject.toml` with Poe tasks defined. |
| 60 | +- The action sets up Python 3.11 and installs dependencies using [uv](https://github.com/astral-sh/uv). |
| 61 | +- The `github-token` input is required for committing changes and posting comments. |
| 62 | + |
| 63 | +## Example Usage |
| 64 | + |
| 65 | +<details> |
| 66 | +<summary>Show/Hide Sample Poe Workflow File</summary> |
| 67 | + |
| 68 | +`.github/workflows/poe-command.yml` |
| 69 | + |
| 70 | +```yaml |
| 71 | +name: On-Demand Poe Task |
| 72 | +
|
| 73 | +on: |
| 74 | + workflow_dispatch: |
| 75 | + inputs: |
| 76 | + pr: |
| 77 | + description: "PR Number. If omitted, a new PR will be created." |
| 78 | + type: string |
| 79 | + required: false |
| 80 | + comment-id: |
| 81 | + description: "Comment ID (Optional)" |
| 82 | + type: string |
| 83 | + required: false |
| 84 | +
|
| 85 | +permissions: |
| 86 | + contents: write |
| 87 | + pull-requests: write |
| 88 | + issues: write |
| 89 | +
|
| 90 | +jobs: |
| 91 | + run-poe-command: |
| 92 | + env: |
| 93 | + GCP_GSM_CREDENTIALS: ${{ secrets.GCP_GSM_CREDENTIALS }} |
| 94 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 95 | + runs-on: ubuntu-latest |
| 96 | + steps: |
| 97 | + - name: Run Poe Slash Command Processor |
| 98 | + uses: aaronsteers/poe-command-processor@v1 |
| 99 | + with: |
| 100 | + pr: ${{ github.event.inputs.pr }} |
| 101 | + comment-id: ${{ github.event.inputs.comment-id }} |
| 102 | + github-token: ${{ secrets.GH_PAT_MAINTENANCE_OCTAVIA }} |
| 103 | +``` |
| 104 | + |
| 105 | +</details> |
| 106 | + |
| 107 | +<details> |
| 108 | +<summary>Show/Hide Sample Slash Command Dispatch File</summary> |
| 109 | + |
| 110 | +`.github/workflows/slash-command-dispatch.yml` |
| 111 | + |
| 112 | +```yaml |
| 113 | +name: Slash Command Dispatch |
| 114 | +
|
| 115 | +on: |
| 116 | + issue_comment: |
| 117 | + types: [created] |
| 118 | +
|
| 119 | +jobs: |
| 120 | + slashCommandDispatch: |
| 121 | + # Only allow slash commands on pull request (not on issues) |
| 122 | + runs-on: ubuntu-latest |
| 123 | + steps: |
| 124 | + - name: Slash Command Dispatch |
| 125 | + id: dispatch |
| 126 | + uses: peter-evans/slash-command-dispatch@v4 |
| 127 | + with: |
| 128 | + repository: ${{ github.repository }} |
| 129 | + token: ${{ github.token }} |
| 130 | + dispatch-type: workflow |
| 131 | + issue-type: both |
| 132 | + commands: | |
| 133 | + poe |
| 134 | + static-args: | |
| 135 | + comment-id=${{ github.event.comment.id }} |
| 136 | + pr=${{ github.event.issue.pull_request != null && github.event.issue.number || '' }} |
| 137 | + # Only run for users with 'write' permission on the main repository |
| 138 | + permission: write |
| 139 | +
|
| 140 | + - name: Edit comment with error message |
| 141 | + if: steps.dispatch.outputs.error-message |
| 142 | + uses: peter-evans/create-or-update-comment@v4 |
| 143 | + with: |
| 144 | + comment-id: ${{ github.event.comment.id }} |
| 145 | + body: | |
| 146 | + > Error: ${{ steps.dispatch.outputs.error-message }} |
| 147 | +
|
| 148 | +``` |
| 149 | + |
| 150 | +<details> |
| 151 | + |
| 152 | +## License |
| 153 | + |
| 154 | +This project is licensed under the terms of the [MIT License](LICENSE). |
0 commit comments