Skip to content

Commit 3bebcd7

Browse files
authored
Merge pull request cangzhang#2 from cangzhang/feat/prettier
feat: add prettier configuration
2 parents ce13a67 + dd8b21c commit 3bebcd7

File tree

9 files changed

+453
-105
lines changed

9 files changed

+453
-105
lines changed

.eslintrc.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/**@type {import('eslint').Linter.Config} */
22
// eslint-disable-next-line no-undef
33
module.exports = {
4-
root: true,
5-
parser: '@typescript-eslint/parser',
6-
plugins: [
7-
'@typescript-eslint',
8-
],
9-
extends: [
10-
'eslint:recommended',
11-
'plugin:@typescript-eslint/recommended',
12-
],
13-
rules: {
14-
'semi': [2, "always"],
15-
'@typescript-eslint/no-unused-vars': 0,
16-
'@typescript-eslint/no-explicit-any': 0,
17-
'@typescript-eslint/explicit-module-boundary-types': 0,
18-
'@typescript-eslint/no-non-null-assertion': 0,
19-
}
4+
root: true,
5+
parser: '@typescript-eslint/parser',
6+
plugins: [
7+
'@typescript-eslint',
8+
],
9+
extends: [
10+
'eslint:recommended',
11+
'plugin:@typescript-eslint/recommended',
12+
],
13+
rules: {
14+
'semi': [2, "always"],
15+
'@typescript-eslint/no-unused-vars': 0,
16+
'@typescript-eslint/no-explicit-any': 0,
17+
'@typescript-eslint/explicit-module-boundary-types': 0,
18+
'@typescript-eslint/no-non-null-assertion': 0,
19+
}
2020
};

.prettierrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
semi: true,
3+
trailingComma: 'all',
4+
singleQuote: true,
5+
jsxSingleQuote: true,
6+
printWidth: 120,
7+
tabWidth: 2
8+
}

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@
105105
"watch:extension": "tsc --watch -p ./src",
106106
"watch:webviews": "webpack --watch --mode development"
107107
},
108+
"husky": {
109+
"hooks": {
110+
"pre-commit": "lint-staged"
111+
}
112+
},
113+
"lint-staged": {
114+
"src/**/*.{ts,tsx,json}": [
115+
"prettier --write"
116+
],
117+
"webview/**/*.{ts,tsx}": [
118+
"prettier --write"
119+
]
120+
},
108121
"dependencies": {
109122
"axios": "^0.21.0",
110123
"isomorphic-git": "^1.8.0",
@@ -120,7 +133,10 @@
120133
"@typescript-eslint/parser": "^4.7.0",
121134
"css-loader": "^5.0.1",
122135
"eslint": "^7.13.0",
136+
"husky": "^4.3.0",
137+
"lint-staged": "^10.5.1",
123138
"npm-run-all": "^4.1.5",
139+
"prettier": "^2.1.2",
124140
"style-loader": "^2.0.0",
125141
"ts-loader": "^8.0.11",
126142
"typescript": "^4.0.5",

src/services/codingServer.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export default class CodingServer {
1515
if (session) {
1616
this._session = session;
1717
}
18-
1918
if (repo) {
2019
this._repo = repo;
2120
}
@@ -34,12 +33,14 @@ export default class CodingServer {
3433
return parseCloneUrl(remotes[0].url);
3534
} catch {
3635
console.error('该目录没有进行git初始化');
37-
}
36+
}
3837
}
3938

