Skip to content

Commit 5712e6c

Browse files
authored
Merge pull request #7957 from totoprayogo1916/conflicting
Renew: add or remove 'stale' label
2 parents 0d8064f + 34f1bfd commit 5712e6c

File tree

3 files changed

+93
-33
lines changed

3 files changed

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

.github/workflows/label-conflict.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Auto Remove "stale" label
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
- '4.*'
8+
9+
jobs:
10+
check-conflict:
11+
runs-on: ubuntu-22.04
12+
permissions:
13+
contents: read
14+
pull-requests: write
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Get PR Detail
21+
id: PR-detail
22+
run: echo "detail=$(gh pr view $PR_URL --json mergeable,url,labels,author)" >> $GITHUB_OUTPUT
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
PR_URL: ${{ github.event.pull_request.html_url }}
26+
27+
- name: 'Remove label "stale"'
28+
env:
29+
PR_DETAIL: ${{ steps.PR-detail.outputs.detail }}
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
PR_URL: ${{ github.event.pull_request.html_url }}
32+
run: |
33+
34+
# MERGEABLE with 'stale' label
35+
if [ "$(echo $PR_DETAIL | jq -r '.mergeable')" == "MERGEABLE" ] && \
36+
[ "$(echo $PR_DETAIL | jq -r '.labels[] | select(.name == "stale")')" != "" ]; then
37+
# remove 'stale' label
38+
gh pr edit $PR_URL --remove-label "stale"
39+
fi

0 commit comments

Comments
 (0)