feat: refactor 3.0

This commit is contained in:
元凛
2021-10-09 17:56:47 +08:00
parent dc85436cff
commit 03531cdc76
46 changed files with 119065 additions and 3393 deletions

8
.eslintignore Normal file
View File

@@ -0,0 +1,8 @@
es/**/*
lib/**/*
node_modules
_site
dist
coverage
**/*.d.ts
.eslintrc.js

8
.eslintrc.js Normal file
View File

@@ -0,0 +1,8 @@
module.exports = {
extends: [require.resolve('@umijs/fabric/dist/eslint')],
plugins: ["simple-import-sort"],
rules: {
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
},
};

2
.gitignore vendored
View File

@@ -18,7 +18,7 @@ yarn-error.log*
# dependencies
node_modules
# yarn.lock
yarn.lock
package-lock.json
# local env files

View File

@@ -3,4 +3,6 @@ const fabric = require('@umijs/fabric');
module.exports = {
...fabric.prettier,
arrowParens: 'avoid',
importOrder: ['^@formily/(.*)', '^@(.*)$', '^[./]'],
importOrderSeparation: true,
};

View File

@@ -1,50 +1,59 @@
{
"name": "issues-helper",
"version": "2.4.3",
"private": true,
"description": "A GitHub Action easily helps you automatically manage issues.",
"main": "src/main.js",
"scripts": {
"start": "dumi dev",
"docs:build": "dumi build",
"docs-dev:build": "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 **/*.js",
"format-check": "prettier --check **/*.ts **/*.js",
"test": "father test",
"package": "ncc build src/main.js -o dist",
"users": "node ./script/update-users.js",
"main": "node ./src/main.js",
"ver": "node ./script/update-version.js",
"pub": "npm run package"
},
"author": "xrkffgg",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/actions-cool/issues-helper.git",
"branch": "main"
},
"keywords": [
"actions",
"issue",
"helper",
"github"
],
"repository": {
"type": "git",
"url": "https://github.com/actions-cool/issues-helper.git",
"branch": "main"
},
"license": "MIT",
"author": "xrkffgg",
"main": "src/main.js",
"scripts": {
"start": "APP_ROOT=web dumi dev",
"docs:build": "APP_ROOT=web dumi build",
"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",
"test": "father test",
"package": "ncc build src/main.ts -o dist",
"users": "node ./script/update-users.js",
"main": "node ./src/main.js",
"ver": "node ./script/update-version.js",
"pub": "npm run package",
"all": "npm run format-check && npm run lint && npm run package"
},
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0",
"@octokit/rest": "^18.0.12",
"actions-util": "^1.0.0",
"dayjs": "^1.9.7",
"father": "^2.30.7",
"lodash": "^4.17.20"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^2.0.4",
"@types/lodash": "^4.14.175",
"@typescript-eslint/parser": "^4.15.2",
"@umijs/fabric": "^2.5.6",
"@vercel/ncc": "^0.25.1",
"@vercel/ncc": "^0.27.0",
"common-tags": "^1.8.0",
"dumi": "^1.1.26",
"gh-pages": "^3.1.0"
"eslint": "^7.18.0",
"eslint-plugin-github": "^4.1.1",
"eslint-plugin-simple-import-sort": "^7.0.0",
"father": "^2.30.7",
"gh-pages": "^3.1.0",
"prettier": "^2.2.1",
"typescript": "^4.1.3"
}
}

View File

@@ -1,4 +0,0 @@
// For dumi style
import '../less/main.less';
import '../less/markdown.less';
import '../less/dumi.less';

2
src/issue/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export * from './issue';
export * from './types';

1
src/issue/issue.ts Normal file
View File

@@ -0,0 +1 @@
export class IssueCoreEngine

36
src/issue/types.ts Normal file
View File

@@ -0,0 +1,36 @@
import { TEmoji, TLockReasons, TStringOrVoid } from '../types';
export interface IIssueBaseInfo {
owner: string;
repo: string;
issueNunber: string | void;
}
export interface IIssueCoreEngine {
addAssignees(assignees: string[]): void;
addLabels(labels: string[]): void;
closeIssue(): void;
/**
* @param body The comment body.
* @returns The create new comment id.
*/
createComment(body: string): string;
createCommentEmoji(emoji: TEmoji): void;
/**
* @param title
* @param body
* @param labels
* @param assignees
* @returns The create new issue number.
*/
createIssue(title: string, body: TStringOrVoid, labels: string[], assignees: string[]): string;
createIssueEmoji(emoji: TEmoji): void;
createLabel(labelName: string, labelColor: string, labelDescription: TStringOrVoid): void;
deleteComment(commentId: string): void;
lockIssue(lockReason: TLockReasons): void;
}

0
src/main.ts Normal file
View File

17
src/shared.ts Normal file
View File

