diff --git a/.eslintrc.js b/.eslintrc.js index a4adabe..e3cb70f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,8 +1,9 @@ module.exports = { - extends: [require.resolve('@umijs/fabric/dist/eslint')], + extends: [require.resolve("@umijs/fabric/dist/eslint")], plugins: ["simple-import-sort"], rules: { "simple-import-sort/imports": "error", "simple-import-sort/exports": "error", + "@typescript-eslint/no-parameter-properties": 0, }, }; diff --git a/.prettierignore b/.prettierignore index 53c8968..d41281f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,3 +3,4 @@ lib/ docs-dist/ node_modules/ src/.umi/ +src/main.ts diff --git a/dist/index.js b/dist/index.js index d3c63df..0f2bb00 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14602,8 +14602,8 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.doWelcome = exports.doMarkDuplicate = exports.doMarkAssignees = exports.doLockIssues = exports.doFindIssues = exports.doFindComments = exports.doCloseIssues = exports.doCheckIssue = exports.doCheckInactive = exports.doQueryIssues = exports.initAdvancedICE = void 0; const actions_util_1 = __nccwpck_require__(6972); const dayjs_1 = __importDefault(__nccwpck_require__(7401)); -const utc_1 = __importDefault(__nccwpck_require__(4359)); const isSameOrBefore_1 = __importDefault(__nccwpck_require__(9517)); +const utc_1 = __importDefault(__nccwpck_require__(4359)); const core = __importStar(__nccwpck_require__(9875)); const util_1 = __nccwpck_require__(9604); const base_1 = __nccwpck_require__(8824); @@ -14620,12 +14620,17 @@ function doQueryIssues(state, creator, ignoreLabels) { 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 = yield ICE.listIssues(params); const issues = []; const issueNumbers = []; @@ -14720,7 +14725,8 @@ function doCheckIssue() { checkAssignee = true; } }); - !checkAssignee ? (checkResult = false) : null; + if (!checkAssignee) + checkResult = false; } const titleRemove = core.getInput('title-excludes'); if (!!checkResult && titleRemove) { @@ -15229,8 +15235,8 @@ const actions_util_1 = __nccwpck_require__(6972); const core = __importStar(__nccwpck_require__(9875)); const issue_1 = __nccwpck_require__(4680); const util_1 = __nccwpck_require__(9604); -const base_1 = __nccwpck_require__(8824); const advanced_1 = __nccwpck_require__(5745); +const base_1 = __nccwpck_require__(8824); class IssueHelperEngine { constructor(ctx) { this.ctx = ctx; @@ -15439,7 +15445,8 @@ class IssueHelperEngine { } 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')); } } exports.IssueHelperEngine = IssueHelperEngine; @@ -15528,7 +15535,7 @@ class IssueCoreEngine { this.octokit = new rest_1.Octokit({ auth: `token ${_info.token}` }); } else { - console && console.error && console.error(`Init failed, need owner、repo!`); + console.error(`Init failed, need owner、repo!`); } } // Allow modify issue number in this way @@ -15798,7 +15805,7 @@ class IssueCoreEngine { return __awaiter(this, void 0, void 0, function* () { const { owner, repo, octokit, issueNumber } = this; const issue = yield this.getIssue(); - const { body: baseBody, title: baseTitle, labels: baseLabels, assignees: baseAssigness, state: baseState } = issue; + const { body: baseBody, title: baseTitle, labels: baseLabels, assignees: baseAssigness, state: baseState, } = issue; const baseLabelsName = baseLabels.map(({ name }) => name); const baseAssignessName = baseAssigness === null || baseAssigness === void 0 ? void 0 : baseAssigness.map(({ login }) => login); const newBody = body ? (mode === 'append' ? `${baseBody}\n${body}` : body) : baseBody; @@ -15864,8 +15871,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -const actions_util_1 = __nccwpck_require__(6972); const github = __importStar(__nccwpck_require__(5438)); +const actions_util_1 = __nccwpck_require__(6972); const core = __importStar(__nccwpck_require__(9875)); const helper_1 = __nccwpck_require__(8406); function main() { @@ -15953,7 +15960,11 @@ const getPreMonth = (m) => { exports.getPreMonth = getPreMonth; // replace some & split & cull empty const replaceStr2Arr = (str, replace, split) => { - return str.replace(replace, '').trim().split(split).reduce((result, it) => it ? [...result, it.trim()] : result, []); + return str + .replace(replace, '') + .trim() + .split(split) + .reduce((result, it) => (it ? [...result, it.trim()] : result), []); }; exports.replaceStr2Arr = replaceStr2Arr; diff --git a/package.json b/package.json index c528d36..e398f5b 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,6 @@ { "private": true, "description": "A GitHub Action easily helps you automatically manage issues.", - "keywords": [ - "actions", - "issue", - "helper", - "github" - ], "repository": { "type": "git", "url": "https://github.com/actions-cool/issues-helper.git", @@ -14,7 +8,6 @@ }, "license": "MIT", "author": "xrkffgg", - "main": "src/main.ts", "scripts": { "dev": "APP_ROOT=web dumi dev", "start": "APP_ROOT=web dumi dev", @@ -22,10 +15,10 @@ "docs-dev:build": "APP_ROOT=web UMI_ENV=dev dumi build", "docs:deploy": "gh-pages -d docs-dist", "deploy": "npm run docs:build && npm run docs:deploy", - "format": "prettier --write **/*.ts", - "format-check": "prettier --check **/*.ts", - "lint": "eslint src/*.ts", - "lint-fix": "eslint src/*.ts --fix", + "format": "prettier --write **/*.ts **/*/*.ts", + "format-check": "prettier --check **/*.ts **/*/*.ts", + "lint": "eslint src/*.ts src/*/*.ts", + "lint-fix": "eslint src/*.ts src/*/*.ts --fix", "check-commit": "node ./scripts/check-commit.js", "tag": "node ./scripts/tag.js", "release": "node ./scripts/release", diff --git a/src/core/index.ts b/src/core/index.ts index 5b5b07a..86d3957 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -2,23 +2,23 @@ import * as core from '@actions/core'; export const baseInfo = (mess: string) => { core.info(mess); -} +}; export const info = (mess: string) => { core.info(`[📝 AC] ${mess}`); -} +}; export const error = (mess: string) => { core.error(`[💥 AC] ${mess}`); -} +}; export const notice = (mess: string) => { core.notice(`[🏷 AC] ${mess}`); -} +}; export const warning = (mess: string) => { core.warning(`[🎃 AC] ${mess}`); -} +}; export const getInput = core.getInput; @@ -26,4 +26,4 @@ export const setOutput = core.setOutput; export const setFailed = (mess: string) => { core.setFailed(`[🚨 AC] ${mess}`); -} +}; diff --git a/src/helper/advanced.ts b/src/helper/advanced.ts index 017e92e..c6b0bec 100644 --- a/src/helper/advanced.ts +++ b/src/helper/advanced.ts @@ -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 { +export async function doQueryIssues( + state: TIssueState | 'all', + creator?: string, + ignoreLabels?: boolean, +): Promise { 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)) { diff --git a/src/helper/base.ts b/src/helper/base.ts index aa2d5db..1b20986 100644 --- a/src/helper/base.ts +++ b/src/helper/base.ts @@ -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!`); diff --git a/src/helper/helper.ts b/src/helper/helper.ts index 6cefe58..94cadfe 100644 --- a/src/helper/helper.ts +++ b/src/helper/helper.ts @@ -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') + ); } } diff --git a/src/helper/types.ts b/src/helper/types.ts index 2718250..0a01fdf 100644 --- a/src/helper/types.ts +++ b/src/helper/types.ts @@ -1,5 +1,5 @@ -import { TAction } from '../types'; +import type { TAction } from '../types'; export interface IIssueHelperEngine { - doExeAction(action: TAction): Promise; + doExeAction: (action: TAction) => Promise; } diff --git a/src/issue/issue.ts b/src/issue/issue.ts index bc2e383..2d695b9 100644 --- a/src/issue/issue.ts +++ b/src/issue/issue.ts @@ -1,7 +1,15 @@ import { Octokit } from '@octokit/rest'; + import { EEmoji } from '../shared'; -import { TEmoji, TLockReasons, TUpdateMode, TIssueState, TUserPermission } from '../types'; -import { IIssueBaseInfo, IIssueCoreEngine, IListIssuesParams, TIssueList, TIssueInfo, TCommentList } from './types'; +import type { TEmoji, TIssueState, TLockReasons, TUpdateMode, TUserPermission } from '../types'; +import type { + IIssueBaseInfo, + IIssueCoreEngine, + IListIssuesParams, + TCommentList, + TIssueInfo, + TIssueList, +} from './types'; export class IssueCoreEngine implements IIssueCoreEngine { private owner!: string; @@ -16,7 +24,7 @@ export class IssueCoreEngine implements IIssueCoreEngine { this.issueNumber = _info.issueNumber; this.octokit = new Octokit({ auth: `token ${_info.token}` }); } else { - console && console.error && console.error(`Init failed, need owner、repo!`); + console.error(`Init failed, need owner、repo!`); } } @@ -80,7 +88,12 @@ export class IssueCoreEngine implements IIssueCoreEngine { } } - public async createIssue(title: string, body: string, labels?: string[], assignees?: string[]): Promise { + public async createIssue( + title: string, + body: string, + labels?: string[], + assignees?: string[], + ): Promise { const { owner, repo, octokit } = this; const { data } = await octokit.issues.create({ owner, @@ -107,7 +120,11 @@ export class IssueCoreEngine implements IIssueCoreEngine { } } - public async createLabel(labelName: string, labelColor: string, labelDescription: string | undefined) { + public async createLabel( + labelName: string, + labelColor: string, + labelDescription: string | undefined, + ) { const { owner, repo, octokit } = this; await octokit.issues.createLabel({ owner, @@ -185,7 +202,7 @@ export class IssueCoreEngine implements IIssueCoreEngine { owner, repo, issue_number: issueNumber, - } + }; if (lockReason) { params.lock_reason = lockReason; } @@ -275,10 +292,23 @@ export class IssueCoreEngine implements IIssueCoreEngine { }); } - public async updateIssue(state: TIssueState, title: string | void, body: string | void, mode: TUpdateMode, labels?: string[] | void, assignees?: string[] | void) { + public async updateIssue( + state: TIssueState, + title: string | void, + body: string | void, + mode: TUpdateMode, + labels?: string[] | void, + assignees?: string[] | void, + ) { const { owner, repo, octokit, issueNumber } = this; const issue = await this.getIssue(); - const { body: baseBody, title: baseTitle, labels: baseLabels, assignees: baseAssigness, state: baseState } = issue; + const { + body: baseBody, + title: baseTitle, + labels: baseLabels, + assignees: baseAssigness, + state: baseState, + } = issue; const baseLabelsName = baseLabels.map(({ name }: any) => name); const baseAssignessName = baseAssigness?.map(({ login }: any) => login); diff --git a/src/issue/types.ts b/src/issue/types.ts index 8154d46..8d21eb7 100644 --- a/src/issue/types.ts +++ b/src/issue/types.ts @@ -1,4 +1,4 @@ -import { TEmoji, TLockReasons, TIssueState, TUpdateMode, TUserPermission } from '../types'; +import type { TEmoji, TIssueState, TLockReasons, TUpdateMode, TUserPermission } from '../types'; export interface IIssueBaseInfo { owner: string; @@ -32,7 +32,7 @@ export type TIssueInfo = { created_at: string; updated_at: string; pull_request?: any; -} +}; export type TIssueList = TIssueInfo[]; @@ -44,22 +44,22 @@ export type TCommentInfo = { }; created_at: string; updated_at: string; -} +}; export type TCommentList = TCommentInfo[]; export interface IIssueCoreEngine { - setIssueNumber(newIssueNumber: number): void; - addAssignees(assignees: string[]): Promise; - addLabels(labels: string[]): Promise; + setIssueNumber: (newIssueNumber: number) => void; + addAssignees: (assignees: string[]) => Promise; + addLabels: (labels: string[]) => Promise; - closeIssue(): Promise; + closeIssue: () => Promise; /** * @param body The comment body. * @returns The create new comment id. */ - createComment(body: string): Promise; - createCommentEmoji(commentId: number, emoji: TEmoji[]): Promise; + createComment: (body: string) => Promise; + createCommentEmoji: (commentId: number, emoji: TEmoji[]) => Promise; /** * @param title * @param body @@ -67,28 +67,44 @@ export interface IIssueCoreEngine { * @param assignees * @returns The create new issue number. */ - createIssue(title: string, body: string, labels: string[] | void, assignees: string[] | void): Promise; - createIssueEmoji(emoji: TEmoji[]): Promise; - createLabel(labelName: string, labelColor: string, labelDescription: string | undefined): Promise; + createIssue: ( + title: string, + body: string, + labels?: string[], + assignees?: string[], + ) => Promise; + createIssueEmoji: (emoji: TEmoji[]) => Promise; + createLabel: ( + labelName: string, + labelColor: string, + labelDescription: string | undefined, + ) => Promise; - deleteComment(commentId: number): Promise; + deleteComment: (commentId: number) => Promise; - getIssue(): Promise; - getUserPermission(username: string): Promise; + getIssue: () => Promise; + getUserPermission: (username: string) => Promise; - listComments(): Promise; - listIssues(params: IListIssuesParams): Promise; - lockIssue(lockReason: TLockReasons): Promise; + listComments: () => Promise; + listIssues: (params: IListIssuesParams) => Promise; + lockIssue: (lockReason: TLockReasons) => Promise; - openIssue(): Promise; + openIssue: () => Promise; - removeAssignees(assignees: string[]): Promise; - removeLabels(labels: string[]): Promise; + removeAssignees: (assignees: string[]) => Promise; + removeLabels: (labels: string[]) => Promise; - setLabels(labels: string[]): Promise; + setLabels: (labels: string[]) => Promise; - unlockIssue(): Promise; + unlockIssue: () => Promise; - updateComment(commentId: number, body: string, mode: TUpdateMode): Promise; - updateIssue(state: TIssueState, title: string | void, body: string | void, mode: TUpdateMode, labels?: string[] | void, assignees?: string[] | void): Promise; + updateComment: (commentId: number, body: string, mode: TUpdateMode) => Promise; + updateIssue: ( + state: TIssueState, + title: string | void, + body: string | void, + mode: TUpdateMode, + labels?: string[] | void, + assignees?: string[] | void, + ) => Promise; } diff --git a/src/main.ts b/src/main.ts index 65309bf..f16960d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,5 @@ -import { dealStringToArr, THANKS } from 'actions-util'; - import * as github from '@actions/github'; +import { dealStringToArr, THANKS } from 'actions-util'; import * as core from './core'; import { IssueHelperEngine } from './helper'; diff --git a/src/util/index.ts b/src/util/index.ts index 99783a5..3b07b64 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -7,25 +7,29 @@ export const dealRandomAssignees = (assignees: string, randomTo: string | void): arr = sampleSize(arr, Number(randomTo)); } return arr; -} +}; export const matchKeyword = (content: string, keywords: string[]): boolean => { return !!keywords.find(item => content.toLowerCase().includes(item)); -} +}; export const checkDuplicate = (body: string | void): boolean => { if (!body || !body.startsWith('Duplicate of')) { return false; } const arr = body.split(' '); - return arr[0] == 'Duplicate' && arr[1] == 'of' -} + return arr[0] == 'Duplicate' && arr[1] == 'of'; +}; export const getPreMonth = (m: number): number => { return m == 1 ? 12 : m - 1; -} +}; // replace some & split & cull empty export const replaceStr2Arr = (str: string, replace: string, split: string): string[] => { - return str.replace(replace, '').trim().split(split).reduce((result: string[], it) => it ? [...result, it.trim()] : result, []); -} + return str + .replace(replace, '') + .trim() + .split(split) + .reduce((result: string[], it) => (it ? [...result, it.trim()] : result), []); +};