Skip to content

Commit ab6c6c5

Browse files
committed
refactor(ts): migrate src/proxy/actions files to TS and ESM
1 parent d478edd commit ab6c6c5

File tree

6 files changed

+152
-197
lines changed

6 files changed

+152
-197
lines changed

src/proxy/actions/Action.js

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

src/proxy/actions/Action.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/** Class representing a Push. */
2+
import { getProxyUrl } from "../../config";
3+
import { Step } from "./Step";
4+
5+
class Action {
6+
steps: Step[] = [];
7+
error: boolean = false;
8+
errorMessage?: string | null;
9+
blocked: boolean = false;
10+
blockedMessage?: string | null;
11+
allowPush: boolean = false;
12+
authorised: boolean = false;
13+
canceled: boolean = false;
14+
rejected: boolean = false;
15+
commitFrom?: string;
16+
commitTo?: string;
17+
branch?: string;
18+
message?: string;
19+
author?: string;
20+
user?: string;
21+
attestation?: string;
22+
lastStep?: Step;
23+
id: string;
24+
type: string;
25+
method: string;
26+
timestamp: number;
27+
project: string;
28+
repoName: string;
29+
url: string;
30+
repo: string;
31+
32+
constructor(id: string, type: string, method: string, timestamp: number, repo: string) {
33+
this.id = id;
34+
this.type = type;
35+
this.method = method;
36+
this.timestamp = timestamp;
37+
this.project = repo.split("/")[0];
38+
this.repoName = repo.split("/")[1];
39+
this.url = `${getProxyUrl()}/${repo}`;
40+
this.repo = repo;
41+
}
42+
43+
/**
44+
* Add a step to the action
45+
* @param {Step} step
46+
*/
47+
addStep(step: Step): void {
48+
this.steps.push(step);
49+
this.lastStep = step;
50+
51+
if (step.blocked) {
52+
this.blocked = true;
53+
this.blockedMessage = step.blockedMessage;
54+
}
55+
56+
if (step.error) {
57+
this.error = true;
58+
this.errorMessage = step.errorMessage;
59+
}
60+
}
61+
62+
getLastStep(): Step | undefined {
63+
return this.lastStep;
64+
}
65+
66+
setCommit(commitFrom: string, commitTo: string): void {
67+
this.commitFrom = commitFrom;
68+
this.commitTo = commitTo;
69+
this.id = `${commitFrom}__${commitTo}`;
70+
}
71+
72+
setBranch(branch: string): void {
73+
this.branch = branch;
74+
}
75+
76+
setMessage(message: string): void {
77+
this.message = message;
78+
}
79+
80+
setAllowPush(): void {
81+
this.allowPush = true;
82+
this.blocked = false;
83+
}
84+
85+
continue(): boolean {
86+
return !(this.error || this.blocked);
87+
}
88+
}
89+
90+
export { Action };

src/proxy/actions/Step.js

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

src/proxy/actions/Step.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { v4 as uuidv4 } from "uuid";
2+
3+
/** Class representing a Push Step. */
4+
class Step {
5+
id: string;
6+
stepName: string;
7+
content: any;
8+
error: boolean;
9+
errorMessage: string | null;
10+
blocked: boolean;
11+
blockedMessage: string | null;
12+
logs: string[] = [];
13+
14+
constructor(
15+
stepName: string,
16+
error: boolean = false,
17+
errorMessage: string | null = null,
18+
blocked: boolean = false,
19+
blockedMessage: string | null = null,
20+
content: any = null
21+
) {
22+
this.id = uuidv4();
23+
this.stepName = stepName;
24+
this.content = content;
25+
this.error = error;
26+
this.errorMessage = errorMessage;
27+
this.blocked = blocked;
28+
this.blockedMessage = blockedMessage;
29+
}
30+
31+
setError(message: string): void {
32+
this.error = true;
33+
this.errorMessage = message;
34+
this.log(message);
35+
}
36+
37+
setContent(content: any): void {
38+
this.log("setting content");
39+
this.content = content;
40+
}
41+
42+
setAsyncBlock(message: string): void {
43+
this.log("setting blocked");
44+
this.blocked = true;
45+
this.blockedMessage = message;
46+
}
47+
48+
log(message: string): void {
49+
const m = `${this.stepName} - ${message}`;
50+
this.logs.push(m);
51+
console.info(m);
52+
}
53+
}
54+
55+
export { Step };

src/proxy/actions/index.js

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

src/proxy/actions/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Action } from './Action';
2+
import { Step } from './Step';
3+
4+
export {
5+
Action,
6+
Step
7+
}

0 commit comments

Comments
 (0)