Skip to content

Commit 8a78bae

Browse files
committed
refactor(ts): refactor pre-processor files
1 parent d1160fe commit 8a78bae

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/proxy/processors/pre-processor/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { exec } from './parseAction';
2+
3+
export const parseAction = exec;
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
const actions = require('../../actions');
1+
import { Action } from '../../actions';
22

3-
const exec = async (req) => {
3+
const exec = async (req: { originalUrl: string; method: string; headers: Record<string, string> }) => {
44
const id = Date.now();
55
const timestamp = id;
66
const repoName = getRepoNameFromUrl(req.originalUrl);
77
const paths = req.originalUrl.split('/');
88

99
let type = 'default';
1010

11-
if (paths[paths.length - 1].endsWith('git-upload-pack') && req.method == 'GET') {
11+
if (paths[paths.length - 1].endsWith('git-upload-pack') && req.method === 'GET') {
1212
type = 'pull';
1313
}
1414
if (
15-
paths[paths.length - 1] == 'git-receive-pack' &&
16-
req.method == 'POST' &&
17-
req.headers['content-type'] == 'application/x-git-receive-pack-request'
15+
paths[paths.length - 1] === 'git-receive-pack' &&
16+
req.method === 'POST' &&
17+
req.headers['content-type'] === 'application/x-git-receive-pack-request'
1818
) {
1919
type = 'push';
2020
}
21-
return new actions.Action(id, type, req.method, timestamp, repoName);
21+
22+
return new Action(id.toString(), type, req.method, timestamp, repoName);
2223
};
2324

24-
const getRepoNameFromUrl = (url) => {
25+
const getRepoNameFromUrl = (url: string): string => {
2526
const parts = url.split('/');
2627
for (let i = 0, len = parts.length; i < len; i++) {
2728
const part = parts[i];
2829
if (part.endsWith('.git')) {
29-
const repo = `${parts[i - 1]}/${part}`;
30-
return repo.trim();
30+
return `${parts[i - 1]}/${part}`.trim();
3131
}
3232
}
3333
return 'NOT-FOUND';
3434
};
3535

3636
exec.displayName = 'parseAction.exec';
37-
exports.exec = exec;
37+
38+
export { exec };

0 commit comments

Comments
 (0)