@@ -0,0 +1,17 @@
export const EEmoji = {
'+1': '+1',
'-1': '-1',
'laugh': 'laugh',
'confused': 'confused',
'heart': 'heart',
'hooray': 'hooray',
'rocket': 'rocket',
'eyes': 'eyes',
}
export const ELockReasons = {
'off-topic': 'off-topic',
'too heated': 'too heated',
'resolved': 'resolved',
'spam': 'spam',
}

5
src/types.ts Normal file
View File

@@ -0,0 +1,5 @@
export type TEmoji = '+1' | '-1' | 'laugh' | 'confused' | 'heart' | 'hooray' | 'rocket' | 'eyes';
export type TLockReasons = 'off-topic' | 'too heated' | 'resolved' | 'spam';
export type TStringOrVoid = string | void;

View File

@@ -1,23 +1,8 @@
const sampleSize = require('lodash/sampleSize');
import sampleSize from 'lodash/sampleSize';
import { dealStringToArr } from 'actions-util';
export { dealStringToArr };
function dealStringToArr(para) {
/**
* in 'x1,x2,x3'
* out ['x1','x2','x3']
*/
let arr = [];
if (para) {
const paraArr = para.split(',');
paraArr.forEach(it => {
if (it.trim()) {
arr.push(it.trim());
}
});
}
return arr;
}
function dealRandomAssignees(assignees, randomTo) {
export const dealRandomAssignees = (assignees: string, randomTo: number): string[] => {
let arr = dealStringToArr(assignees);
if (randomTo && Number(randomTo) > 0 && Number(randomTo) < arr.length) {
arr = sampleSize(arr, randomTo);
@@ -25,11 +10,11 @@ function dealRandomAssignees(assignees, randomTo) {
return arr;
}
function matchKeyword(content, keywords) {
export const matchKeyword = (content: string, keywords: string[]): string | undefined => {
return keywords.find(item => content.toLowerCase().includes(item));
}
function testDuplicate(body) {
export const testDuplicate = (body: string | void): boolean => {
if (!body || !body.startsWith('Duplicate of')) {
return false;
}
@@ -42,11 +27,11 @@ function testDuplicate(body) {
}
}
function getPreMonth(m) {
export const getPreMonth = (m: number): number => {
return m == 1 ? 12 : m - 1;
}
function checkPermission(require, permission) {
export const checkPermission = (require: string, permission: string): boolean => {
/**
* true
*/
@@ -56,13 +41,3 @@ function checkPermission(require, permission) {
return requireNo <= permissionNo;
}
// **********************************************************
module.exports = {
dealStringToArr,
dealRandomAssignees,
getPreMonth,
matchKeyword,
testDuplicate,
checkPermission,
};

74
tsconfig.json Normal file
View File

@@ -0,0 +1,74 @@
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es6",
/* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs",
/* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib",
/* Redirect output structure to the directory. */
"rootDir": "./src",
/* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true,
/* Enable all strict type-checking options. */
"noImplicitAny": true,
/* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true
/* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"exclude": [
"node_modules",
"lib",
"**/*.test.ts"
]
}

View File

@@ -10,7 +10,10 @@ export default defineConfig({
logo: 'https://avatars1.githubusercontent.com/u/73879334?s=200&v=4',
exportStatic: {},
ssr: {},
outputPath: 'docs-dist',
outputPath: '../docs-dist',
resolve: {
includes: ['./docs'],
},
hash: true,
base: `/${name}/`,
publicPath: `/${name}/`,

4
web/app.ts Normal file
View File

@@ -0,0 +1,4 @@
// For dumi style
import './less/main.less';
import './less/markdown.less';
import './less/dumi.less';

4
web/docs-dist/umi.server.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
import { IServerRender } from 'umi';
export = render;
export as namespace render;
declare const render: IServerRender;

116705
web/docs-dist/umi.server.js Normal file

File diff suppressed because one or more lines are too long

View File

@@ -35,4 +35,4 @@ toc: menu
- v2 [upgrade reference](/en-US/guide/faq)
<embed src="../CHANGELOG.md"></embed>
<embed src="../../CHANGELOG.md"></embed>

View File

@@ -35,4 +35,4 @@ toc: menu
- v2 [升级参考](/guide/faq)
<embed src="../CHANGELOG.md"></embed>
<embed src="../../CHANGELOG.md"></embed>

View File

@@ -51,7 +51,7 @@ jobs:
## 💖 Who is using?
<embed src="../README.md#RE-/<table>[^]+?[\r\n]<\/table>/"></embed>
<embed src="../../README.md#RE-/<table>[^]+?[\r\n]<\/table>/"></embed>
## ⚡ Feedback

View File

@@ -51,7 +51,7 @@ jobs:
## 💖 谁在使用?
<embed src="../README.md#RE-/<table>[^]+?[\r\n]<\/table>/"></embed>
<embed src="../../README.md#RE-/<table>[^]+?[\r\n]<\/table>/"></embed>
## ⚡ 反馈

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 54 KiB

View File

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

5469
yarn.lock

File diff suppressed because it is too large Load Diff