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:
Wuxh
2023-01-31 12:56:43 +08:00
committed by GitHub
parent f4eba4debf
commit 6a55b3a9f4
8 changed files with 193 additions and 2 deletions

View File

@@ -16,6 +16,7 @@ import {
doCreateComment,
doCreateCommentEmoji,
doLockIssue,
doRemoveLabels,
doSetLabels,
doUpdateComment,
} from './base';
@@ -392,3 +393,29 @@ export async function doWelcome(
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!`);
}

View File

@@ -14,6 +14,7 @@ import {
doLockIssues,
doMarkAssignees,
doMarkDuplicate,
doToggleLabels,
doWelcome,
initAdvancedICE,
} from './advanced';
@@ -259,6 +260,10 @@ export class IssueHelperEngine implements IIssueHelperEngine {
}
break;
}
case 'toggle-labels': {
await doToggleLabels(labels);
break;
}
// -[ Advanced End ]->
default: {
core.warning(`The ${action} is not allowed.`);

View File

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