@@ -22,6 +22,16 @@ name: labeler
2222# Workflow triggers:
2323on :
2424 pull_request_target :
25+ types :
26+ - opened
27+ - synchronize
28+ - reopened
29+ - edited
30+ - review_requested
31+ - review_request_removed
32+ - ready_for_review
33+ - converted_to_draft
34+ - labeled
2535
2636# Workflow jobs:
2737jobs :
5363 with :
5464 configuration-path : .github/labeler.yml
5565 repo-token : ${{ secrets.CHATBOT_GITHUB_TOKEN }}
66+
67+ # Add "Needs Review" label when PR is opened and not a draft:
68+ - name : ' Add "Needs Review" label if PR is opened and not draft'
69+ if : ${{ github.event.action == 'opened' && github.event.pull_request.draft == false }}
70+ # Pin action to full length commit SHA
71+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
72+ with :
73+ github-token : ${{ secrets.CHATBOT_GITHUB_TOKEN }}
74+ script : |
75+ await github.rest.issues.addLabels({
76+ 'owner': context.repo.owner,
77+ 'repo': context.repo.repo,
78+ 'issue_number': context.payload.pull_request.number,
79+ 'labels': [ 'Needs Review' ]
80+ })
81+
82+ # Add "Needs Review" label when PR is marked ready for review or review is requested:
83+ - name : ' Add "Needs Review" label if PR is ready for review or review is requested'
84+ if : ${{ github.event.action == 'ready_for_review' || github.event.action == 'review_requested' }}
85+ # Pin action to full length commit SHA
86+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
87+ with :
88+ github-token : ${{ secrets.CHATBOT_GITHUB_TOKEN }}
89+ script : |
90+ await github.rest.issues.addLabels({
91+ 'owner': context.repo.owner,
92+ 'repo': context.repo.repo,
93+ 'issue_number': context.payload.pull_request.number,
94+ 'labels': [ 'Needs Review' ]
95+ })
96+
97+ # Remove "Needs Review" label when PR is converted to draft or closed:
98+ - name : ' Remove "Needs Review" label if PR is converted to draft or closed'
99+ if : ${{ github.event.action == 'converted_to_draft' || github.event.action == 'closed' }}
100+ # Pin action to full length commit SHA
101+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
102+ with :
103+ github-token : ${{ secrets.CHATBOT_GITHUB_TOKEN }}
104+ script : |
105+ try {
106+ await github.rest.issues.removeLabel({
107+ 'owner': context.repo.owner,
108+ 'repo': context.repo.repo,
109+ 'issue_number': context.payload.pull_request.number,
110+ 'name': 'Needs Review'
111+ })
112+ } catch ( error ) {
113+ console.log( 'Error removing label: %s', error.message );
114+ }
115+
116+ # Remove "Needs Review" and "Needs Changes" labels when "Ready To Merge" is assigned:
117+ - name : ' Remove "Needs Review" and "Needs Changes" labels when "Ready To Merge" is assigned'
118+ if : ${{ github.event.action == 'labeled' && github.event.label.name == 'Ready To Merge' }}
119+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
120+ with :
121+ github-token : ${{ secrets.CHATBOT_GITHUB_TOKEN }}
122+ script : |
123+ const labelsToRemove = [ 'Needs Review', 'Needs Changes' ];
124+ for ( const label of labelsToRemove ) {
125+ try {
126+ await github.rest.issues.removeLabel({
127+ 'owner': context.repo.owner,
128+ 'repo': context.repo.repo,
129+ 'issue_number': context.payload.pull_request.number,
130+ 'name': label
131+ })
132+ } catch ( error ) {
133+ console.log( 'Error removing label %s: %s', label, error.message );
134+ }
135+ }
0 commit comments