80 lines
2.6 KiB
YAML
80 lines
2.6 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=$(echo "${{ github.repository }}" | cut -d '/' -f 1)
|
|
repo=$(echo "${{ github.repository }}" | cut -d '/' -f 2)
|
|
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 -c --argjson pr "${{ github.event.pull_request.number }}" '
|
|
reduce ( .[].data.repository.pullRequests.nodes[] | select(
|
|
.bodyText |
|
|
scan("(?:blocked (?:by|on)|stacked on):? #([0-9]+)") |
|
|
map(tonumber) |
|
|
any(.[]; . == $pr)
|
|
)) as $i ([]; . + [$i])
|
|
'
|
|
)
|
|
echo "deps=$blocked_prs" >> "$GITHUB_OUTPUT"
|
|
echo "numdeps=$(jq -r '. | length' <<< "$blocked_prs")" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Trigger Blocked PP Workflows for Dependants
|
|
if: fromJSON(steps.gather_deps.outputs.numdeps) > 0
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
DEPS: ${{ steps.gather_deps.outputs.deps }}
|
|
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' <<< "$DEPS")
|
|
|