-
Notifications
You must be signed in to change notification settings - Fork 1.9k
54 lines (44 loc) · 1.78 KB
/
label-add-conflict.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
52
53
54
name: Auto Add Label "stale" & Comment Conflicts
on:
push:
branches:
- develop
- '4.*'
pull_request:
branches:
- develop
- '4.*'
jobs:
auto-label-comment-conflict:
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#pushing-your-branch)"
fi
done