Skip to content

Commit 3d0a486

Browse files
committed
refactor(ts): refactor remaining actions into TS
1 parent 263f3cb commit 3d0a486

File tree

16 files changed

+130
-78
lines changed

16 files changed

+130
-78
lines changed

src/proxy/actions/Action.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ export interface Commit {
1919
* Class representing a Push.
2020
*/
2121
class Action {
22+
id: string;
23+
type: string;
24+
method: string;
25+
timestamp: number;
26+
project: string;
27+
repoName: string;
28+
url: string;
29+
repo: string;
2230
steps: Step[] = [];
2331
error: boolean = false;
2432
errorMessage?: string | null;
@@ -37,14 +45,7 @@ class Action {
3745
user?: string;
3846
attestation?: string;
3947
lastStep?: Step;
40-
id: string;
41-
type: string;
42-
method: string;
43-
timestamp: number;
44-
project: string;
45-
repoName: string;
46-
url: string;
47-
repo: string;
48+
proxyGitPath?: string;
4849

4950
/**
5051
* Create an action.

src/proxy/chain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const proc = require('./processors');
1+
import * as proc from './processors';
22

33
const pushActionChain = [
44
proc.push.parsePush,

src/proxy/processors/index.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/proxy/processors/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as pre from './pre-processor';
2+
import * as push from './push-action';
3+
4+
export { pre, push };

src/proxy/processors/push-action/audit.js

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { writeAudit } from '../../../db';
2+
import { Action } from '../../actions';
3+
4+
const exec = async (req: any, action: Action) => {
5+
if (action.type !== 'pull') {
6+
await writeAudit(action);
7+
}
8+
9+
return action;
10+
};
11+
12+
exec.displayName = 'audit.exec';
13+
14+
export { exec };

src/proxy/processors/push-action/blockForAuth.js renamed to src/proxy/processors/push-action/blockForAuth.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const { getServiceUIURL } = require('../../../service/urls');
1+
import { Action, Step } from '../../actions';
2+
import { getServiceUIURL } from '../../../service/urls';
23

3-
const Step = require('../../actions').Step;
4-
5-
const exec = async (req, action) => {
4+
const exec = async (req: any, action: Action) => {
65
const step = new Step('authBlock');
76
const url = getServiceUIURL(req);
87

@@ -19,4 +18,5 @@ const exec = async (req, action) => {
1918
};
2019

2120
exec.displayName = 'blockForAuth.exec';
22-
exports.exec = exec;
21+
22+
export { exec };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const exec = async (req: any, action: Action): Promise<Action> => {
1212
// Find the user associated with this Git Account
1313
const list = await getUsers({ gitAccount: action.user });
1414

15-
console.log(JSON.stringify(list));
15+
console.log(`Users for this git account: ${JSON.stringify(list)}`);
1616

1717
if (list.length == 1) {
1818
user = list[0].username;

src/proxy/processors/push-action/clearBareClone.js renamed to src/proxy/processors/push-action/clearBareClone.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const Step = require('../../actions').Step;
2-
const fs = require('node:fs');
1+
import { Action, Step } from '../../actions';
2+
import fs from 'node:fs';
33

4-
const exec = async (req, action) => {
4+
const exec = async (req: any, action: Action): Promise<Action> => {
55
const step = new Step('clearBareClone');
66

77
// Recursively remove the contents of ./.remote and ignore exceptions
@@ -17,4 +17,5 @@ const exec = async (req, action) => {
1717
};
1818

1919
exec.displayName = 'clearBareClone.exec';
20-
exports.exec = exec;
20+
21+
export { exec };

src/proxy/processors/push-action/getDiff.js renamed to src/proxy/processors/push-action/getDiff.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const Step = require('../../actions').Step;
2-
const simpleGit = require('simple-git')
1+
import { Action, Step } from '../../actions';
2+
import simpleGit from 'simple-git';
33

4-
5-
const exec = async (req, action) => {
4+
const exec = async (req: any, action: Action): Promise<Action> => {
65
const step = new Step('diff');
76

87
try {
@@ -11,6 +10,10 @@ const exec = async (req, action) => {
1110
// https://stackoverflow.com/questions/40883798/how-to-get-git-diff-of-the-first-commit
1211
let commitFrom = `4b825dc642cb6eb9a060e54bf8d69288fbee4904`;
1312

13+
if (!action.commitData) {
14+
throw new Error('No commit data found');
15+
}
16+
1417
if (action.commitFrom === '0000000000000000000000000000000000000000') {
1518
if (action.commitData[0].parent !== '0000000000000000000000000000000000000000') {
1619
commitFrom = `${action.commitData[action.commitData.length - 1].parent}`;
@@ -24,7 +27,7 @@ const exec = async (req, action) => {
2427
const diff = await git.diff([revisionRange]);
2528
step.log(diff);
2629
step.setContent(diff);
27-
} catch (e) {
30+
} catch (e: any) {
2831
step.setError(e.toString('utf-8'));
2932
} finally {
3033
action.addStep(step);
@@ -33,4 +36,5 @@ const exec = async (req, action) => {
3336
};
3437

3538
exec.displayName = 'getDiff.exec';
36-
exports.exec = exec;
39+
40+
export { exec };

0 commit comments

Comments
 (0)