mirror of
https://gitea.com/Lydanne/issues-helper.git
synced 2025-08-21 19:25:46 +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!`);
|
core.info(`[doSetLabels] [${labels}] success!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function doToggleLabels(labels: string[]) {
|
||||||
|
await ICE.toggleLabels(labels);
|
||||||
|
core.info(`[doToggleLabels] [${labels}] success!`);
|
||||||
|
}
|
||||||
|
|
||||||
export async function doUnlockIssue() {
|
export async function doUnlockIssue() {
|
||||||
await ICE.unlockIssue();
|
await ICE.unlockIssue();
|
||||||
core.info(`[doUnlockIssue] success!`);
|
core.info(`[doUnlockIssue] success!`);
|
||||||
|
@@ -31,6 +31,7 @@ import {
|
|||||||
doRemoveAssignees,
|
doRemoveAssignees,
|
||||||
doRemoveLabels,
|
doRemoveLabels,
|
||||||
doSetLabels,
|
doSetLabels,
|
||||||
|
doToggleLabels,
|
||||||
doUnlockIssue,
|
doUnlockIssue,
|
||||||
doUpdateComment,
|
doUpdateComment,
|
||||||
doUpdateIssue,
|
doUpdateIssue,
|
||||||
@@ -208,6 +209,14 @@ export class IssueHelperEngine implements IIssueHelperEngine {
|
|||||||
await doUpdateIssue(0, state, title, body, updateMode, labels, assignees);
|
await doUpdateIssue(0, state, title, body, updateMode, labels, assignees);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'toggle-labels': {
|
||||||
|
if (labels && labels.length) {
|
||||||
|
await doToggleLabels(labels);
|
||||||
|
} else {
|
||||||
|
core.warning(`[doToggleLabels] labels is empty!`);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
// ---[ Base End ]--->>>
|
// ---[ Base End ]--->>>
|
||||||
// ^_^ ============= ^_^
|
// ^_^ ============= ^_^
|
||||||
// -[ Advanced Begin ]->
|
// -[ 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() {
|
public async unlockIssue() {
|
||||||
const { owner, repo, octokit, issueNumber } = this;
|
const { owner, repo, octokit, issueNumber } = this;
|
||||||
await octokit.issues.unlock({
|
await octokit.issues.unlock({
|
||||||
|
@@ -102,6 +102,7 @@ export interface IIssueCoreEngine {
|
|||||||
removeLabels: (labels: string[]) => Promise<void>;
|
removeLabels: (labels: string[]) => Promise<void>;
|
||||||
|
|
||||||
setLabels: (labels: string[]) => Promise<void>;
|
setLabels: (labels: string[]) => Promise<void>;
|
||||||
|
toggleLabels: (labels: string[]) => Promise<void>;
|
||||||
|
|
||||||
unlockIssue: () => Promise<void>;
|
unlockIssue: () => Promise<void>;
|
||||||
|
|
||||||
|
@@ -44,6 +44,7 @@ export type TAction =
|
|||||||
| 'unlock-issue'
|
| 'unlock-issue'
|
||||||
| 'update-comment'
|
| 'update-comment'
|
||||||
| 'update-issue'
|
| 'update-issue'
|
||||||
|
| 'toggle-labels'
|
||||||
// [ Base End ]
|
// [ Base End ]
|
||||||
// ^_^ ========== ^_^
|
// ^_^ ========== ^_^
|
||||||
// [ Advanced Begin ]
|
// [ Advanced Begin ]
|
||||||
|
Reference in New Issue
Block a user