GitHub操作,运行命令并在键入注释时添加提交



我的目标是在GitHub中键入/run-black作为拉请求的注释,然后GitHubActions将在拉请求的分支上运行black .并添加提交。

用例是,有时临时贡献者会向我的库发出一个小的拉取请求(例如修复拼写错误(,我希望能够在合并之前只写一个像/run-black这样的注释,让black格式化程序在他们的文件上运行。

使用Slash Command Dispatch操作。将名称为PATrepo作用域PAT添加到机密中,并使用以下定义创建两个工作流。

name: Slash Command Dispatch
on:
issue_comment:
types: [created]
jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v2
with:
token: ${{ secrets.PAT }}
issue-type: pull-request
commands: |
run-black
on:
repository_dispatch:
types: [run-black-command]
jobs:
runBlack:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
repository: ${{github.event.client_payload.pull_request.head.repo.full_name}}
ref: ${{github.event.client_payload.pull_request.head.ref}}
token: ${{ secrets.PAT }}
- name: Slash Command Dispatch
run: black .
- run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "Run black" -a
git push

最新更新