style: format

This commit is contained in:
元凛
2022-02-10 17:55:52 +08:00
parent bdb9ee8890
commit c626dd5ef0
13 changed files with 218 additions and 126 deletions

View File

@@ -1,20 +1,22 @@
import { dealStringToArr, checkPermission, TPermissionType } from 'actions-util';
import type { TPermissionType } from 'actions-util';
import { checkPermission, dealStringToArr } from 'actions-util';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
import utc from 'dayjs/plugin/utc';
import * as core from '../core';
import { matchKeyword, checkDuplicate, replaceStr2Arr } from '../util';
import { TIssueState, TOutList, TEmoji } from '../types';
import { IIssueCoreEngine, IListIssuesParams, TIssueList, TCommentInfo } from '../issue';
import type { IIssueCoreEngine, IListIssuesParams, TCommentInfo, TIssueList } from '../issue';
import type { TEmoji, TIssueState, TOutList } from '../types';
import { checkDuplicate, matchKeyword, replaceStr2Arr } from '../util';
import {
doAddAssignees,
doAddLabels,
doCloseIssue,
doCreateComment,
doCreateCommentEmoji,
doCloseIssue,
doLockIssue,
doUpdateComment,
doSetLabels,
doUpdateComment,
} from './base';
let ICE: IIssueCoreEngine;
@@ -22,7 +24,11 @@ export function initAdvancedICE(_ICE: IIssueCoreEngine) {
ICE = _ICE;
}
export async function doQueryIssues(state: TIssueState | 'all', creator?: string, ignoreLabels?: boolean): Promise<TIssueList> {
export async function doQueryIssues(
state: TIssueState | 'all',
creator?: string,
ignoreLabels?: boolean,
): Promise<TIssueList> {
const params = {
state,
} as IListIssuesParams;
@@ -30,14 +36,16 @@ export async function doQueryIssues(state: TIssueState | 'all', creator?: string
const issueCreator = core.getInput('issue-creator');
const issueAssignee = core.getInput('issue-assignee');
const issueMentioned = core.getInput('issue-mentioned');
issueCreator ? (params.creator = issueCreator) : null;
issueAssignee ? (params.assignee = issueAssignee) : null;
issueMentioned ? (params.mentioned = issueMentioned) : null;
if (issueCreator) params.creator = issueCreator;
if (issueAssignee) params.assignee = issueAssignee;
if (issueMentioned) params.mentioned = issueMentioned;
const labels = core.getInput('labels');
labels && !ignoreLabels ? params.labels = labels : null;
creator ? params.creator = creator : null;
if (labels && !ignoreLabels) params.labels = labels;
if (creator) params.creator = creator;
const issuesList = await ICE.listIssues(params);
const issues: TIssueList = [];
@@ -131,7 +139,7 @@ export async function doCheckIssue() {
checkAssignee = true;
}
});
!checkAssignee ? (checkResult = false) : null;
if (!checkAssignee) checkResult = false;
}
const titleRemove = core.getInput('title-excludes');
@@ -234,8 +242,8 @@ export async function doFindIssues() {
state: issue.state,
created: issue.created_at,
updated: issue.updated_at,
}
})
};
});
if (direction === 'desc') {
issues.reverse();
}
@@ -282,7 +290,11 @@ export async function doMarkAssignees(comment: TCommentInfo) {
}
}
export async function doMarkDuplicate(comment: TCommentInfo, labels?: string[] | void, emoji?: string) {
export async function doMarkDuplicate(
comment: TCommentInfo,
labels?: string[] | void,
emoji?: string,
) {
const duplicateCommand = core.getInput('duplicate-command');
const duplicateLabels = core.getInput('duplicate-labels');
const removeLables = core.getInput('remove-labels') || '';
@@ -342,7 +354,14 @@ export async function doMarkDuplicate(comment: TCommentInfo, labels?: string[] |
}
}
export async function doWelcome(auth: string, issueNumber: number, body: string, labels?: string[] | void, assignees?: string[] | void, emoji?: string) {
export async function doWelcome(
auth: string,
issueNumber: number,
body: string,
labels?: string[] | void,
assignees?: string[] | void,
emoji?: string,
) {
core.info(`[doWelcome] [${auth}]`);
const issues = await doQueryIssues('all', auth, true);
if (issues.length == 0 || (issues.length == 1 && issues[0].number == issueNumber)) {

View File

@@ -1,8 +1,9 @@
import { dealStringToArr } from 'actions-util';
import * as core from '../core';
import { TIssueState, TUpdateMode, TEmoji, TLockReasons } from '../types';
import type { IIssueCoreEngine } from '../issue';
import { ELockReasons } from '../shared';
import { IIssueCoreEngine } from '../issue';
import type { TEmoji, TIssueState, TLockReasons, TUpdateMode } from '../types';
let ICE: IIssueCoreEngine;
export function initBaseICE(_ICE: IIssueCoreEngine) {
@@ -50,7 +51,13 @@ export async function doCreateCommentEmoji(_commentId: number | void, emoji: str
}
}
export async function doCreateIssue(title: string, body: string, labels: string[] | void, assignees: string[] | void, emoji: string | void) {
export async function doCreateIssue(
title: string,
body: string,
labels?: string[],
assignees?: string[],
emoji?: string | void,
) {
if (title) {
const issueNumber = await ICE.createIssue(title, body, labels, assignees);
core.info(`[doCreateIssue] [${title}] success!`);
@@ -124,7 +131,12 @@ export async function doUnlockIssue() {
core.info(`[doUnlockIssue] success!`);
}
export async function doUpdateComment(_commentId: number | void, body: string, updateMode: TUpdateMode, emoji: string | void) {
export async function doUpdateComment(
_commentId: number | void,
body: string,
updateMode: TUpdateMode,
emoji: string | void,
) {
const commentId = _commentId || core.getInput('comment-id');
if (commentId) {
await ICE.updateComment(+commentId, body, updateMode);
@@ -137,7 +149,15 @@ export async function doUpdateComment(_commentId: number | void, body: string, u
}
}
export async function doUpdateIssue(issueNumber: number, state: TIssueState, title: string | void, body: string | void, updateMode: TUpdateMode, labels?: string[] | void, assignees?: string[] | void) {
export async function doUpdateIssue(
issueNumber: number,
state: TIssueState,
title: string | void,
body: string | void,
updateMode: TUpdateMode,
labels?: string[] | void,
assignees?: string[] | void,
) {
if (issueNumber) ICE.setIssueNumber(issueNumber);
await ICE.updateIssue(state, title, body, updateMode, labels, assignees);
core.info(`[doUpdateIssue] success!`);

View File

@@ -1,22 +1,28 @@
// import * as github from '@actions/github';
import { dealStringToArr } from 'actions-util';
import * as core from '../core';
import { Context, TIssueState, TUpdateMode, TAction, TEmoji } from '../types';
import {
IssueCoreEngine,
IIssueCoreEngine,
TCommentInfo,
} from '../issue';
import { dealRandomAssignees } from '../util';
import { IIssueHelperEngine } from './types';
import * as core from '../core';
import type { IIssueCoreEngine, TCommentInfo } from '../issue';
import { IssueCoreEngine } from '../issue';
import type { Context, TAction, TIssueState, TUpdateMode } from '../types';
import { dealRandomAssignees } from '../util';
import {
doCheckInactive,
doCheckIssue,
doCloseIssues,
doFindComments,
doFindIssues,
doLockIssues,
doMarkAssignees,
doMarkDuplicate,
doWelcome,
initAdvancedICE,
} from './advanced';
import {
initBaseICE,
doAddAssignees,
doAddLabels,
doCloseIssue,
doCreateComment,
doCreateCommentEmoji,
doCreateIssue,
doCreateLabel,
doDeleteComment,
@@ -28,20 +34,9 @@ import {
doUnlockIssue,
doUpdateComment,
doUpdateIssue,
initBaseICE,
} from './base';
import {
initAdvancedICE,
doCheckInactive,
doCheckIssue,
doCloseIssues,
doFindComments,
doFindIssues,
doLockIssues,
doMarkAssignees,
doMarkDuplicate,
doWelcome,
} from './advanced';
import type { IIssueHelperEngine } from './types';
export class IssueHelperEngine implements IIssueHelperEngine {
private ICE!: IIssueCoreEngine;
@@ -51,8 +46,8 @@ export class IssueHelperEngine implements IIssueHelperEngine {
private issueNumber!: number;
private emoji?: string;
private labels?: string[] | void;
private assignees?: string[] | void;
private labels?: string[];
private assignees?: string[];
private title: string = '';
private body: string = '';
private state: TIssueState = 'open';
@@ -249,7 +244,7 @@ export class IssueHelperEngine implements IIssueHelperEngine {
break;
}
default: {
core.warning(`The ${action} is not allowed.`)
core.warning(`The ${action} is not allowed.`);
break;
}
}
@@ -257,6 +252,9 @@ export class IssueHelperEngine implements IIssueHelperEngine {
private checkEvent4Mark() {
const { ctx } = this;
return ctx.eventName !== 'issue_comment' && (ctx.payload.action === 'created' || ctx.payload.action === 'edited');
return (
ctx.eventName !== 'issue_comment' &&
(ctx.payload.action === 'created' || ctx.payload.action === 'edited')
);
}
}

View File

@@ -1,5 +1,5 @@
import { TAction } from '../types';
import type { TAction } from '../types';
export interface IIssueHelperEngine {
doExeAction(action: TAction): Promise<void>;
doExeAction: (action: TAction) => Promise<void>;
}