4039
async getUserInfo(team: string, token: string = this._session?.accessToken || ``) {
4140
try {
42-
const result = await axios.get(`https://${team}.coding.net/api/current_user`, {
41+
const result = await axios({
42+
method: 'get',
43+
url: `https://${team}.coding.net/api/current_user`,
4344
params: {
4445
access_token: token,
4546
},
@@ -59,20 +60,21 @@ export default class CodingServer {
5960
async getMrList(
6061
team: string = this._repo.team,
6162
project: string = this._repo.project,
62-
repo: string = this._repo.repo
63+
repo: string = this._repo.repo,
6364
) {
64-
return MOCK.MR_LIST.data.list;
6565
try {
6666
const url = `https://${team}.coding.net/api/user/${team}/project/${project}/depot/${repo}/git/merges/query`;
67-
const result = await axios.get(url, {
67+
const result = await axios({
68+
method: 'get',
69+
url,
6870
params: {
6971
status: `open`,
7072
sort: `action_at`,
7173
page: 1,
7274
PageSize: 100,
7375
sortDirection: `DESC`,
7476
access_token: this._session.accessToken,
75-
}
77+
},
7678
});
7779
return result?.data?.list || [];
7880
} catch (err) {
@@ -81,20 +83,21 @@ export default class CodingServer {
8183
}
8284

8385
async getDepotList(team: string = this._repo.team, project: string = this._repo.project) {
84-
return MOCK.DEPOT_LIST.data.depots;
8586
try {
86-
const result = await axios.get(`https://${team}.coding.net/api/user/${team}/project/${project}/repos`, {
87+
const result = await axios({
88+
method: 'get',
89+
url: `https://${team}.coding.net/api/user/${team}/project/${project}/repos`,
8790
params: {
8891
access_token: this._session.accessToken,
89-
}
92+
},
9093
});
9194
return result?.data?.depots || [];
9295
} catch (err) {
9396
throw new Error(err);
9497
}
9598
}
9699

97-
async createProjectAndDepot(team: string, payload: { project: string, depot: string }) {
100+
async createProjectAndDepot(team: string, payload: { project: string; depot: string }) {
98101
return 'createProjectAndDepot';
99102
}
100103

@@ -103,15 +106,15 @@ export default class CodingServer {
103106
const result = await axios({
104107
method: 'post',
105108
url: `https://${team}.coding.net/api/user/${team}/project/${project}/depot?access_token=${this._session.accessToken}`,
106-
header: {
107-
'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'
109+
headers: {
110+
'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
108111
},
109112
data: qs.stringify({
110113
name: depot,
111114
vcsType: 'git',
112115
gitReadmeEnabled: false,
113-
shared: false
114-
})
116+
shared: false,
117+
}),
115118
});
116119
console.log('result => ', result);
117120
} catch (err) {

src/tsconfig.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"compilerOptions": {
3-
"module": "commonjs",
4-
"target": "es6",
5-
"lib": ["es6"],
6-
"outDir": "../out",
7-
"sourceMap": false,
8-
"strict": true,
9-
"rootDir": ".",
10-
"esModuleInterop": true
11-
},
12-
"exclude": ["node_modules"]
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"lib": ["es6"],
6+
"outDir": "../out",
7+
"sourceMap": false,
8+
"strict": true,
9+
"rootDir": ".",
10+
"esModuleInterop": true
11+
},
12+
"exclude": ["node_modules"]
1313
}

src/typings/common.ts

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,61 @@
11
export interface IRepoInfo {
2-
team: string;
3-
project: string;
4-
repo: string;
2+
team: string
3+
project: string
4+
repo: string
55
}
66

77
export enum TokenType {
88
AccessToken = `accessToken`,
9-
RefreshToken = `refreshToken` ,
9+
RefreshToken = `refreshToken`,
1010
}
1111

1212
export interface IUserResponse {
13-
avatar: string;
14-
global_key: string;
15-
name: string;
16-
path: string;
17-
team: string;
13+
avatar: string
14+
global_key: string
15+
name: string
16+
path: string
17+
team: string
1818
}
1919

2020
export interface ISessionData {
21-
id: string;
22-
user: IUserResponse | null;
23-
accessToken: string;
24-
refreshToken: string;
25-
}
26-
27-
export interface RepoInfo {
28-
team: string;
29-
project: string;
30-
repo: string;
21+
id: string
22+
user: IUserResponse | null
23+
accessToken: string
24+
refreshToken: string
3125
}
3226

3327
export interface IUserInfo {
34-
id: number;
28+
id: number
3529
}
3630

3731
export interface IReviewer {
38-
reviewer: IUserInfo;
32+
reviewer: IUserInfo
3933
}
4034

4135
export interface IMRItem {
42-
id: number;
43-
iid: number;
44-
srcBranch: string;
45-
desBranch: string;
46-
title: string;
47-
path: string;
48-
author: IUserInfo;
49-
reviewers: IReviewer[];
36+
id: number
37+
iid: number
38+
srcBranch: string
39+
desBranch: string
40+
title: string
41+
path: string
42+
author: IUserInfo
43+
reviewers: IReviewer[]
5044
}
5145

5246
export interface IDepot {
53-
depotPath: string;
54-
gitHttpsHost: string;
55-
gitHttpsUrl: string;
56-
gitSshHost: string;
57-
gitSshUrl: string;
58-
id: number;
59-
isDefault: boolean;
60-
isSvnHttp: boolean;
61-
name: string;
62-
shared: boolean;
63-
size: number;
64-
status: number;
65-
svnEnabled: boolean;
47+
depotPath: string
48+
gitHttpsHost: string
49+
gitHttpsUrl: string
50+
gitSshHost: string
51+
gitSshUrl: string
52+
id: number
53+
isDefault: boolean
54+
isSvnHttp: boolean
55+
name: string
56+
shared: boolean
57+
size: number
58+
status: number
59+
svnEnabled: boolean
6660
vcsType: 'git' | 'svn'
6761
}

src/utils/axios.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ const handleError = (error: any) => {
1010
};
1111

1212
interface Instance extends AxiosInstance {
13-
(config: AxiosRequestConfig): Promise<any>
13+
(config: AxiosRequestConfig): Promise<any>;
1414
}
1515

16-
const createInstance = (): any => {
16+
const createInstance = (): Instance => {
1717
const instance = axios.create();
1818
instance.interceptors.response.use(handleResponse, handleError);
1919
return instance;
2020
};
2121

22-
export default createInstance();
22+
export default createInstance();

src/utils/repo.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import { RepoInfo, IMRItem, IDepot } from '../typings/common';
1+
import { IRepoInfo, IMRItem, IDepot } from '../typings/common';
22

3-
export function parseCloneUrl(url: string): RepoInfo | null {
4-
const reg = /^(https:\/\/|git@)e\.coding\.net(\/|:)(.*)\.git$/i;
5-
const result = url.match(reg);
3+
export function parseCloneUrl(url: string): IRepoInfo | null {
4+
const reg = /^(https:\/\/|git@)e\.coding\.net(\/|:)(.*)\.git$/i;
5+
const result = url.match(reg);
66

7-
if (!result) {
8-
return null;
9-
}
7+
if (!result) {
8+
return null;
9+
}
1010

11-
const str = result.pop();
12-
if (!str || !str?.includes(`/`)) {
13-
return null;
14-
}
11+
const str = result.pop();
12+
if (!str || !str?.includes(`/`)) {
13+
return null;
14+
}
1515

16-
const [team, project, repo] = str.split(`/`);
17-
return { team, project, repo: repo || project };
16+
const [team, project, repo] = str.split(`/`);
17+
return { team, project, repo: repo || project };
1818
}
1919

2020
export function getMRUrl(team: string, mrItem: IMRItem): string {
21-
return `https://${team}.coding.net${mrItem.path}`;
21+
return `https://${team}.coding.net${mrItem.path}`;
2222
}
2323

2424
export function getDepotUrl(team: string, depot: IDepot): string {
25-
return `https://${team}.coding.net${depot.depotPath}`;
25+
return `https://${team}.coding.net${depot.depotPath}`;
2626
}

0 commit comments

Comments
 (0)