mirror of
https://gitea.com/Lydanne/issues-helper.git
synced 2025-08-22 11:45:48 +08:00
style: format
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
extends: [require.resolve('@umijs/fabric/dist/eslint')],
|
extends: [require.resolve("@umijs/fabric/dist/eslint")],
|
||||||
plugins: ["simple-import-sort"],
|
plugins: ["simple-import-sort"],
|
||||||
rules: {
|
rules: {
|
||||||
"simple-import-sort/imports": "error",
|
"simple-import-sort/imports": "error",
|
||||||
"simple-import-sort/exports": "error",
|
"simple-import-sort/exports": "error",
|
||||||
|
"@typescript-eslint/no-parameter-properties": 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@@ -3,3 +3,4 @@ lib/
|
|||||||
docs-dist/
|
docs-dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
src/.umi/
|
src/.umi/
|
||||||
|
src/main.ts
|
||||||
|
37
dist/index.js
vendored
37
dist/index.js
vendored
@@ -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;
|
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 actions_util_1 = __nccwpck_require__(6972);
|
||||||
const dayjs_1 = __importDefault(__nccwpck_require__(7401));
|
const dayjs_1 = __importDefault(__nccwpck_require__(7401));
|
||||||
const utc_1 = __importDefault(__nccwpck_require__(4359));
|
|
||||||
const isSameOrBefore_1 = __importDefault(__nccwpck_require__(9517));
|
const isSameOrBefore_1 = __importDefault(__nccwpck_require__(9517));
|
||||||
|
const utc_1 = __importDefault(__nccwpck_require__(4359));
|
||||||
const core = __importStar(__nccwpck_require__(9875));
|
const core = __importStar(__nccwpck_require__(9875));
|
||||||
const util_1 = __nccwpck_require__(9604);
|
const util_1 = __nccwpck_require__(9604);
|
||||||
const base_1 = __nccwpck_require__(8824);
|
const base_1 = __nccwpck_require__(8824);
|
||||||
@@ -14620,12 +14620,17 @@ function doQueryIssues(state, creator, ignoreLabels) {
|
|||||||
const issueCreator = core.getInput('issue-creator');
|
const issueCreator = core.getInput('issue-creator');
|
||||||
const issueAssignee = core.getInput('issue-assignee');
|
const issueAssignee = core.getInput('issue-assignee');
|
||||||
const issueMentioned = core.getInput('issue-mentioned');
|
const issueMentioned = core.getInput('issue-mentioned');
|
||||||
issueCreator ? (params.creator = issueCreator) : null;
|
if (issueCreator)
|
||||||
issueAssignee ? (params.assignee = issueAssignee) : null;
|
params.creator = issueCreator;
|
||||||
issueMentioned ? (params.mentioned = issueMentioned) : null;
|
if (issueAssignee)
|
||||||
|
params.assignee = issueAssignee;
|
||||||
|
if (issueMentioned)
|
||||||
|
params.mentioned = issueMentioned;
|
||||||
const labels = core.getInput('labels');
|
const labels = core.getInput('labels');
|
||||||
labels && !ignoreLabels ? params.labels = labels : null;
|
if (labels && !ignoreLabels)
|
||||||
creator ? params.creator = creator : null;
|
params.labels = labels;
|
||||||
|
if (creator)
|
||||||
|
params.creator = creator;
|
||||||
const issuesList = yield ICE.listIssues(params);
|
const issuesList = yield ICE.listIssues(params);
|
||||||
const issues = [];
|
const issues = [];
|
||||||
const issueNumbers = [];
|
const issueNumbers = [];
|
||||||
@@ -14720,7 +14725,8 @@ function doCheckIssue() {
|
|||||||
checkAssignee = true;
|
checkAssignee = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
!checkAssignee ? (checkResult = false) : null;
|
if (!checkAssignee)
|
||||||
|
checkResult = false;
|
||||||
}
|
}
|
||||||
const titleRemove = core.getInput('title-excludes');
|
const titleRemove = core.getInput('title-excludes');
|
||||||
if (!!checkResult && titleRemove) {
|
if (!!checkResult && titleRemove) {
|
||||||
@@ -15229,8 +15235,8 @@ const actions_util_1 = __nccwpck_require__(6972);
|
|||||||
const core = __importStar(__nccwpck_require__(9875));
|
const core = __importStar(__nccwpck_require__(9875));
|
||||||
const issue_1 = __nccwpck_require__(4680);
|
const issue_1 = __nccwpck_require__(4680);
|
||||||
const util_1 = __nccwpck_require__(9604);
|
const util_1 = __nccwpck_require__(9604);
|
||||||
const base_1 = __nccwpck_require__(8824);
|
|
||||||
const advanced_1 = __nccwpck_require__(5745);
|
const advanced_1 = __nccwpck_require__(5745);
|
||||||
|
const base_1 = __nccwpck_require__(8824);
|
||||||
class IssueHelperEngine {
|
class IssueHelperEngine {
|
||||||
constructor(ctx) {
|
constructor(ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
@@ -15439,7 +15445,8 @@ class IssueHelperEngine {
|
|||||||
}
|
}
|
||||||
checkEvent4Mark() {
|
checkEvent4Mark() {
|
||||||
const { ctx } = this;
|
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;
|
exports.IssueHelperEngine = IssueHelperEngine;
|
||||||
@@ -15528,7 +15535,7 @@ class IssueCoreEngine {
|
|||||||
this.octokit = new rest_1.Octokit({ auth: `token ${_info.token}` });
|
this.octokit = new rest_1.Octokit({ auth: `token ${_info.token}` });
|
||||||
}
|
}
|
||||||
else {
|
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
|
// Allow modify issue number in this way
|
||||||
@@ -15798,7 +15805,7 @@ class IssueCoreEngine {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const { owner, repo, octokit, issueNumber } = this;
|
const { owner, repo, octokit, issueNumber } = this;
|
||||||
const issue = yield this.getIssue();
|
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 baseLabelsName = baseLabels.map(({ name }) => name);
|
||||||
const baseAssignessName = baseAssigness === null || baseAssigness === void 0 ? void 0 : baseAssigness.map(({ login }) => login);
|
const baseAssignessName = baseAssigness === null || baseAssigness === void 0 ? void 0 : baseAssigness.map(({ login }) => login);
|
||||||
const newBody = body ? (mode === 'append' ? `${baseBody}\n${body}` : body) : baseBody;
|
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 }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
const actions_util_1 = __nccwpck_require__(6972);
|
|
||||||
const github = __importStar(__nccwpck_require__(5438));
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
|
const actions_util_1 = __nccwpck_require__(6972);
|
||||||
const core = __importStar(__nccwpck_require__(9875));
|
const core = __importStar(__nccwpck_require__(9875));
|
||||||
const helper_1 = __nccwpck_require__(8406);
|
const helper_1 = __nccwpck_require__(8406);
|
||||||
function main() {
|
function main() {
|
||||||
@@ -15953,7 +15960,11 @@ const getPreMonth = (m) => {
|
|||||||
exports.getPreMonth = getPreMonth;
|
exports.getPreMonth = getPreMonth;
|
||||||
// replace some & split & cull empty
|
// replace some & split & cull empty
|
||||||
const replaceStr2Arr = (str, replace, split) => {
|
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;
|
exports.replaceStr2Arr = replaceStr2Arr;
|
||||||
|
|
||||||
|
15
package.json
15
package.json
@@ -1,12 +1,6 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "A GitHub Action easily helps you automatically manage issues.",
|
"description": "A GitHub Action easily helps you automatically manage issues.",
|
||||||
"keywords": [
|
|
||||||
"actions",
|
|
||||||
"issue",
|
|
||||||
"helper",
|
|
||||||
"github"
|
|
||||||
],
|
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/actions-cool/issues-helper.git",
|
"url": "https://github.com/actions-cool/issues-helper.git",
|
||||||
@@ -14,7 +8,6 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "xrkffgg",
|
"author": "xrkffgg",
|
||||||
"main": "src/main.ts",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "APP_ROOT=web dumi dev",
|
"dev": "APP_ROOT=web dumi dev",
|
||||||
"start": "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-dev:build": "APP_ROOT=web UMI_ENV=dev dumi build",
|
||||||
"docs:deploy": "gh-pages -d docs-dist",
|
"docs:deploy": "gh-pages -d docs-dist",
|
||||||
"deploy": "npm run docs:build && npm run docs:deploy",
|
"deploy": "npm run docs:build && npm run docs:deploy",
|
||||||
"format": "prettier --write **/*.ts",
|
"format": "prettier --write **/*.ts **/*/*.ts",
|
||||||
"format-check": "prettier --check **/*.ts",
|
"format-check": "prettier --check **/*.ts **/*/*.ts",
|
||||||
"lint": "eslint src/*.ts",
|
"lint": "eslint src/*.ts src/*/*.ts",
|
||||||
"lint-fix": "eslint src/*.ts --fix",
|
"lint-fix": "eslint src/*.ts src/*/*.ts --fix",
|
||||||
"check-commit": "node ./scripts/check-commit.js",
|
"check-commit": "node ./scripts/check-commit.js",
|
||||||
"tag": "node ./scripts/tag.js",
|
"tag": "node ./scripts/tag.js",
|
||||||
"release": "node ./scripts/release",
|
"release": "node ./scripts/release",
|
||||||
|
@@ -2,23 +2,23 @@ import * as core from '@actions/core';
|
|||||||
|
|
||||||
export const baseInfo = (mess: string) => {
|
export const baseInfo = (mess: string) => {
|
||||||
core.info(mess);
|
core.info(mess);
|
||||||
}
|
};
|
||||||
|
|
||||||
export const info = (mess: string) => {
|
export const info = (mess: string) => {
|
||||||
core.info(`[📝 AC] ${mess}`);
|
core.info(`[📝 AC] ${mess}`);
|
||||||
}
|
};
|
||||||
|
|
||||||
export const error = (mess: string) => {
|
export const error = (mess: string) => {
|
||||||
core.error(`[💥 AC] ${mess}`);
|
core.error(`[💥 AC] ${mess}`);
|
||||||
}
|
};
|
||||||
|
|
||||||
export const notice = (mess: string) => {
|
export const notice = (mess: string) => {
|
||||||
core.notice(`[🏷 AC] ${mess}`);
|
core.notice(`[🏷 AC] ${mess}`);
|
||||||
}
|
};
|
||||||
|
|
||||||
export const warning = (mess: string) => {
|
export const warning = (mess: string) => {
|
||||||
core.warning(`[🎃 AC] ${mess}`);
|
core.warning(`[🎃 AC] ${mess}`);
|
||||||
}
|
};
|
||||||
|
|
||||||
export const getInput = core.getInput;
|
export const getInput = core.getInput;
|
||||||
|
|
||||||
@@ -26,4 +26,4 @@ export const setOutput = core.setOutput;
|
|||||||
|
|
||||||
export const setFailed = (mess: string) => {
|
export const setFailed = (mess: string) => {
|
||||||
core.setFailed(`[🚨 AC] ${mess}`);
|
core.setFailed(`[🚨 AC] ${mess}`);
|
||||||
}
|
};
|
||||||
|
@@ -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 dayjs from 'dayjs';
|
||||||
import utc from 'dayjs/plugin/utc';
|
|
||||||
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
||||||
|
import utc from 'dayjs/plugin/utc';
|
||||||
|
|
||||||
import * as core from '../core';
|
import * as core from '../core';
|
||||||
import { matchKeyword, checkDuplicate, replaceStr2Arr } from '../util';
|
import type { IIssueCoreEngine, IListIssuesParams, TCommentInfo, TIssueList } from '../issue';
|
||||||
import { TIssueState, TOutList, TEmoji } from '../types';
|
import type { TEmoji, TIssueState, TOutList } from '../types';
|
||||||
import { IIssueCoreEngine, IListIssuesParams, TIssueList, TCommentInfo } from '../issue';
|
import { checkDuplicate, matchKeyword, replaceStr2Arr } from '../util';
|
||||||
import {
|
import {
|
||||||
doAddAssignees,
|
doAddAssignees,
|
||||||
doAddLabels,
|
doAddLabels,
|
||||||
|
doCloseIssue,
|
||||||
doCreateComment,
|
doCreateComment,
|
||||||
doCreateCommentEmoji,
|
doCreateCommentEmoji,
|
||||||
doCloseIssue,
|
|
||||||
doLockIssue,
|
doLockIssue,
|
||||||
doUpdateComment,
|
|
||||||
doSetLabels,
|
doSetLabels,
|
||||||
|
doUpdateComment,
|
||||||
} from './base';
|
} from './base';
|
||||||
|
|
||||||
let ICE: IIssueCoreEngine;
|
let ICE: IIssueCoreEngine;
|
||||||
@@ -22,7 +24,11 @@ export function initAdvancedICE(_ICE: IIssueCoreEngine) {
|
|||||||
ICE = _ICE;
|
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 = {
|
const params = {
|
||||||
state,
|
state,
|
||||||
} as IListIssuesParams;
|
} as IListIssuesParams;
|
||||||
@@ -30,14 +36,16 @@ export async function doQueryIssues(state: TIssueState | 'all', creator?: string
|
|||||||
const issueCreator = core.getInput('issue-creator');
|
const issueCreator = core.getInput('issue-creator');
|
||||||
const issueAssignee = core.getInput('issue-assignee');
|
const issueAssignee = core.getInput('issue-assignee');
|
||||||
const issueMentioned = core.getInput('issue-mentioned');
|
const issueMentioned = core.getInput('issue-mentioned');
|
||||||
issueCreator ? (params.creator = issueCreator) : null;
|
|
||||||
issueAssignee ? (params.assignee = issueAssignee) : null;
|
if (issueCreator) params.creator = issueCreator;
|
||||||
issueMentioned ? (params.mentioned = issueMentioned) : null;
|
if (issueAssignee) params.assignee = issueAssignee;
|
||||||
|
if (issueMentioned) params.mentioned = issueMentioned;
|
||||||
|
|
||||||
const labels = core.getInput('labels');
|
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 issuesList = await ICE.listIssues(params);
|
||||||
const issues: TIssueList = [];
|
const issues: TIssueList = [];
|
||||||
@@ -131,7 +139,7 @@ export async function doCheckIssue() {
|
|||||||
checkAssignee = true;
|
checkAssignee = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
!checkAssignee ? (checkResult = false) : null;
|
if (!checkAssignee) checkResult = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const titleRemove = core.getInput('title-excludes');
|
const titleRemove = core.getInput('title-excludes');
|
||||||
@@ -234,8 +242,8 @@ export async function doFindIssues() {
|
|||||||
state: issue.state,
|
state: issue.state,
|
||||||
created: issue.created_at,
|
created: issue.created_at,
|
||||||
updated: issue.updated_at,
|
updated: issue.updated_at,
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
if (direction === 'desc') {
|
if (direction === 'desc') {
|
||||||
issues.reverse();
|
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 duplicateCommand = core.getInput('duplicate-command');
|
||||||
const duplicateLabels = core.getInput('duplicate-labels');
|
const duplicateLabels = core.getInput('duplicate-labels');
|
||||||
const removeLables = core.getInput('remove-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}]`);
|
core.info(`[doWelcome] [${auth}]`);
|
||||||
const issues = await doQueryIssues('all', auth, true);
|
const issues = await doQueryIssues('all', auth, true);
|
||||||
if (issues.length == 0 || (issues.length == 1 && issues[0].number == issueNumber)) {
|
if (issues.length == 0 || (issues.length == 1 && issues[0].number == issueNumber)) {
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
import { dealStringToArr } from 'actions-util';
|
import { dealStringToArr } from 'actions-util';
|
||||||
|
|
||||||
import * as core from '../core';
|
import * as core from '../core';
|
||||||
import { TIssueState, TUpdateMode, TEmoji, TLockReasons } from '../types';
|
import type { IIssueCoreEngine } from '../issue';
|
||||||
import { ELockReasons } from '../shared';
|
import { ELockReasons } from '../shared';
|
||||||
import { IIssueCoreEngine } from '../issue';
|
import type { TEmoji, TIssueState, TLockReasons, TUpdateMode } from '../types';
|
||||||
|
|
||||||
let ICE: IIssueCoreEngine;
|
let ICE: IIssueCoreEngine;
|
||||||
export function initBaseICE(_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) {
|
if (title) {
|
||||||
const issueNumber = await ICE.createIssue(title, body, labels, assignees);
|
const issueNumber = await ICE.createIssue(title, body, labels, assignees);
|
||||||
core.info(`[doCreateIssue] [${title}] success!`);
|
core.info(`[doCreateIssue] [${title}] success!`);
|
||||||
@@ -124,7 +131,12 @@ export async function doUnlockIssue() {
|
|||||||
core.info(`[doUnlockIssue] success!`);
|
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');
|
const commentId = _commentId || core.getInput('comment-id');
|
||||||
if (commentId) {
|
if (commentId) {
|
||||||
await ICE.updateComment(+commentId, body, updateMode);
|
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);
|
if (issueNumber) ICE.setIssueNumber(issueNumber);
|
||||||
await ICE.updateIssue(state, title, body, updateMode, labels, assignees);
|
await ICE.updateIssue(state, title, body, updateMode, labels, assignees);
|
||||||
core.info(`[doUpdateIssue] success!`);
|
core.info(`[doUpdateIssue] success!`);
|
||||||
|
@@ -1,22 +1,28 @@
|
|||||||
// import * as github from '@actions/github';
|
// import * as github from '@actions/github';
|
||||||
import { dealStringToArr } from 'actions-util';
|
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 {
|
import {
|
||||||
initBaseICE,
|
|
||||||
doAddAssignees,
|
doAddAssignees,
|
||||||
doAddLabels,
|
doAddLabels,
|
||||||
doCloseIssue,
|
doCloseIssue,
|
||||||
doCreateComment,
|
doCreateComment,
|
||||||
doCreateCommentEmoji,
|
|
||||||
doCreateIssue,
|
doCreateIssue,
|
||||||
doCreateLabel,
|
doCreateLabel,
|
||||||
doDeleteComment,
|
doDeleteComment,
|
||||||
@@ -28,20 +34,9 @@ import {
|
|||||||
doUnlockIssue,
|
doUnlockIssue,
|
||||||
doUpdateComment,
|
doUpdateComment,
|
||||||
doUpdateIssue,
|
doUpdateIssue,
|
||||||
|
initBaseICE,
|
||||||
} from './base';
|
} from './base';
|
||||||
|
import type { IIssueHelperEngine } from './types';
|
||||||
import {
|
|
||||||
initAdvancedICE,
|
|
||||||
doCheckInactive,
|
|
||||||
doCheckIssue,
|
|
||||||
doCloseIssues,
|
|
||||||
doFindComments,
|
|
||||||
doFindIssues,
|
|
||||||
doLockIssues,
|
|
||||||
doMarkAssignees,
|
|
||||||
doMarkDuplicate,
|
|
||||||
doWelcome,
|
|
||||||
} from './advanced';
|
|
||||||
|
|
||||||
export class IssueHelperEngine implements IIssueHelperEngine {
|
export class IssueHelperEngine implements IIssueHelperEngine {
|
||||||
private ICE!: IIssueCoreEngine;
|
private ICE!: IIssueCoreEngine;
|
||||||
@@ -51,8 +46,8 @@ export class IssueHelperEngine implements IIssueHelperEngine {
|
|||||||
private issueNumber!: number;
|
private issueNumber!: number;
|
||||||
|
|
||||||
private emoji?: string;
|
private emoji?: string;
|
||||||
private labels?: string[] | void;
|
private labels?: string[];
|
||||||
private assignees?: string[] | void;
|
private assignees?: string[];
|
||||||
private title: string = '';
|
private title: string = '';
|
||||||
private body: string = '';
|
private body: string = '';
|
||||||
private state: TIssueState = 'open';
|
private state: TIssueState = 'open';
|
||||||
@@ -249,7 +244,7 @@ export class IssueHelperEngine implements IIssueHelperEngine {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
core.warning(`The ${action} is not allowed.`)
|
core.warning(`The ${action} is not allowed.`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,6 +252,9 @@ export class IssueHelperEngine implements IIssueHelperEngine {
|
|||||||
|
|
||||||
private checkEvent4Mark() {
|
private checkEvent4Mark() {
|
||||||
const { ctx } = this;
|
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')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { TAction } from '../types';
|
import type { TAction } from '../types';
|
||||||
|
|
||||||
export interface IIssueHelperEngine {
|
export interface IIssueHelperEngine {
|
||||||
doExeAction(action: TAction): Promise<void>;
|
doExeAction: (action: TAction) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,15 @@
|
|||||||
import { Octokit } from '@octokit/rest';
|
import { Octokit } from '@octokit/rest';
|
||||||
|
|
||||||
import { EEmoji } from '../shared';
|
import { EEmoji } from '../shared';
|
||||||
import { TEmoji, TLockReasons, TUpdateMode, TIssueState, TUserPermission } from '../types';
|
import type { TEmoji, TIssueState, TLockReasons, TUpdateMode, TUserPermission } from '../types';
|
||||||
import { IIssueBaseInfo, IIssueCoreEngine, IListIssuesParams, TIssueList, TIssueInfo, TCommentList } from './types';
|
import type {
|
||||||
|
IIssueBaseInfo,
|
||||||
|
IIssueCoreEngine,
|
||||||
|
IListIssuesParams,
|
||||||
|
TCommentList,
|
||||||
|
TIssueInfo,
|
||||||
|
TIssueList,
|
||||||
|
} from './types';
|
||||||
|
|
||||||
export class IssueCoreEngine implements IIssueCoreEngine {
|
export class IssueCoreEngine implements IIssueCoreEngine {
|
||||||
private owner!: string;
|
private owner!: string;
|
||||||
@@ -16,7 +24,7 @@ export class IssueCoreEngine implements IIssueCoreEngine {
|
|||||||
this.issueNumber = _info.issueNumber;
|
this.issueNumber = _info.issueNumber;
|
||||||
this.octokit = new Octokit({ auth: `token ${_info.token}` });
|
this.octokit = new Octokit({ auth: `token ${_info.token}` });
|
||||||
} else {
|
} 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<number> {
|
public async createIssue(
|
||||||
|
title: string,
|
||||||
|
body: string,
|
||||||
|
labels?: string[],
|
||||||
|
assignees?: string[],
|
||||||
|
): Promise<number> {
|
||||||
const { owner, repo, octokit } = this;
|
const { owner, repo, octokit } = this;
|
||||||
const { data } = await octokit.issues.create({
|
const { data } = await octokit.issues.create({
|
||||||
owner,
|
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;
|
const { owner, repo, octokit } = this;
|
||||||
await octokit.issues.createLabel({
|
await octokit.issues.createLabel({
|
||||||
owner,
|
owner,
|
||||||
@@ -185,7 +202,7 @@ export class IssueCoreEngine implements IIssueCoreEngine {
|
|||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
issue_number: issueNumber,
|
issue_number: issueNumber,
|
||||||
}
|
};
|
||||||
if (lockReason) {
|
if (lockReason) {
|
||||||
params.lock_reason = 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 { owner, repo, octokit, issueNumber } = this;
|
||||||
const issue = await this.getIssue();
|
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 baseLabelsName = baseLabels.map(({ name }: any) => name);
|
||||||
const baseAssignessName = baseAssigness?.map(({ login }: any) => login);
|
const baseAssignessName = baseAssigness?.map(({ login }: any) => login);
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { TEmoji, TLockReasons, TIssueState, TUpdateMode, TUserPermission } from '../types';
|
import type { TEmoji, TIssueState, TLockReasons, TUpdateMode, TUserPermission } from '../types';
|
||||||
|
|
||||||
export interface IIssueBaseInfo {
|
export interface IIssueBaseInfo {
|
||||||
owner: string;
|
owner: string;
|
||||||
@@ -32,7 +32,7 @@ export type TIssueInfo = {
|
|||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
pull_request?: any;
|
pull_request?: any;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type TIssueList = TIssueInfo[];
|
export type TIssueList = TIssueInfo[];
|
||||||
|
|
||||||
@@ -44,22 +44,22 @@ export type TCommentInfo = {
|
|||||||
};
|
};
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type TCommentList = TCommentInfo[];
|
export type TCommentList = TCommentInfo[];
|
||||||
|
|
||||||
export interface IIssueCoreEngine {
|
export interface IIssueCoreEngine {
|
||||||
setIssueNumber(newIssueNumber: number): void;
|
setIssueNumber: (newIssueNumber: number) => void;
|
||||||
addAssignees(assignees: string[]): Promise<void>;
|
addAssignees: (assignees: string[]) => Promise<void>;
|
||||||
addLabels(labels: string[]): Promise<void>;
|
addLabels: (labels: string[]) => Promise<void>;
|
||||||
|
|
||||||
closeIssue(): Promise<void>;
|
closeIssue: () => Promise<void>;
|
||||||
/**
|
/**
|
||||||
* @param body The comment body.
|
* @param body The comment body.
|
||||||
* @returns The create new comment id.
|
* @returns The create new comment id.
|
||||||
*/
|
*/
|
||||||
createComment(body: string): Promise<number>;
|
createComment: (body: string) => Promise<number>;
|
||||||
createCommentEmoji(commentId: number, emoji: TEmoji[]): Promise<void>;
|
createCommentEmoji: (commentId: number, emoji: TEmoji[]) => Promise<void>;
|
||||||
/**
|
/**
|
||||||
* @param title
|
* @param title
|
||||||
* @param body
|
* @param body
|
||||||
@@ -67,28 +67,44 @@ export interface IIssueCoreEngine {
|
|||||||
* @param assignees
|
* @param assignees
|
||||||
* @returns The create new issue number.
|
* @returns The create new issue number.
|
||||||
*/
|
*/
|
||||||
createIssue(title: string, body: string, labels: string[] | void, assignees: string[] | void): Promise<number>;
|
createIssue: (
|
||||||
createIssueEmoji(emoji: TEmoji[]): Promise<void>;
|
title: string,
|
||||||
createLabel(labelName: string, labelColor: string, labelDescription: string | undefined): Promise<void>;
|
body: string,
|
||||||
|
labels?: string[],
|
||||||
|
assignees?: string[],
|
||||||
|
) => Promise<number>;
|
||||||
|
createIssueEmoji: (emoji: TEmoji[]) => Promise<void>;
|
||||||
|
createLabel: (
|
||||||
|
labelName: string,
|
||||||
|
labelColor: string,
|
||||||
|
labelDescription: string | undefined,
|
||||||
|
) => Promise<void>;
|
||||||
|
|
||||||
deleteComment(commentId: number): Promise<void>;
|
deleteComment: (commentId: number) => Promise<void>;
|
||||||
|
|
||||||
getIssue(): Promise<TIssueInfo>;
|
getIssue: () => Promise<TIssueInfo>;
|
||||||
getUserPermission(username: string): Promise<TUserPermission>;
|
getUserPermission: (username: string) => Promise<TUserPermission>;
|
||||||
|
|
||||||
listComments(): Promise<TCommentList>;
|
listComments: () => Promise<TCommentList>;
|
||||||
listIssues(params: IListIssuesParams): Promise<TIssueList>;
|
listIssues: (params: IListIssuesParams) => Promise<TIssueList>;
|
||||||
lockIssue(lockReason: TLockReasons): Promise<void>;
|
lockIssue: (lockReason: TLockReasons) => Promise<void>;
|
||||||
|
|
||||||
openIssue(): Promise<void>;
|
openIssue: () => Promise<void>;
|
||||||
|
|
||||||
removeAssignees(assignees: string[]): Promise<void>;
|
removeAssignees: (assignees: string[]) => Promise<void>;
|
||||||
removeLabels(labels: string[]): Promise<void>;
|
removeLabels: (labels: string[]) => Promise<void>;
|
||||||
|
|
||||||
setLabels(labels: string[]): Promise<void>;
|
setLabels: (labels: string[]) => Promise<void>;
|
||||||
|
|
||||||
unlockIssue(): Promise<void>;
|
unlockIssue: () => Promise<void>;
|
||||||
|
|
||||||
updateComment(commentId: number, body: string, mode: TUpdateMode): Promise<void>;
|
updateComment: (commentId: number, body: string, mode: TUpdateMode) => Promise<void>;
|
||||||
updateIssue(state: TIssueState, title: string | void, body: string | void, mode: TUpdateMode, labels?: string[] | void, assignees?: string[] | void): Promise<void>;
|
updateIssue: (
|
||||||
|
state: TIssueState,
|
||||||
|
title: string | void,
|
||||||
|
body: string | void,
|
||||||
|
mode: TUpdateMode,
|
||||||
|
labels?: string[] | void,
|
||||||
|
assignees?: string[] | void,
|
||||||
|
) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import { dealStringToArr, THANKS } from 'actions-util';
|
|
||||||
|
|
||||||
import * as github from '@actions/github';
|
import * as github from '@actions/github';
|
||||||
|
import { dealStringToArr, THANKS } from 'actions-util';
|
||||||
|
|
||||||
import * as core from './core';
|
import * as core from './core';
|
||||||
import { IssueHelperEngine } from './helper';
|
import { IssueHelperEngine } from './helper';
|
||||||
|
@@ -7,25 +7,29 @@ export const dealRandomAssignees = (assignees: string, randomTo: string | void):
|
|||||||
arr = sampleSize(arr, Number(randomTo));
|
arr = sampleSize(arr, Number(randomTo));
|
||||||
}
|
}
|
||||||
return arr;
|
return arr;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const matchKeyword = (content: string, keywords: string[]): boolean => {
|
export const matchKeyword = (content: string, keywords: string[]): boolean => {
|
||||||
return !!keywords.find(item => content.toLowerCase().includes(item));
|
return !!keywords.find(item => content.toLowerCase().includes(item));
|
||||||
}
|
};
|
||||||
|
|
||||||
export const checkDuplicate = (body: string | void): boolean => {
|
export const checkDuplicate = (body: string | void): boolean => {
|
||||||
if (!body || !body.startsWith('Duplicate of')) {
|
if (!body || !body.startsWith('Duplicate of')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const arr = body.split(' ');
|
const arr = body.split(' ');
|
||||||
return arr[0] == 'Duplicate' && arr[1] == 'of'
|
return arr[0] == 'Duplicate' && arr[1] == 'of';
|
||||||
}
|
};
|
||||||
|
|
||||||
export const getPreMonth = (m: number): number => {
|
export const getPreMonth = (m: number): number => {
|
||||||
return m == 1 ? 12 : m - 1;
|
return m == 1 ? 12 : m - 1;
|
||||||
}
|
};
|
||||||
|
|
||||||
// replace some & split & cull empty
|
// replace some & split & cull empty
|
||||||
export const replaceStr2Arr = (str: string, replace: string, split: string): string[] => {
|
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), []);
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user