我正在尝试设置一个 GitHub 操作,该操作在合并未通过所有状态检查的拉取请求时触发
这就是我现在拥有的
name: Alert Merged Failed Checks
on:
push:
branches:
- main
- develop
jobs:
alert-if-merged-failed-checks:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
# Get the commit that checks were run on (non-merge commit)
- name: Get commit
id: get_commit
run: |
commit_hash=$(git log -n 1 ${{ github.event.after }}^2 --format='%H')
echo "commit_hash=$commit_hash" >> $GITHUB_OUTPUT
echo "commit_hash=$commit_hash"
# Get the status of the commit
- name: GitHub API Request
uses: octokit/[email protected]
id: get_check_status
with:
route: GET /repos/{owner}/{repo}/commits/{ref}/status
owner: ***
repo: ***
ref: ${{ steps.get_commit.outputs.commit_hash }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: "echo check status: ${{ steps.get_check_status.outputs.data }}"
- run: "echo help"
但是 GitHub API 请求的结果是
{
"state": "pending",
"statuses": [],
"total_count": 0,
...
}
当我在 GitHub 中查看具有相同 SHA 的相关提交时,我看到了
我期待
"state"
是"failure"
每
https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28