-
Notifications
You must be signed in to change notification settings - Fork 2
111 lines (103 loc) · 3.8 KB
/
pr-labels.yml
File metadata and controls
111 lines (103 loc) · 3.8 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# PR Labeling Workflow
#
# Purpose: Automatically applies and removes labels on pull requests based on their status
# to improve visibility and workflow management.
#
# Triggers:
# - Pull request converted to draft
# - Pull request marked as ready for review
# - Pull request opened
# - Pull request reopened
# - Pull request closed
#
# How it works:
# - Uses GitHub CLI to modify PR labels based on the event action.
# - Continues execution even if label operations fail (uses `|| true`).
#
# Permissions:
# - pull-requests: write (required to add/remove labels)
name: Label PR
on:
pull_request:
types:
- converted_to_draft
- ready_for_review
- opened
- reopened
- closed
permissions:
pull-requests: write
env:
DRAFT_LABEL: "draft"
READY_LABEL: "ready for review"
jobs:
pr-in-draft-label:
if: github.event.action == 'converted_to_draft'
runs-on: ubuntu-latest
steps:
- name: Add/Remove PR labels based on event type
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
EVENT_ACTION: ${{ github.event.action }}
ADD_LABEL: ${{ env.DRAFT_LABEL }}
REMOVE_LABEL: ${{ env.READY_LABEL }}
run: &update_run |
gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "$ADD_LABEL" || true
gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$REMOVE_LABEL" || true
echo "Labels updated based on event action: $EVENT_ACTION for PR #$PR_NUMBER" >> "$GITHUB_STEP_SUMMARY"
pr-ready-review-label:
if: github.event.action == 'ready_for_review'
runs-on: ubuntu-latest
steps:
- name: Add/Remove PR labels based on event type
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
EVENT_ACTION: ${{ github.event.action }}
ADD_LABEL: ${{ env.READY_LABEL }}
REMOVE_LABEL: ${{ env.DRAFT_LABEL }}
run: *update_run
open-pr-label:
if: github.event.action == 'opened' || github.event.action == 'reopened'
runs-on: ubuntu-latest
steps:
- name: Set labels based on draft status
shell: bash
run: |
if [[ "${{ github.event.pull_request.draft }}" == "true" ]]; then
echo "ADD_LABEL_VALUE=${{ env.DRAFT_LABEL }}" >> $GITHUB_ENV
echo "REMOVE_LABEL_VALUE=${{ env.READY_LABEL }}" >> $GITHUB_ENV
else
echo "ADD_LABEL_VALUE=${{ env.READY_LABEL }}" >> $GITHUB_ENV
echo "REMOVE_LABEL_VALUE=${{ env.DRAFT_LABEL }}" >> $GITHUB_ENV
fi
- name: Add/Remove PR labels based on event type
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
EVENT_ACTION: ${{ github.event.action }}
ADD_LABEL: ${{ env.ADD_LABEL_VALUE }}
REMOVE_LABEL: ${{ env.REMOVE_LABEL_VALUE }}
run: *update_run
close-remove-labels:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Add/Remove PR labels based on event type
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
EVENT_ACTION: ${{ github.event.action }}
run: |
gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "${{ env.DRAFT_LABEL }}" || true
gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "${{ env.READY_LABEL }}" || true
echo "Removed labels based on event action: $EVENT_ACTION for PR #$PR_NUMBER" >> "$GITHUB_STEP_SUMMARY"