mirror of
https://gitea.com/Lydanne/issues-helper.git
synced 2025-08-20 02:35:58 +08:00
feat: add reason for closing issue (#110)
* feat: add reason for closing issue * style: fix lint
This commit is contained in:
@@ -6,7 +6,7 @@ import utc from 'dayjs/plugin/utc';
|
||||
|
||||
import * as core from '../core';
|
||||
import type { IIssueCoreEngine, IListIssuesParams, TCommentInfo, TIssueList } from '../issue';
|
||||
import type { TEmoji, TIssueState, TOutList } from '../types';
|
||||
import type { TCloseReason, TEmoji, TIssueState, TOutList } from '../types';
|
||||
import { checkDuplicate, matchKeyword, replaceStr2Arr } from '../util';
|
||||
import {
|
||||
doAddAssignees,
|
||||
@@ -179,13 +179,13 @@ export async function doCheckIssue() {
|
||||
core.setOutput('check-result', checkResult);
|
||||
}
|
||||
|
||||
export async function doCloseIssues(body: string, emoji?: string) {
|
||||
export async function doCloseIssues(body: string, closeReason: TCloseReason, emoji?: string) {
|
||||
const issues = await doQueryIssues('open');
|
||||
if (issues.length) {
|
||||
for (const { number } of issues) {
|
||||
core.info(`[doCloseIssues] Doing ---> ${number}`);
|
||||
if (body) await doCreateComment(body, emoji, number);
|
||||
await doCloseIssue(number);
|
||||
await doCloseIssue(closeReason, number);
|
||||
}
|
||||
} else {
|
||||
core.info(`[doCloseIssues] Query issues empty!`);
|
||||
@@ -293,6 +293,7 @@ export async function doMarkAssignees(comment: TCommentInfo) {
|
||||
|
||||
export async function doMarkDuplicate(
|
||||
comment: TCommentInfo,
|
||||
closeReason: TCloseReason,
|
||||
labels?: string[] | void,
|
||||
emoji?: string,
|
||||
) {
|
||||
@@ -345,7 +346,7 @@ export async function doMarkDuplicate(
|
||||
await doSetLabels(newLabels);
|
||||
}
|
||||
if (closeIssue === 'true') {
|
||||
await doCloseIssue();
|
||||
await doCloseIssue(closeReason);
|
||||
}
|
||||
core.info(`[doMarkDuplicate] Done!`);
|
||||
} else {
|
||||
|
@@ -3,7 +3,7 @@ import { dealStringToArr } from 'actions-util';
|
||||
import * as core from '../core';
|
||||
import type { IIssueCoreEngine } from '../issue';
|
||||
import { ELockReasons } from '../shared';
|
||||
import type { TEmoji, TIssueState, TLockReasons, TUpdateMode } from '../types';
|
||||
import type { TCloseReason, TEmoji, TIssueState, TLockReasons, TUpdateMode } from '../types';
|
||||
|
||||
let ICE: IIssueCoreEngine;
|
||||
export function initBaseICE(_ICE: IIssueCoreEngine) {
|
||||
@@ -21,9 +21,9 @@ export async function doAddLabels(labels: string[], issueNumber?: number) {
|
||||
core.info(`[doAddLabels] [${labels}] success!`);
|
||||
}
|
||||
|
||||
export async function doCloseIssue(issueNumber?: number) {
|
||||
export async function doCloseIssue(reason: TCloseReason, issueNumber?: number) {
|
||||
if (issueNumber) ICE.setIssueNumber(issueNumber);
|
||||
await ICE.closeIssue();
|
||||
await ICE.closeIssue(reason);
|
||||
core.info(`[doCloseIssue] success!`);
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,7 @@ import { dealStringToArr } from 'actions-util';
|
||||
import * as core from '../core';
|
||||
import type { IIssueCoreEngine, TCommentInfo } from '../issue';
|
||||
import { IssueCoreEngine } from '../issue';
|
||||
import type { Context, TAction, TIssueState, TUpdateMode } from '../types';
|
||||
import type { Context, TAction, TCloseReason, TIssueState, TUpdateMode } from '../types';
|
||||
import { dealRandomAssignees } from '../util';
|
||||
import {
|
||||
doCheckInactive,
|
||||
@@ -51,6 +51,7 @@ export class IssueHelperEngine implements IIssueHelperEngine {
|
||||
private body: string = '';
|
||||
private state: TIssueState = 'open';
|
||||
private updateMode: TUpdateMode = 'replace';
|
||||
private closeReason: TCloseReason = 'not_planned';
|
||||
|
||||
public constructor(readonly ctx: Context) {
|
||||
this.initInput(ctx);
|
||||
@@ -92,6 +93,7 @@ export class IssueHelperEngine implements IIssueHelperEngine {
|
||||
this.body = core.getInput('body') || '';
|
||||
this.state = core.getInput('state') === 'closed' ? 'closed' : 'open';
|
||||
this.updateMode = core.getInput('update-mode') === 'append' ? 'append' : 'replace';
|
||||
this.closeReason = core.getInput('close-reason') === 'completed' ? 'completed' : 'not_planned';
|
||||
}
|
||||
|
||||
private initIssueCore() {
|
||||
@@ -107,7 +109,18 @@ export class IssueHelperEngine implements IIssueHelperEngine {
|
||||
}
|
||||
|
||||
public async doExeAction(action: TAction) {
|
||||
const { issueNumber, emoji, labels, assignees, title, body, updateMode, state, ctx } = this;
|
||||
const {
|
||||
issueNumber,
|
||||
emoji,
|
||||
labels,
|
||||
assignees,
|
||||
title,
|
||||
body,
|
||||
updateMode,
|
||||
state,
|
||||
ctx,
|
||||
closeReason,
|
||||
} = this;
|
||||
switch (action) {
|
||||
// ---[ Base Begin ]--->>>
|
||||
case 'add-assignees': {
|
||||
@@ -127,7 +140,7 @@ export class IssueHelperEngine implements IIssueHelperEngine {
|
||||
break;
|
||||
}
|
||||
case 'close-issue': {
|
||||
await doCloseIssue();
|
||||
await doCloseIssue(closeReason);
|
||||
break;
|
||||
}
|
||||
case 'create-comment': {
|
||||
@@ -202,7 +215,7 @@ export class IssueHelperEngine implements IIssueHelperEngine {
|
||||
break;
|
||||
}
|
||||
case 'close-issues': {
|
||||
await doCloseIssues(body, emoji);
|
||||
await doCloseIssues(body, closeReason, emoji);
|
||||
break;
|
||||
}
|
||||
case 'find-comments': {
|
||||
@@ -230,7 +243,7 @@ export class IssueHelperEngine implements IIssueHelperEngine {
|
||||
core.warning(`[mark-duplicate] only support event '[issue_comment: created/edited]'!`);
|
||||
return;
|
||||
}
|
||||
await doMarkDuplicate(ctx.payload.comment as TCommentInfo, labels, emoji);
|
||||
await doMarkDuplicate(ctx.payload.comment as TCommentInfo, closeReason, labels, emoji);
|
||||
break;
|
||||
}
|
||||
case 'welcome': {
|
||||
|
Reference in New Issue
Block a user