GitHub 操作,绕过分支保护时发送通知

问题描述 投票:0回答:0

我正在尝试设置一个 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 的相关提交时,我看到了

commit with failed checks

我期待

"state"
"failure"
https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28

github github-actions push github-api pull-request
© www.soinside.com 2019 - 2024. All rights reserved.