mirror of
https://gitea.com/Lydanne/issues-helper.git
synced 2025-08-19 18:25:58 +08:00
feat: add toggle-labels
action
This commit is contained in:
@@ -138,6 +138,11 @@ export async function doSetLabels(labels: string[]) {
|
||||
core.info(`[doSetLabels] [${labels}] success!`);
|
||||
}
|
||||
|
||||
export async function doToggleLabels(labels: string[]) {
|
||||
await ICE.toggleLabels(labels);
|
||||
core.info(`[doToggleLabels] [${labels}] success!`);
|
||||
}
|
||||
|
||||
export async function doUnlockIssue() {
|
||||
await ICE.unlockIssue();
|
||||
core.info(`[doUnlockIssue] success!`);
|
||||
|
@@ -31,6 +31,7 @@ import {
|
||||
doRemoveAssignees,
|
||||
doRemoveLabels,
|
||||
doSetLabels,
|
||||
doToggleLabels,
|
||||
doUnlockIssue,
|
||||
doUpdateComment,
|
||||
doUpdateIssue,
|
||||
@@ -208,6 +209,14 @@ export class IssueHelperEngine implements IIssueHelperEngine {
|
||||
await doUpdateIssue(0, state, title, body, updateMode, labels, assignees);
|
||||
break;
|
||||
}
|
||||
case 'toggle-labels': {
|
||||
if (labels && labels.length) {
|
||||
await doToggleLabels(labels);
|
||||
} else {
|
||||
core.warning(`[doToggleLabels] labels is empty!`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// ---[ Base End ]--->>>
|
||||
// ^_^ ============= ^_^
|
||||
// -[ Advanced Begin ]->
|
||||
|
@@ -273,6 +273,30 @@ export class IssueCoreEngine implements IIssueCoreEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public async toggleLabels(labels: string[]) {
|
||||
const issue = await this.getIssue();
|
||||
const baseLabels: string[] = issue.labels.map(({ name }: any) => name);
|
||||
|
||||
let addLabels = [];
|
||||
let removeLabels = [];
|
||||
|
||||
for (const label of labels) {
|
||||
if (baseLabels.includes(label)) {
|
||||
removeLabels.push(label);
|
||||
} else {
|
||||
addLabels.push(label);
|
||||
}
|
||||
}
|
||||
|
||||
if (removeLabels.length) {
|
||||
await this.removeLabels(removeLabels);
|
||||
}
|
||||
|
||||
if (addLabels.length) {
|
||||
await this.addLabels(addLabels);
|
||||
}
|
||||
}
|
||||
|
||||
public async unlockIssue() {
|
||||
const { owner, repo, octokit, issueNumber } = this;
|
||||
await octokit.issues.unlock({
|
||||
|
@@ -102,6 +102,7 @@ export interface IIssueCoreEngine {
|
||||
removeLabels: (labels: string[]) => Promise<void>;
|
||||
|
||||
setLabels: (labels: string[]) => Promise<void>;
|
||||
toggleLabels: (labels: string[]) => Promise<void>;
|
||||
|
||||
unlockIssue: () => Promise<void>;
|
||||
|
||||
|
@@ -44,6 +44,7 @@ export type TAction =
|
||||
| 'unlock-issue'
|
||||
| 'update-comment'
|
||||
| 'update-issue'
|
||||
| 'toggle-labels'
|
||||
// [ Base End ]
|
||||
// ^_^ ========== ^_^
|
||||
// [ Advanced Begin ]
|
||||
|
Reference in New Issue
Block a user