Files
prismlauncher-crack/.github/workflows/merge_blocking_pr.yml

81 lines
2.5 KiB
YAML

name: Merged Blocking Pull Request Automation
on:
pull_request:
types:
- closed
jobs:
update_blocked_status:
name: Update Blocked Status
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
permissions:
issues: write
pull-requests: write
statuses: write
checks: write
steps:
- name: Gather Dependent PRs
id: gather_deps
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
owner="${{ github.repository_owner }}"
owner_repo="${{ github.repository }}"
repo="${owner_repo#"${owner}/"}"
blocked_prs=$(
gh api graphql \
-f repo="$repo" \
-f owner="$owner" \
-f query='
query($repo: String!, $owner: String!, $endCursor: String) {
repository(name: $repo, owner: $owner) {
pullRequests(first: 100, after: $endCursor, states: [OPEN], labels: ["blocked"]) {
nodes {
number
bodyText
merged
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
' \
--paginate \
--slurp \
| jq --argjson pr "${{ github.event.pull_request.number }}" '
[.[].data.repository.pullRequests.nodes[]] | .[] | select(
.bodyText |
scan("(?:blocked (?:by|on)|stacked on):? #(?<num>[0-9]+)") |
map(tonumber) |
any(.[]; . == $pr)
)
'
)
echo "deps=$blocked_prs" >> "$GITHUB_OUTPUT"
echo "numdeps='$(jq -r '. | length' <<< "$blocked_prs")"
- name: Trigger Blocked PP Workflows for Dependants
if: fromJSON(steps.gather_deps.outputs.numdeps) > 0
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
while read -r pr ; do
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/actions/workflows/blocked_prs.yml/dispatches" \
-f "ref=${{ github.ref_name }}" \
-f "inputs[pr_id]=$pr"
done < <(jq -c '.[].number' <<< "${{steps.gather_deps.outputs.deps}}")