Skip to content

Commit d8ea2aa

Browse files
authored
Merge pull request #24 from datamweb/add-conflict
feat: add auto Label stale for All PRs
2 parents 8c449c8 + 00e368b commit d8ea2aa

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Auto Label "stale" for All PRs
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
9+
cancel-in-progress: true
10+
11+
permissions:
12+
contents: read
13+
pull-requests: write
14+
15+
jobs:
16+
build:
17+
name: Check Conflicts
18+
runs-on: ubuntu-22.04
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Get PR List
24+
id: PR-list
25+
run: echo "pr_list=$(gh pr list -L 100 --json mergeable,url,labels,author)" >> $GITHUB_OUTPUT
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: 'Add label "stale" and comment'
30+
env:
31+
PR_LIST: ${{ steps.PR-list.outputs.pr_list }}
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
run: |
34+
35+
IFS=$'\n' # Set Internal Field Separator to newline to handle array elements
36+
37+
# Iterate through the PRs in PR_LIST
38+
for pr in $(echo "$PR_LIST" | jq -c '.[]'); do
39+
mergeable=$(echo "$pr" | jq -r '.mergeable')
40+
author=$(echo "$pr" | jq -r '.author.login')
41+
labels=$(echo "$pr" | jq -c '.labels[].name' | tr -d '[]"')
42+
url=$(echo "$pr" | jq -r '.url')
43+
44+
# CONFLICTING and no 'stale' label
45+
if [ "$mergeable" == "CONFLICTING" ] && [[ ! "$labels" == *"stale"* ]]; then
46+
# Add "stale" label
47+
gh pr edit $url --add-label "stale"
48+
49+
# Add a comment
50+
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)"
51+
fi
52+
done

0 commit comments

Comments
 (0)