Files
element-plus/.github/workflows/pr-conflict.yml
2025-11-21 16:07:51 +08:00

78 lines
2.5 KiB
YAML

name: Comment on PR with conflict Label
# Note that this `pull_request_target` is vulnerable, it grants write access to a fork repo
# DO NOT ADD ANY CHECKOUT/CACHING in this workflow
on:
pull_request_target:
types: [labeled, synchronize]
permissions:
pull-requests: write
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: Check for specific label
if: |
contains(github.event.pull_request.labels.*.name, 'conflict pending') &&
github.repository_owner == 'element-plus'
uses: actions-cool/maintain-one-comment@v3.2.0
with:
body: |
@${{ github.event.pull_request.user.login }} This PR has conflicts, please resolve them.
<!-- ELEMENT_PLUS_CONFLICT_COMMENT -->
body-include: '<!-- ELEMENT_PLUS_CONFLICT_COMMENT -->'
number: ${{ github.event.pull_request.number }}
remove-label:
runs-on: ubuntu-latest
steps:
- name: Poll mergeable until ready
id: poll
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
# Polling for 15 seconds
run: |
echo "Polling mergeable for PR #$PR_NUMBER ..."
for i in {1..3}; do
resp=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '{mergeable}')
mergeable=$(echo "$resp" | jq -r '.mergeable')
echo "Check $i: mergeable=$mergeable"
# mergeable is ready
if [ "$mergeable" != "null" ]; then
echo "mergeable=$mergeable" >> $GITHUB_OUTPUT
exit 0
fi
sleep 5
done
echo "mergeable=null" >> $GITHUB_OUTPUT
echo "Timeout: mergeable never resolved."
exit 0
# Log final values (debug)
- name: Log mergeable results
run: |
echo "mergeable: ${{ steps.poll.outputs.mergeable }}"
echo "pull_request.mergeable: ${{ github.event.pull_request.mergeable }}"
echo "pull_request.mergeable_state: ${{ github.event.pull_request.mergeable_state }}"
- name: Remove conflict pending label
if: |
github.repository_owner == 'element-plus' &&
contains(github.event.pull_request.labels.*.name, 'conflict pending') &&
steps.poll.outputs.mergeable == 'true'
uses: actions-cool/issues-helper@v3
with:
actions: 'remove-labels'
labels: 'conflict pending'
issue-number: ${{ github.event.pull_request.number }}