Skip to content

Commit c008381

Browse files
committed
fix(ts): add proper typing to chain module and fix minor issues
1 parent 7108307 commit c008381

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"connect-mongo": "^5.1.0",
4848
"cors": "^2.8.5",
4949
"diff2html": "^3.4.33",
50-
"eslint-plugin-typescript": "^0.14.0",
5150
"express": "^4.18.2",
5251
"express-http-proxy": "^2.0.0",
5352
"express-rate-limit": "^7.1.5",
@@ -101,6 +100,7 @@
101100
"eslint-plugin-prettier": "^5.0.0",
102101
"eslint-plugin-react": "^7.21.5",
103102
"eslint-plugin-standard": "^5.0.0",
103+
"eslint-plugin-typescript": "^0.14.0",
104104
"husky": "^9.0.0",
105105
"mocha": "^10.8.2",
106106
"nyc": "^17.0.0",

src/proxy/chain.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { PluginLoader } from '../plugin';
22
import { Action } from './actions';
33
import * as proc from './processors';
44

5-
const pushActionChain = [
5+
const pushActionChain: ((req: any, action: Action) => Promise<Action>)[] = [
66
proc.push.parsePush,
77
proc.push.checkRepoInAuthorisedList,
88
proc.push.checkCommitMessages,
@@ -18,19 +18,17 @@ const pushActionChain = [
1818
proc.push.blockForAuth,
1919
];
2020

21-
const pullActionChain = [proc.push.checkRepoInAuthorisedList];
21+
const pullActionChain: ((req: any, action: Action) => Promise<Action>)[] = [proc.push.checkRepoInAuthorisedList];
2222

2323
let pluginsInserted = false;
2424

2525
export const executeChain = async (req: any, res: any): Promise<Action> => {
2626
let action: Action;
2727
try {
2828
action = await proc.pre.parseAction(req);
29-
const actions = await getChain(action);
30-
for (const i in actions) {
31-
if (!i) continue;
32-
const fn = actions[i as any];
29+
const actionFns = await getChain(action);
3330

31+
for (const fn of actionFns) {
3432
action = await fn(req, action);
3533
if (!action.continue()) {
3634
return action;
@@ -53,7 +51,7 @@ export const executeChain = async (req: any, res: any): Promise<Action> => {
5351
*/
5452
let chainPluginLoader: PluginLoader;
5553

56-
const getChain = async (action: Action) => {
54+
const getChain = async (action: Action): Promise<((req: any, action: Action) => Promise<Action>)[]> => {
5755
if (chainPluginLoader === undefined) {
5856
console.error(
5957
'Plugin loader was not initialized! This is an application error. Please report it to the GitProxy maintainers. Skipping plugins...',
@@ -77,13 +75,9 @@ const getChain = async (action: Action) => {
7775
// This is set to true so that we don't re-insert the plugins into the chain
7876
pluginsInserted = true;
7977
}
80-
if (action.type === 'pull') {
81-
return pullActionChain;
82-
}
83-
if (action.type === 'push') {
84-
return pushActionChain;
85-
}
86-
if (action.type === 'default') return [];
78+
if (action.type === 'pull') return pullActionChain;
79+
if (action.type === 'push') return pushActionChain;
80+
return [];
8781
};
8882

8983
export default {

src/proxy/processors/push-action/parsePush.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (!fs.existsSync(dir)) {
1212
fs.mkdirSync(dir, { recursive: true });
1313
}
1414

15-
const exec = async (req: any, action: Action): Promise<Action> => {
15+
async function exec(req: any, action: Action): Promise<Action> {
1616
const step = new Step('parsePackFile');
1717

1818
try {

0 commit comments

Comments
 (0)