Skip to content

Commit 3714857

Browse files
committed
Provide a way for users to add/remove labels
1 parent 74e95ec commit 3714857

File tree

2 files changed

+178
-0
lines changed

2 files changed

+178
-0
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
name: PR Label Automation
2+
on:
3+
issue_comment:
4+
types: [created]
5+
6+
permissions:
7+
contents: read
8+
issues: write
9+
pull-requests: write
10+
11+
jobs:
12+
auto-label:
13+
if: github.event.issue.pull_request
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check for breaking change command
17+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
18+
with:
19+
script: |
20+
const comment = context.payload.comment.body.trim();
21+
if (comment !== '/breaking-change') {
22+
return;
23+
}
24+
25+
await github.rest.issues.addLabels({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
issue_number: context.issue.number,
29+
labels: ['breaking change']
30+
});
31+
32+
await github.rest.reactions.createForIssueComment({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
comment_id: context.payload.comment.id,
36+
content: '+1'
37+
});
38+
39+
await github.rest.issues.createComment({
40+
owner: context.repo.owner,
41+
repo: context.repo.repo,
42+
issue_number: context.issue.number,
43+
body: '✅ Added `breaking change` label to this PR.'
44+
});
45+
46+
- name: Check for deprecation command
47+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
48+
with:
49+
script: |
50+
const comment = context.payload.comment.body.trim();
51+
if (comment !== '/deprecation') {
52+
return;
53+
}
54+
55+
await github.rest.issues.addLabels({
56+
owner: context.repo.owner,
57+
repo: context.repo.repo,
58+
issue_number: context.issue.number,
59+
labels: ['deprecation']
60+
});
61+
62+
await github.rest.reactions.createForIssueComment({
63+
owner: context.repo.owner,
64+
repo: context.repo.repo,
65+
comment_id: context.payload.comment.id,
66+
content: '+1'
67+
});
68+
69+
await github.rest.issues.createComment({
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
issue_number: context.issue.number,
73+
body: '✅ Added `deprecation` label to this PR.'
74+
});
75+
76+
- name: Check for remove breaking change command
77+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
78+
with:
79+
script: |
80+
const comment = context.payload.comment.body.trim();
81+
if (comment !== '/remove-breaking-change') {
82+
return;
83+
}
84+
85+
try {
86+
await github.rest.issues.removeLabel({
87+
owner: context.repo.owner,
88+
repo: context.repo.repo,
89+
issue_number: context.issue.number,
90+
name: 'breaking change'
91+
});
92+
93+
await github.rest.reactions.createForIssueComment({
94+
owner: context.repo.owner,
95+
repo: context.repo.repo,
96+
comment_id: context.payload.comment.id,
97+
content: '+1'
98+
});
99+
100+
await github.rest.issues.createComment({
101+
owner: context.repo.owner,
102+
repo: context.repo.repo,
103+
issue_number: context.issue.number,
104+
body: '✅ Removed `breaking change` label from this PR.'
105+
});
106+
} catch (error) {
107+
if (error.status === 404) {
108+
await github.rest.reactions.createForIssueComment({
109+
owner: context.repo.owner,
110+
repo: context.repo.repo,
111+
comment_id: context.payload.comment.id,
112+
content: 'confused'
113+
});
114+
115+
await github.rest.issues.createComment({
116+
owner: context.repo.owner,
117+
repo: context.repo.repo,
118+
issue_number: context.issue.number,
119+
body: '⚠️ The `breaking change` label was not found on this PR.'
120+
});
121+
} else {
122+
throw error;
123+
}
124+
}
125+
126+
- name: Check for remove deprecation command
127+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
128+
with:
129+
script: |
130+
const comment = context.payload.comment.body.trim();
131+
if (comment !== '/remove-deprecation') {
132+
return;
133+
}
134+
135+
try {
136+
await github.rest.issues.removeLabel({
137+
owner: context.repo.owner,
138+
repo: context.repo.repo,
139+
issue_number: context.issue.number,
140+
name: 'deprecation'
141+
});
142+
143+
await github.rest.reactions.createForIssueComment({
144+
owner: context.repo.owner,
145+
repo: context.repo.repo,
146+
comment_id: context.payload.comment.id,
147+
content: '+1'
148+
});
149+
150+
await github.rest.issues.createComment({
151+
owner: context.repo.owner,
152+
repo: context.repo.repo,
153+
issue_number: context.issue.number,
154+
body: '✅ Removed `deprecation` label from this PR.'
155+
});
156+
} catch (error) {
157+
if (error.status === 404) {
158+
await github.rest.reactions.createForIssueComment({
159+
owner: context.repo.owner,
160+
repo: context.repo.repo,
161+
comment_id: context.payload.comment.id,
162+
content: 'confused'
163+
});
164+
165+
await github.rest.issues.createComment({
166+
owner: context.repo.owner,
167+
repo: context.repo.repo,
168+
issue_number: context.issue.number,
169+
body: '⚠️ The `deprecation` label was not found on this PR.'
170+
});
171+
} else {
172+
throw error;
173+
}
174+
}

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and discuss your ideas or propose the changes you wish to make.
1212
When your PR introduces a breaking change:
1313

1414
* Add the `breaking change` label to your PR
15+
- If you can't add labels directly, post a comment containing only `/breaking-change` and the label will be added automatically
16+
- To remove the label, post a comment containing only `/remove-breaking-change`
1517
* Provide migration notes in the PR description:
1618
- What is changing and why
1719
- How users should update their code/configuration
@@ -29,6 +31,8 @@ When your PR introduces a breaking change:
2931
When your PR deprecates functionality:
3032

3133
* Add the `deprecation` label to your PR
34+
- If you can't add labels directly, post a comment containing only `/deprecation` and the label will be added automatically
35+
- To remove the label, post a comment containing only `/remove-deprecation`
3236
* Provide deprecation details in the PR description:
3337
- What is being deprecated and why
3438
- What should be used instead (if applicable)

0 commit comments

Comments
 (0)