-
Notifications
You must be signed in to change notification settings - Fork 1.9k
51 lines (41 loc) · 1.72 KB
/
label-add-conflict-all-pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
name: Auto Label "stale" for All PRs
on:
push:
branches:
- develop
- '4.*'
jobs:
build:
name: Check Conflicts
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get PR List
id: PR-list
run: echo "pr_list=$(gh pr list -L 100 --json mergeable,url,labels,author)" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 'Add label "stale" and comment'
env:
PR_LIST: ${{ steps.PR-list.outputs.pr_list }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
IFS=$'\n' # Set Internal Field Separator to newline to handle array elements
# Iterate through the PRs in PR_LIST
for pr in $(echo "$PR_LIST" | jq -c '.[]'); do
mergeable=$(echo "$pr" | jq -r '.mergeable')
author=$(echo "$pr" | jq -r '.author.login')
labels=$(echo "$pr" | jq -c '.labels[].name' | tr -d '[]"')
url=$(echo "$pr" | jq -r '.url')
# CONFLICTING and no 'stale' label
if [ "$mergeable" == "CONFLICTING" ] && [[ ! "$labels" == *"stale"* ]]; then
# Add "stale" label
gh pr edit $url --add-label "stale"
# Add a comment
gh pr comment $url --body ":wave: Hi, @$author!<br><br>We detected conflicts in your PR against the base branch :speak_no_evil:<br>You may want to sync :arrows_counterclockwise: your branch with upstream!<br><br>Ref: [Syncing Your Branch](https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/workflow.md#updating-your-branch)"
fi
done