|
1 |
| -const actions = require('../../actions'); |
| 1 | +import { Action } from '../../actions'; |
2 | 2 |
|
3 |
| -const exec = async (req) => { |
| 3 | +const exec = async (req: { originalUrl: string; method: string; headers: Record<string, string> }) => { |
4 | 4 | const id = Date.now();
|
5 | 5 | const timestamp = id;
|
6 | 6 | const repoName = getRepoNameFromUrl(req.originalUrl);
|
7 | 7 | const paths = req.originalUrl.split('/');
|
8 | 8 |
|
9 | 9 | let type = 'default';
|
10 | 10 |
|
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') { |
12 | 12 | type = 'pull';
|
13 | 13 | }
|
14 | 14 | 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' |
18 | 18 | ) {
|
19 | 19 | type = 'push';
|
20 | 20 | }
|
21 |
| - return new actions.Action(id, type, req.method, timestamp, repoName); |
| 21 | + |
| 22 | + return new Action(id.toString(), type, req.method, timestamp, repoName); |
22 | 23 | };
|
23 | 24 |
|
24 |
| -const getRepoNameFromUrl = (url) => { |
| 25 | +const getRepoNameFromUrl = (url: string): string => { |
25 | 26 | const parts = url.split('/');
|
26 | 27 | for (let i = 0, len = parts.length; i < len; i++) {
|
27 | 28 | const part = parts[i];
|
28 | 29 | if (part.endsWith('.git')) {
|
29 |
| - const repo = `${parts[i - 1]}/${part}`; |
30 |
| - return repo.trim(); |
| 30 | + return `${parts[i - 1]}/${part}`.trim(); |
31 | 31 | }
|
32 | 32 | }
|
33 | 33 | return 'NOT-FOUND';
|
34 | 34 | };
|
35 | 35 |
|
36 | 36 | exec.displayName = 'parseAction.exec';
|
37 |
| -exports.exec = exec; |
| 37 | + |
| 38 | +export { exec }; |
0 commit comments