Skip to content

Commit dbeaa21

Browse files
committed
style: update style & changelog
1 parent 6a55b3a commit dbeaa21

File tree

8 files changed

+158
-152
lines changed

8 files changed

+158
-152
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
🛠 refactor
88
-->
99

10+
## v3.4.0
11+
12+
`2023.02.06`
13+
14+
- 🚀 feat: support `toggle-labels`. [#132](https://github.com/actions-cool/issues-helper/pull/132) [@Wxh16144](https://github.com/Wxh16144)
15+
1016
## v3.3.3
1117

1218
`2022.11.13`

README.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ When the following list does not have the features you want, you can submit it i
255255
- [`lock-issues`](#lock-issues)
256256
- [`mark-assignees`](#mark-assignees)
257257
- [`mark-duplicate`](#mark-duplicate)
258-
- [`welcome`](#welcome)
259258
- [`toggle-labels`](#toggle-labels)
259+
- [`welcome`](#welcome)
260260

261261
## 🚀 Usage
262262

@@ -1110,77 +1110,77 @@ jobs:
11101110

11111111
⏫ [Back to list](#List)
11121112

1113-
#### `welcome`
1114-
1115-
When an issue is created, the user who created the issue for the first time is welcome.
1113+
#### `toggle-labels`
11161114

1117-
If the user is not creating for the first time, there is no operation.
1115+
When an issue is reopened, the set labels are removed if they already exist, otherwise they are added.
11181116

11191117
```yml
1120-
name: Issue Welcome
1118+
name: Toggle Labels
11211119
11221120
on:
11231121
issues:
1124-
types: [opened]
1122+
types: [reopened]
11251123
11261124
jobs:
1127-
issue-welcome:
1125+
toggle-labels:
11281126
runs-on: ubuntu-latest
11291127
steps:
1130-
- name: welcome
1128+
- name: Toggle labels
11311129
uses: actions-cool/issues-helper@v3
11321130
with:
1133-
actions: 'welcome'
1131+
actions: 'toggle-labels'
11341132
token: ${{ secrets.GITHUB_TOKEN }}
1135-
body: hi @${{ github.event.issue.user.login }}, welcome!
1136-
labels: 'welcome1, welcome2'
1137-
assignees: 'xx1'
1138-
issue-emoji: '+1, -1, eyes'
1133+
issue-number: ${{ github.event.issue.number }}
1134+
labels: 'unread,outdated'
11391135
```
11401136

11411137
| Param | Desc | Type | Required |
11421138
| -- | -- | -- | -- |
11431139
| actions | Action type | string | ✔ |
11441140
| token | [Token explain](#token) | string | ✖ |
1145-
| body | Comment on the welcome content, no comment if you leave it blank | string | ✖ |
1146-
| labels | Add labels to this issue | string | ✖ |
1147-
| assignees | Add assignees to this issue | string | ✖ |
1148-
| issue-emoji | Add [reaction](#emoji-types) to this issue| string | ✖ |
1149-
1150-
- If these 4 options are not filled, no operation
1141+
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | ✖ |
1142+
| labels | The toggle labels. Delete if the label already exists, add if it does not exist | string | ✖ |
11511143

11521144
⏫ [Back to list](#List)
11531145

1154-
#### `toggle-labels`
1146+
#### `welcome`
11551147

1156-
When an issue is reopened, the set labels are removed if they already exist, otherwise they are added.
1148+
When an issue is created, the user who created the issue for the first time is welcome.
1149+
1150+
If the user is not creating for the first time, there is no operation.
11571151

11581152
```yml
1159-
name: Toggle Labels
1153+
name: Issue Welcome
11601154
11611155
on:
11621156
issues:
1163-
types: [reopened]
1157+
types: [opened]
11641158
11651159
jobs:
1166-
toggle-labels:
1160+
issue-welcome:
11671161
runs-on: ubuntu-latest
11681162
steps:
1169-
- name: Toggle labels
1163+
- name: welcome
11701164
uses: actions-cool/issues-helper@v3
11711165
with:
1172-
actions: 'toggle-labels'
1166+
actions: 'welcome'
11731167
token: ${{ secrets.GITHUB_TOKEN }}
1174-
issue-number: ${{ github.event.issue.number }}
1175-
labels: 'unread,outdated'
1168+
body: hi @${{ github.event.issue.user.login }}, welcome!
1169+
labels: 'welcome1, welcome2'
1170+
assignees: 'xx1'
1171+
issue-emoji: '+1, -1, eyes'
11761172
```
11771173

11781174
| Param | Desc | Type | Required |
11791175
| -- | -- | -- | -- |
11801176
| actions | Action type | string | ✔ |
11811177
| token | [Token explain](#token) | string | ✖ |
1182-
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | ✖ |
1183-
| labels | The toggle labels. Delete if the label already exists, add if it does not exist | string | ✖ |
1178+
| body | Comment on the welcome content, no comment if you leave it blank | string | ✖ |
1179+
| labels | Add labels to this issue | string | ✖ |
1180+
| assignees | Add assignees to this issue | string | ✖ |
1181+
| issue-emoji | Add [reaction](#emoji-types) to this issue| string | ✖ |
1182+
1183+
- If these 4 options are not filled, no operation
11841184

11851185
⏫ [Back to list](#List)
11861186

README.zh-CN.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@
259259
- [`lock-issues`](#lock-issues)
260260
- [`mark-assignees`](#mark-assignees)
261261
- [`mark-duplicate`](#mark-duplicate)
262-
- [`welcome`](#welcome)
263262
- [`toggle-labels`](#toggle-labels)
263+
- [`welcome`](#welcome)
264264

265265
## 🚀 使 用
266266

@@ -1109,76 +1109,76 @@ jobs:
11091109

11101110
⏫ [返回列表](#列-表)
11111111

1112-
#### `welcome`
1112+
#### `toggle-labels`
11131113

1114-
当一个 issue 新建时,对首次新建 issue 的用户进行欢迎。若用户非首次新建,则无操作
1114+
当一个 issue 被重新打开,判断设置的 labels 如果已经存在则进行删除,否则进行添加
11151115

11161116
```yml
1117-
name: Issue Welcome
1117+
name: Toggle Labels
11181118
11191119
on:
11201120
issues:
1121-
types: [opened]
1121+
types: [reopened]
11221122
11231123
jobs:
1124-
issue-welcome:
1124+
toggle-labels:
11251125
runs-on: ubuntu-latest
11261126
steps:
1127-
- name: welcome
1127+
- name: Toggle labels
11281128
uses: actions-cool/issues-helper@v3
11291129
with:
1130-
actions: 'welcome'
1130+
actions: 'toggle-labels'
11311131
token: ${{ secrets.GITHUB_TOKEN }}
1132-
body: hi @${{ github.event.issue.user.login }}, welcome!
1133-
labels: 'welcome1, welcome2'
1134-
assignees: 'xx1'
1135-
issue-emoji: '+1, -1, eyes'
1132+
issue-number: ${{ github.event.issue.number }}
1133+
labels: 'unread,outdated'
11361134
```
11371135

11381136
| 参数 | 描述 | 类型 | 必填 |
11391137
| -- | -- | -- | -- |
11401138
| actions | 操作类型 | string | ✔ |
11411139
| token | [token 说明](#token) | string | ✖ |
1142-
| body | 评论欢迎的内容,不填则不评论 | string | ✖ |
1143-
| emoji | 为该评论的增加 [emoji](#emoji-types) | string | ✖ |
1144-
| labels | 为该 issue 增加 labels | string | ✖ |
1145-
| assignees | 为该 issue 增加 assignees | string | ✖ |
1146-
| issue-emoji | 为该 issue 增加 [emoji](#emoji-types) | string | ✖ |
1147-
1148-
- 若这 4 个可选项都不填,则无操作
1140+
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | ✖ |
1141+
| labels | 切换 labels。如果 label 已存在则删除,不存在则添加 | string | ✖ |
11491142

11501143
⏫ [返回列表](#列-表)
11511144

1152-
#### `toggle-labels`
1145+
#### `welcome`
11531146

1154-
当一个 issue 被重新打开,判断设置的 labels 如果已经存在则进行删除,否则进行添加
1147+
当一个 issue 新建时,对首次新建 issue 的用户进行欢迎。若用户非首次新建,则无操作
11551148

11561149
```yml
1157-
name: Toggle Labels
1150+
name: Issue Welcome
11581151
11591152
on:
11601153
issues:
1161-
types: [reopened]
1154+
types: [opened]
11621155
11631156
jobs:
1164-
toggle-labels:
1157+
issue-welcome:
11651158
runs-on: ubuntu-latest
11661159
steps:
1167-
- name: Toggle labels
1160+
- name: welcome
11681161
uses: actions-cool/issues-helper@v3
11691162
with:
1170-
actions: 'toggle-labels'
1163+
actions: 'welcome'
11711164
token: ${{ secrets.GITHUB_TOKEN }}
1172-
issue-number: ${{ github.event.issue.number }}
1173-
labels: 'unread,outdated'
1165+
body: hi @${{ github.event.issue.user.login }}, welcome!
1166+
labels: 'welcome1, welcome2'
1167+
assignees: 'xx1'
1168+
issue-emoji: '+1, -1, eyes'
11741169
```
11751170

11761171
| 参数 | 描述 | 类型 | 必填 |
11771172
| -- | -- | -- | -- |
11781173
| actions | 操作类型 | string | ✔ |
11791174
| token | [token 说明](#token) | string | ✖ |
1180-
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | ✖ |
1181-
| labels | 切换 labels。如果 label 已存在则删除,不存在则添加 | string | ✖ |
1175+
| body | 评论欢迎的内容,不填则不评论 | string | ✖ |
1176+
| emoji | 为该评论的增加 [emoji](#emoji-types) | string | ✖ |
1177+
| labels | 为该 issue 增加 labels | string | ✖ |
1178+
| assignees | 为该 issue 增加 assignees | string | ✖ |
1179+
| issue-emoji | 为该 issue 增加 [emoji](#emoji-types) | string | ✖ |
1180+
1181+
- 若这 4 个可选项都不填,则无操作
11821182

11831183
⏫ [返回列表](#列-表)
11841184

src/helper/advanced.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,32 @@ export async function doMarkDuplicate(
362362
}
363363
}
364364

365+
export async function doToggleLabels(labels: string[] = []) {
366+
const issue = await ICE.getIssue();
367+
const baseLabels: string[] = issue.labels.map(({ name }: any) => name);
368+
369+
const addLabels = [];
370+
const removeLabels = [];
371+
372+
for (const label of labels) {
373+
if (baseLabels.includes(label)) {
374+
removeLabels.push(label);
375+
} else {
376+
addLabels.push(label);
377+
}
378+
}
379+
380+
if (removeLabels.length) {
381+
await doRemoveLabels(removeLabels);
382+
}
383+
384+
if (addLabels.length) {
385+
await doAddLabels(addLabels);
386+
}
387+
388+
core.info(`[doToggleLabels] Done!`);
389+
}
390+
365391
export async function doWelcome(
366392
auth: string,
367393
issueNumber: number,
@@ -393,29 +419,3 @@ export async function doWelcome(
393419
core.info(`[doWelcome] ${auth} is not first time!`);
394420
}
395421
}
396-
397-
export async function doToggleLabels(labels: string[] = []) {
398-
const issue = await ICE.getIssue();
399-
const baseLabels: string[] = issue.labels.map(({ name }: any) => name);
400-
401-
const addLabels = [];
402-
const removeLabels = [];
403-
404-
for (const label of labels) {
405-
if (baseLabels.includes(label)) {
406-
removeLabels.push(label);
407-
} else {
408-
addLabels.push(label);
409-
}
410-
}
411-
412-
if (removeLabels.length) {
413-
await doRemoveLabels(removeLabels);
414-
}
415-
416-
if (addLabels.length) {
417-
await doAddLabels(addLabels);
418-
}
419-
420-
core.info(`[doToggleLabels] Done!`);
421-
}

src/helper/helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ export class IssueHelperEngine implements IIssueHelperEngine {
252252
await doMarkDuplicate(ctx.payload.comment as TCommentInfo, closeReason, labels, emoji);
253253
break;
254254
}
255+
case 'toggle-labels': {
256+
await doToggleLabels(labels);
257+
break;
258+
}
255259
case 'welcome': {
256260
if (ctx.eventName === 'issues' && ctx.payload.action === 'opened') {
257261
await doWelcome(ctx.actor, issueNumber, body, labels, assignees, emoji);
@@ -260,10 +264,6 @@ export class IssueHelperEngine implements IIssueHelperEngine {
260264
}
261265
break;
262266
}
263-
case 'toggle-labels': {
264-
await doToggleLabels(labels);
265-
break;
266-
}
267267
// -[ Advanced End ]->
268268
default: {
269269
core.warning(`The ${action} is not allowed.`);

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ export type TAction =
5656
| 'lock-issues'
5757
| 'mark-assignees'
5858
| 'mark-duplicate'
59-
| 'welcome'
60-
| 'toggle-labels';
59+
| 'toggle-labels'
60+
| 'welcome';
6161
//// [ Advanced End ]

0 commit comments

Comments
 (0)