mirror of
https://gitea.com/Lydanne/issues-helper.git
synced 2025-10-13 23:33:51 +08:00
feat: add toggle-labels
action (#132)
* feat: add `toggle-labels` action
* docs: update docs
* chore: npm run package
* Revert "docs: update docs"
This reverts commit b08e8f300e
.
* docs: update docs
* Update README.zh-CN.md
Co-authored-by: xrkffgg <xrkffgg@vip.qq.com>
* Update README.md
Co-authored-by: xrkffgg <xrkffgg@vip.qq.com>
* Update README.zh-CN.md
Co-authored-by: xrkffgg <xrkffgg@vip.qq.com>
* Update README.md
* move
* update
* lint code
* build
use npm run all
* update
* build
use npm run all
* chore: order
* update docs
* format code
use npm run format
* build
use npm run all
---------
Co-authored-by: xrkffgg <xrkffgg@vip.qq.com>
This commit is contained in:
34
README.md
34
README.md
@@ -256,6 +256,7 @@ When the following list does not have the features you want, you can submit it i
|
|||||||
- [`mark-assignees`](#mark-assignees)
|
- [`mark-assignees`](#mark-assignees)
|
||||||
- [`mark-duplicate`](#mark-duplicate)
|
- [`mark-duplicate`](#mark-duplicate)
|
||||||
- [`welcome`](#welcome)
|
- [`welcome`](#welcome)
|
||||||
|
- [`toggle-labels`](#toggle-labels)
|
||||||
|
|
||||||
## 🚀 Usage
|
## 🚀 Usage
|
||||||
|
|
||||||
@@ -1150,6 +1151,39 @@ jobs:
|
|||||||
|
|
||||||
⏫ [Back to list](#List)
|
⏫ [Back to list](#List)
|
||||||
|
|
||||||
|
#### `toggle-labels`
|
||||||
|
|
||||||
|
When an issue is reopened, the set labels are removed if they already exist, otherwise they are added.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
name: Toggle Labels
|
||||||
|
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [reopened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
toggle-labels:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Toggle labels
|
||||||
|
uses: actions-cool/issues-helper@v3
|
||||||
|
with:
|
||||||
|
actions: 'toggle-labels'
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
issue-number: ${{ github.event.issue.number }}
|
||||||
|
labels: 'unread,outdated'
|
||||||
|
```
|
||||||
|
|
||||||
|
| Param | Desc | Type | Required |
|
||||||
|
| -- | -- | -- | -- |
|
||||||
|
| actions | Action type | string | ✔ |
|
||||||
|
| token | [Token explain](#token) | string | ✖ |
|
||||||
|
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | ✖ |
|
||||||
|
| labels | The toggle labels. Delete if the label already exists, add if it does not exist | string | ✖ |
|
||||||
|
|
||||||
|
⏫ [Back to list](#List)
|
||||||
|
|
||||||
## 🎁 Reference
|
## 🎁 Reference
|
||||||
|
|
||||||
### token
|
### token
|
||||||
|
@@ -260,6 +260,7 @@
|
|||||||
- [`mark-assignees`](#mark-assignees)
|
- [`mark-assignees`](#mark-assignees)
|
||||||
- [`mark-duplicate`](#mark-duplicate)
|
- [`mark-duplicate`](#mark-duplicate)
|
||||||
- [`welcome`](#welcome)
|
- [`welcome`](#welcome)
|
||||||
|
- [`toggle-labels`](#toggle-labels)
|
||||||
|
|
||||||
## 🚀 使 用
|
## 🚀 使 用
|
||||||
|
|
||||||
@@ -1148,6 +1149,39 @@ jobs:
|
|||||||
|
|
||||||
⏫ [返回列表](#列-表)
|
⏫ [返回列表](#列-表)
|
||||||
|
|
||||||
|
#### `toggle-labels`
|
||||||
|
|
||||||
|
当一个 issue 被重新打开,判断设置的 labels 如果已经存在则进行删除,否则进行添加。
|
||||||
|
|
||||||
|
```yml
|
||||||
|
name: Toggle Labels
|
||||||
|
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [reopened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
toggle-labels:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Toggle labels
|
||||||
|
uses: actions-cool/issues-helper@v3
|
||||||
|
with:
|
||||||
|
actions: 'toggle-labels'
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
issue-number: ${{ github.event.issue.number }}
|
||||||
|
labels: 'unread,outdated'
|
||||||
|
```
|
||||||
|
|
||||||
|
| 参数 | 描述 | 类型 | 必填 |
|
||||||
|
| -- | -- | -- | -- |
|
||||||
|
| actions | 操作类型 | string | ✔ |
|
||||||
|
| token | [token 说明](#token) | string | ✖ |
|
||||||
|
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | ✖ |
|
||||||
|
| labels | 切换 labels。如果 label 已存在则删除,不存在则添加 | string | ✖ |
|
||||||
|
|
||||||
|
⏫ [返回列表](#列-表)
|
||||||
|
|
||||||
## 🎁 参 考
|
## 🎁 参 考
|
||||||
|
|
||||||
### token
|
### token
|
||||||
|
30
dist/index.js
vendored
30
dist/index.js
vendored
@@ -16060,7 +16060,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.doWelcome = exports.doMarkDuplicate = exports.doMarkAssignees = exports.doLockIssues = exports.doFindIssues = exports.doFindComments = exports.doCloseIssues = exports.doCheckIssue = exports.doCheckInactive = exports.doQueryIssues = exports.initAdvancedICE = void 0;
|
exports.doToggleLabels = exports.doWelcome = exports.doMarkDuplicate = exports.doMarkAssignees = exports.doLockIssues = exports.doFindIssues = exports.doFindComments = exports.doCloseIssues = exports.doCheckIssue = exports.doCheckInactive = exports.doQueryIssues = exports.initAdvancedICE = void 0;
|
||||||
const actions_util_1 = __nccwpck_require__(6972);
|
const actions_util_1 = __nccwpck_require__(6972);
|
||||||
const dayjs_1 = __importDefault(__nccwpck_require__(7401));
|
const dayjs_1 = __importDefault(__nccwpck_require__(7401));
|
||||||
const isSameOrBefore_1 = __importDefault(__nccwpck_require__(9517));
|
const isSameOrBefore_1 = __importDefault(__nccwpck_require__(9517));
|
||||||
@@ -16437,6 +16437,30 @@ function doWelcome(auth, issueNumber, body, labels, assignees, emoji) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.doWelcome = doWelcome;
|
exports.doWelcome = doWelcome;
|
||||||
|
function doToggleLabels(labels = []) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const issue = yield ICE.getIssue();
|
||||||
|
const baseLabels = issue.labels.map(({ name }) => name);
|
||||||
|
const addLabels = [];
|
||||||
|
const removeLabels = [];
|
||||||
|
for (const label of labels) {
|
||||||
|
if (baseLabels.includes(label)) {
|
||||||
|
removeLabels.push(label);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
addLabels.push(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (removeLabels.length) {
|
||||||
|
yield (0, base_1.doRemoveLabels)(removeLabels);
|
||||||
|
}
|
||||||
|
if (addLabels.length) {
|
||||||
|
yield (0, base_1.doAddLabels)(addLabels);
|
||||||
|
}
|
||||||
|
core.info(`[doToggleLabels] Done!`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.doToggleLabels = doToggleLabels;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -16923,6 +16947,10 @@ class IssueHelperEngine {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'toggle-labels': {
|
||||||
|
yield (0, advanced_1.doToggleLabels)(labels);
|
||||||
|
break;
|
||||||
|
}
|
||||||
// -[ Advanced End ]->
|
// -[ Advanced End ]->
|
||||||
default: {
|
default: {
|
||||||
core.warning(`The ${action} is not allowed.`);
|
core.warning(`The ${action} is not allowed.`);
|
||||||
|
@@ -16,6 +16,7 @@ import {
|
|||||||
doCreateComment,
|
doCreateComment,
|
||||||
doCreateCommentEmoji,
|
doCreateCommentEmoji,
|
||||||
doLockIssue,
|
doLockIssue,
|
||||||
|
doRemoveLabels,
|
||||||
doSetLabels,
|
doSetLabels,
|
||||||
doUpdateComment,
|
doUpdateComment,
|
||||||
} from './base';
|
} from './base';
|
||||||
@@ -392,3 +393,29 @@ export async function doWelcome(
|
|||||||
core.info(`[doWelcome] ${auth} is not first time!`);
|
core.info(`[doWelcome] ${auth} is not first time!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function doToggleLabels(labels: string[] = []) {
|
||||||
|
const issue = await ICE.getIssue();
|
||||||
|
const baseLabels: string[] = issue.labels.map(({ name }: any) => name);
|
||||||
|
|
||||||
|
const addLabels = [];
|
||||||
|
const removeLabels = [];
|
||||||
|
|
||||||
|
for (const label of labels) {
|
||||||
|
if (baseLabels.includes(label)) {
|
||||||
|
removeLabels.push(label);
|
||||||
|
} else {
|
||||||
|
addLabels.push(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removeLabels.length) {
|
||||||
|
await doRemoveLabels(removeLabels);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addLabels.length) {
|
||||||
|
await doAddLabels(addLabels);
|
||||||
|
}
|
||||||
|
|
||||||
|
core.info(`[doToggleLabels] Done!`);
|
||||||
|
}
|
||||||
|
@@ -14,6 +14,7 @@ import {
|
|||||||
doLockIssues,
|
doLockIssues,
|
||||||
doMarkAssignees,
|
doMarkAssignees,
|
||||||
doMarkDuplicate,
|
doMarkDuplicate,
|
||||||
|
doToggleLabels,
|
||||||
doWelcome,
|
doWelcome,
|
||||||
initAdvancedICE,
|
initAdvancedICE,
|
||||||
} from './advanced';
|
} from './advanced';
|
||||||
@@ -259,6 +260,10 @@ export class IssueHelperEngine implements IIssueHelperEngine {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'toggle-labels': {
|
||||||
|
await doToggleLabels(labels);
|
||||||
|
break;
|
||||||
|
}
|
||||||
// -[ Advanced End ]->
|
// -[ Advanced End ]->
|
||||||
default: {
|
default: {
|
||||||
core.warning(`The ${action} is not allowed.`);
|
core.warning(`The ${action} is not allowed.`);
|
||||||
|
@@ -56,5 +56,6 @@ export type TAction =
|
|||||||
| 'lock-issues'
|
| 'lock-issues'
|
||||||
| 'mark-assignees'
|
| 'mark-assignees'
|
||||||
| 'mark-duplicate'
|
| 'mark-duplicate'
|
||||||
| 'welcome';
|
| 'welcome'
|
||||||
|
| 'toggle-labels';
|
||||||
//// [ Advanced End ]
|
//// [ Advanced End ]
|
||||||
|
@@ -389,3 +389,34 @@ jobs:
|
|||||||
| issue-emoji | Add [emoji](/guide/ref#-emoji-type) to this issue| string | ✖ |
|
| issue-emoji | Add [emoji](/guide/ref#-emoji-type) to this issue| string | ✖ |
|
||||||
|
|
||||||
- If these 4 options are not filled, no operation
|
- If these 4 options are not filled, no operation
|
||||||
|
|
||||||
|
## `toggle-labels`
|
||||||
|
|
||||||
|
When an issue is reopened, the set labels are removed if they already exist, otherwise they are added.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
name: Toggle Labels
|
||||||
|
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [reopened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
toggle-labels:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Toggle labels
|
||||||
|
uses: actions-cool/issues-helper@v3
|
||||||
|
with:
|
||||||
|
actions: 'toggle-labels'
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
issue-number: ${{ github.event.issue.number }}
|
||||||
|
labels: 'unread,outdated'
|
||||||
|
```
|
||||||
|
|
||||||
|
| Param | Desc | Type | Required |
|
||||||
|
| -- | -- | -- | -- |
|
||||||
|
| actions | Action type | string | ✔ |
|
||||||
|
| token | [Token explain](/guide/ref#-token) | string | ✖ |
|
||||||
|
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | ✖ |
|
||||||
|
| labels | The toggle labels. Delete if the label already exists, add if it does not exist | string | ✖ |
|
||||||
|
@@ -384,3 +384,34 @@ jobs:
|
|||||||
| issue-emoji | 为该 issue 增加 [emoji](/zh-CN/guide/ref#-emoji-类型) | string | ✖ |
|
| issue-emoji | 为该 issue 增加 [emoji](/zh-CN/guide/ref#-emoji-类型) | string | ✖ |
|
||||||
|
|
||||||
- 若这 4 个可选项都不填,则无操作
|
- 若这 4 个可选项都不填,则无操作
|
||||||
|
|
||||||
|
## `toggle-labels`
|
||||||
|
|
||||||
|
当一个 issue 被重新打开,判断设置的 labels 如果已经存在则进行删除,否则进行添加。
|
||||||
|
|
||||||
|
```yml
|
||||||
|
name: Toggle Labels
|
||||||
|
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [reopened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
toggle-labels:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Toggle labels
|
||||||
|
uses: actions-cool/issues-helper@v3
|
||||||
|
with:
|
||||||
|
actions: 'toggle-labels'
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
issue-number: ${{ github.event.issue.number }}
|
||||||
|
labels: 'unread,outdated'
|
||||||
|
```
|
||||||
|
|
||||||
|
| 参数 | 描述 | 类型 | 必填 |
|
||||||
|
| -- | -- | -- | -- |
|
||||||
|
| actions | 操作类型 | string | ✔ |
|
||||||
|
| token | [token 说明](/zh-CN/guide/ref#-token-说明) | string | ✖ |
|
||||||
|
| issue-number | 指定的 issue,当不传时会从触发事件中获取 | number | ✖ |
|
||||||
|
| labels | 切换 labels。如果 label 已存在则删除,不存在则添加 | string | ✖ |
|
||||||
|
Reference in New Issue
Block a user