Compare commits

..

6 Commits

Author SHA1 Message Date
元凛
65840f57fe chore: update dist 2023-02-06 21:51:50 +08:00
元凛
dbeaa215cb style: update style & changelog 2023-02-06 21:47:17 +08:00
Wuxh
6a55b3a9f4 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>
2023-01-31 12:56:43 +08:00
xrkffgg
f4eba4debf docs: update badge 2022-12-21 20:35:47 +08:00
xrkffgg
09bc8811a0 docs: up badge 2022-12-21 20:34:35 +08:00
元凛
dfac87c369 chore: update tag 2022-11-13 01:15:25 +08:00
10 changed files with 201 additions and 3 deletions

View File

@@ -7,6 +7,12 @@
🛠 refactor 🛠 refactor
--> -->
## v3.4.0
`2023.02.06`
- 🚀 feat: support `toggle-labels`. [#132](https://github.com/actions-cool/issues-helper/pull/132) [@Wxh16144](https://github.com/Wxh16144)
## v3.3.3 ## v3.3.3
`2022.11.13` `2022.11.13`

View File

@@ -10,7 +10,7 @@
A GitHub Action that easily helps you automatically manage issues A GitHub Action that easily helps you automatically manage issues
[![](https://img.shields.io/github/workflow/status/actions-cool/issues-helper/ci?style=flat-square)](https://github.com/actions-cool/issues-helper/actions) [![](https://img.shields.io/github/actions/workflow/status/actions-cool/issues-helper/ci.yml?branch=main&style=flat-square)](https://github.com/actions-cool/issues-helper/actions)
[![](https://img.shields.io/badge/marketplace-issues--helper-red?style=flat-square)](https://github.com/marketplace/actions/issues-helper) [![](https://img.shields.io/badge/marketplace-issues--helper-red?style=flat-square)](https://github.com/marketplace/actions/issues-helper)
![](https://img.shields.io/github/languages/top/actions-cool/issues-helper?color=%2308979c&style=flat-square) ![](https://img.shields.io/github/languages/top/actions-cool/issues-helper?color=%2308979c&style=flat-square)
[![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi)
@@ -255,6 +255,7 @@ When the following list does not have the features you want, you can submit it i
- [`lock-issues`](#lock-issues) - [`lock-issues`](#lock-issues)
- [`mark-assignees`](#mark-assignees) - [`mark-assignees`](#mark-assignees)
- [`mark-duplicate`](#mark-duplicate) - [`mark-duplicate`](#mark-duplicate)
- [`toggle-labels`](#toggle-labels)
- [`welcome`](#welcome) - [`welcome`](#welcome)
## 🚀 Usage ## 🚀 Usage
@@ -1109,6 +1110,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)
#### `welcome` #### `welcome`
When an issue is created, the user who created the issue for the first time is welcome. When an issue is created, the user who created the issue for the first time is welcome.

View File

@@ -10,7 +10,7 @@
一个轻松帮你自动管理 issues 的 GitHub Action 一个轻松帮你自动管理 issues 的 GitHub Action
[![](https://img.shields.io/github/workflow/status/actions-cool/issues-helper/ci?style=flat-square)](https://github.com/actions-cool/issues-helper/actions) [![](https://img.shields.io/github/actions/workflow/status/actions-cool/issues-helper/ci.yml?branch=main&style=flat-square)](https://github.com/actions-cool/issues-helper/actions)
[![](https://img.shields.io/badge/marketplace-issues--helper-red?style=flat-square)](https://github.com/marketplace/actions/issues-helper) [![](https://img.shields.io/badge/marketplace-issues--helper-red?style=flat-square)](https://github.com/marketplace/actions/issues-helper)
![](https://img.shields.io/github/languages/top/actions-cool/issues-helper?color=%2308979c&style=flat-square) ![](https://img.shields.io/github/languages/top/actions-cool/issues-helper?color=%2308979c&style=flat-square)
[![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi)
@@ -259,6 +259,7 @@
- [`lock-issues`](#lock-issues) - [`lock-issues`](#lock-issues)
- [`mark-assignees`](#mark-assignees) - [`mark-assignees`](#mark-assignees)
- [`mark-duplicate`](#mark-duplicate) - [`mark-duplicate`](#mark-duplicate)
- [`toggle-labels`](#toggle-labels)
- [`welcome`](#welcome) - [`welcome`](#welcome)
## 🚀 使 用 ## 🚀 使 用
@@ -1108,6 +1109,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 | ✖ |
⏫ [返回列表](#列-表)
#### `welcome` #### `welcome`
当一个 issue 新建时,对首次新建 issue 的用户进行欢迎。若用户非首次新建,则无操作。 当一个 issue 新建时,对首次新建 issue 的用户进行欢迎。若用户非首次新建,则无操作。

30
dist/index.js vendored
View File

@@ -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.doWelcome = exports.doToggleLabels = 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));
@@ -16412,6 +16412,30 @@ function doMarkDuplicate(comment, closeReason, labels, emoji) {
}); });
} }
exports.doMarkDuplicate = doMarkDuplicate; exports.doMarkDuplicate = doMarkDuplicate;
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;
function doWelcome(auth, issueNumber, body, labels, assignees, emoji) { function doWelcome(auth, issueNumber, body, labels, assignees, emoji) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.info(`[doWelcome] [${auth}]`); core.info(`[doWelcome] [${auth}]`);
@@ -16914,6 +16938,10 @@ class IssueHelperEngine {
yield (0, advanced_1.doMarkDuplicate)(ctx.payload.comment, closeReason, labels, emoji); yield (0, advanced_1.doMarkDuplicate)(ctx.payload.comment, closeReason, labels, emoji);
break; break;
} }
case 'toggle-labels': {
yield (0, advanced_1.doToggleLabels)(labels);
break;
}
case 'welcome': { case 'welcome': {
if (ctx.eventName === 'issues' && ctx.payload.action === 'opened') { if (ctx.eventName === 'issues' && ctx.payload.action === 'opened') {
yield (0, advanced_1.doWelcome)(ctx.actor, issueNumber, body, labels, assignees, emoji); yield (0, advanced_1.doWelcome)(ctx.actor, issueNumber, body, labels, assignees, emoji);

View File

@@ -38,6 +38,7 @@ async function run() {
if (tags.includes(tagSimple)) { if (tags.includes(tagSimple)) {
console.log(chalk.yellow(`[Git Action] Delete ${tagSimple} tag`)); console.log(chalk.yellow(`[Git Action] Delete ${tagSimple} tag`));
execSync(`git push origin :refs/tags/${tagSimple}`); execSync(`git push origin :refs/tags/${tagSimple}`);
console.log(chalk.green(`[Git Action] Delete ${tagSimple} tag success`));
} }
console.log(chalk.yellow(`[Git Action] Add new simple ${tagSimple} tag`)); console.log(chalk.yellow(`[Git Action] Add new simple ${tagSimple} tag`));

View File

@@ -16,6 +16,7 @@ import {
doCreateComment, doCreateComment,
doCreateCommentEmoji, doCreateCommentEmoji,
doLockIssue, doLockIssue,
doRemoveLabels,
doSetLabels, doSetLabels,
doUpdateComment, doUpdateComment,
} from './base'; } from './base';
@@ -361,6 +362,32 @@ export async function doMarkDuplicate(
} }
} }
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!`);
}
export async function doWelcome( export async function doWelcome(
auth: string, auth: string,
issueNumber: number, issueNumber: number,

View File

@@ -14,6 +14,7 @@ import {
doLockIssues, doLockIssues,
doMarkAssignees, doMarkAssignees,
doMarkDuplicate, doMarkDuplicate,
doToggleLabels,
doWelcome, doWelcome,
initAdvancedICE, initAdvancedICE,
} from './advanced'; } from './advanced';
@@ -251,6 +252,10 @@ export class IssueHelperEngine implements IIssueHelperEngine {
await doMarkDuplicate(ctx.payload.comment as TCommentInfo, closeReason, labels, emoji); await doMarkDuplicate(ctx.payload.comment as TCommentInfo, closeReason, labels, emoji);
break; break;
} }
case 'toggle-labels': {
await doToggleLabels(labels);
break;
}
case 'welcome': { case 'welcome': {
if (ctx.eventName === 'issues' && ctx.payload.action === 'opened') { if (ctx.eventName === 'issues' && ctx.payload.action === 'opened') {
await doWelcome(ctx.actor, issueNumber, body, labels, assignees, emoji); await doWelcome(ctx.actor, issueNumber, body, labels, assignees, emoji);

View File

@@ -56,5 +56,6 @@ export type TAction =
| 'lock-issues' | 'lock-issues'
| 'mark-assignees' | 'mark-assignees'
| 'mark-duplicate' | 'mark-duplicate'
| 'toggle-labels'
| 'welcome'; | 'welcome';
//// [ Advanced End ] //// [ Advanced End ]

View File

@@ -351,6 +351,37 @@ Note: Duplicate created with the concise command does not display the content of
![](https://gw.alipayobjects.com/mdn/rms_f97235/afts/img/A*PN2tS7PjDQ4AAAAAAAAAAAAAARQnAQ) ![](https://gw.alipayobjects.com/mdn/rms_f97235/afts/img/A*PN2tS7PjDQ4AAAAAAAAAAAAAARQnAQ)
## `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 | ✖ |
## `welcome` ## `welcome`
When an issue is created, the user who created the issue for the first time is welcome. When an issue is created, the user who created the issue for the first time is welcome.

View File

@@ -348,6 +348,37 @@ jobs:
![](https://gw.alipayobjects.com/mdn/rms_f97235/afts/img/A*PN2tS7PjDQ4AAAAAAAAAAAAAARQnAQ) ![](https://gw.alipayobjects.com/mdn/rms_f97235/afts/img/A*PN2tS7PjDQ4AAAAAAAAAAAAAARQnAQ)
## `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 | ✖ |
## `welcome` ## `welcome`
当一个 issue 新建时,对首次新建 issue 的用户进行欢迎。若用户非首次新建,则无操作。 当一个 issue 新建时,对首次新建 issue 的用户进行欢迎。若用户非首次新建,则无操作。