feat: add reason for closing issue (#110)

* feat: add reason for closing issue

* style: fix lint
This commit is contained in:
Noah Hsu
2022-08-09 11:57:40 +08:00
committed by GitHub
parent 99345e5b9f
commit 95857edf92
15 changed files with 1436 additions and 1387 deletions

View File

@@ -354,6 +354,7 @@ Close the specified issue.
| 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 | ✖ |
| close-reason | Reason for closing. Default `not_planned`, another `completed` | string | ✖ |
⏫ [Back to list](#List)
@@ -856,6 +857,7 @@ jobs:
| title-includes | Title filtering | string | ✖ |
| inactive-day | Inactive days filtering | number | ✖ |
| exclude-labels | Exclude labels filtering | string | ✖ |
| close-reason | Reason for closing. Default `not_planned`, another `completed` | string | ✖ |
- `labels`: When there are multiple, the query will have multiple at the same time. If not entered, all
- `issue-assignee`: Multiplayer is not supported. If you do not enter or enter *, all will be searched. Entering `none` will query issues for which the specified person is not added
@@ -1062,6 +1064,7 @@ jobs:
| emoji | Add [reaction](#emoji-types) for this comment | string | ✖ |
| close-issue | Whether to close the issue at the same time | string | ✖ |
| require-permission | Permission required, default is `write` | string | ✖ |
| close-reason | Reason for closing. Default `not_planned`, another `completed` | string | ✖ |
- `duplicate-command`: When setting concise commands, while still supporting the original `Duplicate of`. Block content contains `?`
- `labels`: Highest priority

View File

@@ -358,6 +358,7 @@ jobs:
| actions | 操作类型 | string | ✔ |
| token | [token 说明](#token) | string | ✖ |
| issue-number | 指定的 issue当不传时会从触发事件中获取 | number | ✖ |
| close-reason | 关闭原因。默认`not_planned`未计划,`completed`完成 | string | ✖ |
⏫ [返回列表](#列-表)
@@ -855,6 +856,7 @@ jobs:
| title-includes | 包含标题筛选 | string | ✖ |
| inactive-day | 非活跃天数筛选 | number | ✖ |
| exclude-labels | 排除标签筛选 | string | ✖ |
| close-reason | 关闭原因。默认`not_planned`未计划,`completed`完成 | string | ✖ |
- `labels`:为多个时,会查询同时拥有多个。不填时,会查询所有
- `issue-assignee`:不支持多人。不填或输入 * 时,查询所有。输入 `none` 会查询未添加指定人的 issues
@@ -1061,6 +1063,7 @@ jobs:
| emoji | 为该评论的增加 [emoji](#emoji-types) | string | ✖ |
| close-issue | 是否同时关闭该 issue | string | ✖ |
| require-permission | 要求权限,默认为 `write` | string | ✖ |
| close-reason | 关闭原因。默认`not_planned`未计划,`completed`完成 | string | ✖ |
- `duplicate-command`:当设置简洁命令时,同时仍支持原有 `Duplicate of`。屏蔽内容包含 `?`
- `labels`:优先级最高

View File

@@ -28,6 +28,8 @@ inputs:
description: 'Issue assignees'
random-to:
description: 'Issue assignees random to'
close-reason:
description: 'Issue close reason'
# label
labels:

2743
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -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 {

View File

@@ -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!`);
}

View File

@@ -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': {

View File

@@ -1,7 +1,14 @@
import { Octokit } from '@octokit/rest';
import { EEmoji } from '../shared';
import type { TEmoji, TIssueState, TLockReasons, TUpdateMode, TUserPermission } from '../types';
import type {
TEmoji,
TIssueState,
TLockReasons,
TUpdateMode,
TUserPermission,
TCloseReason,
} from '../types';
import type {
IIssueBaseInfo,
IIssueCoreEngine,
@@ -53,13 +60,14 @@ export class IssueCoreEngine implements IIssueCoreEngine {
});
}
public async closeIssue() {
public async closeIssue(reason: TCloseReason) {
const { owner, repo, octokit, issueNumber } = this;
await octokit.issues.update({
owner,
repo,
issue_number: issueNumber,
state: 'closed',
state_reason: reason,
});
}

View File

@@ -1,4 +1,11 @@
import type { TEmoji, TIssueState, TLockReasons, TUpdateMode, TUserPermission } from '../types';
import type {
TCloseReason,
TEmoji,
TIssueState,
TLockReasons,
TUpdateMode,
TUserPermission,
} from '../types';
export interface IIssueBaseInfo {
owner: string;
@@ -53,7 +60,7 @@ export interface IIssueCoreEngine {
addAssignees: (assignees: string[]) => Promise<void>;
addLabels: (labels: string[]) => Promise<void>;
closeIssue: () => Promise<void>;
closeIssue: (reason: TCloseReason) => Promise<void>;
/**
* @param body The comment body.
* @returns The create new comment id.

View File

@@ -12,6 +12,8 @@ export type TUpdateMode = 'append' | 'replace';
export type TUserPermission = TPermissionType;
export type TCloseReason = 'completed' | 'not_planned';
export type TOutInfo = {
auth: string;
id?: number;

View File

@@ -3,7 +3,8 @@ import { defineConfig } from 'dumi';
const name = 'issues-helper';
const logo = 'https://gw.alipayobjects.com/mdn/rms_f97235/afts/img/A*8xDgSL-O6O4AAAAAAAAAAAAAARQnAQ';
const logo =
'https://gw.alipayobjects.com/mdn/rms_f97235/afts/img/A*8xDgSL-O6O4AAAAAAAAAAAAAARQnAQ';
export default defineConfig({
title: 'Issues Helper',

View File

@@ -134,6 +134,7 @@ jobs:
| title-includes | Title filtering | string | ✖ |
| inactive-day | Inactive days filtering | number | ✖ |
| exclude-labels | Exclude labels filtering | string | ✖ |
| close-reason | Reason for closing. Default `not_planned`, another `completed` | string | ✖ |
- `labels`: When there are multiple, the query will have multiple at the same time. If not entered, all
- `issue-assignee`: Multiplayer is not supported. If you do not enter or enter *, all will be searched. Entering `none` will query issues for which the specified person is not added
@@ -329,6 +330,7 @@ jobs:
| emoji | Add [emoji](/en-US/guide/ref#-emoji-type) for this comment | string | ✖ |
| close-issue | Whether to close the issue at the same time | string | ✖ |
| require-permission | Permission required, default is `write` | string | ✖ |
| close-reason | Reason for closing. Default `not_planned`, another `completed` | string | ✖ |
- `duplicate-command`: When setting concise commands, while still supporting the original `Duplicate of`. Block content contains `?`
- `labels`: Highest priority

View File

@@ -130,6 +130,7 @@ jobs:
| title-includes | 包含标题筛选 | string | ✖ |
| inactive-day | 非活跃天数筛选 | number | ✖ |
| exclude-labels | 排除标签筛选 | string | ✖ |
| close-reason | 关闭原因。默认`not_planned`未计划,`completed`完成 | string | ✖ |
- `labels`:为多个时,会查询同时拥有多个。不填时,会查询所有
- `issue-assignee`:不支持多人。不填或输入 * 时,查询所有。输入 `none` 会查询未添加指定人的 issues
@@ -326,6 +327,7 @@ jobs:
| emoji | 为该评论的增加 [emoji](/guide/ref#-emoji-类型) | string | ✖ |
| close-issue | 是否同时关闭该 issue | string | ✖ |
| require-permission | 要求权限,默认为 `write` | string | ✖ |
| close-reason | 关闭原因。默认`not_planned`未计划,`completed`完成 | string | ✖ |
- `duplicate-command`:当设置简洁命令时,同时仍支持原有 `Duplicate of`。屏蔽内容包含 `?`
- `labels`:优先级最高

View File

@@ -98,6 +98,7 @@ Close the specified issue.
| actions | Action type | string | ✔ |
| token | [Token explain](/en-US/guide/ref#-token) | string | ✖ |
| issue-number | The number of issue. When not input, it will be obtained from the trigger event | number | ✖ |
| close-reason | Reason for closing. Default `not_planned`, another `completed` | string | ✖ |
## `create-comment`

View File

@@ -98,6 +98,7 @@ jobs:
| actions | 操作类型 | string | ✔ |
| token | [token 说明](/guide/ref#-token-说明) | string | ✖ |
| issue-number | 指定的 issue当不传时会从触发事件中获取 | number | ✖ |
| close-reason | 关闭原因。默认`not_planned`未计划,`completed`完成 | string | ✖ |
## `create-comment`