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

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,
};