|
| 1 | +name: Auto Add/Remove "stale" label in single PR |
| 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)" >> $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 |
| 40 | +
|
| 41 | + - name: 'Check for conflicts and add label/comment' |
| 42 | + env: |
| 43 | + PR_DETAIL: ${{ steps.PR-detail.outputs.detail }} |
| 44 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 46 | + AUTHOR: ${{ github.event.pull_request.user.login }} |
| 47 | + run: | |
| 48 | +
|
| 49 | + # CONFLICTING with no "stale" label, |
| 50 | + if [ "$(echo $PR_DETAIL | jq -r '.mergeable')" == "CONFLICTING" ] && \ |
| 51 | + [ "$(echo $PR_DETAIL | jq -r '.labels[] | select(.name == "stale")')" != "" ]; then |
| 52 | + # add label |
| 53 | + gh pr edit $PR_URL --add-label "stale" |
| 54 | + # add comment |
| 55 | + gh pr comment $PR_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)" |
| 56 | + fi |
0 commit comments