Skip to content

Commit 60adecd

Browse files
removed zod stripping and created helper
1 parent 0ae4bec commit 60adecd

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

src/main.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as core from "@actions/core";
22
import { CodeJSON } from "./model.js";
33
import * as helpers from "./helper.js";
4-
import { stripOutdatedFields } from "./validation.js";
54

65
const baselineCodeJSON: CodeJSON = {
76
name: "",
@@ -67,6 +66,21 @@ const baselineCodeJSON: CodeJSON = {
6766
maturityModelTier: 0,
6867
};
6968

69+
function filterValidFields(existingCodeJSON: any): Partial<CodeJSON> {
70+
const validKeys = new Set(Object.keys(baselineCodeJSON));
71+
const filtered: any = {};
72+
73+
for (const key of Object.keys(existingCodeJSON)) {
74+
if (validKeys.has(key)) {
75+
filtered[key] = existingCodeJSON[key];
76+
} else {
77+
core.info(`Removing outdated field from current code.json: ${key}`);
78+
}
79+
}
80+
81+
return filtered as Partial<CodeJSON>;
82+
}
83+
7084
async function getMetaData(
7185
existingCodeJSON?: CodeJSON | null,
7286
): Promise<Partial<CodeJSON>> {
@@ -148,9 +162,12 @@ export async function run(): Promise<void> {
148162
let finalCodeJSON = {} as CodeJSON;
149163

150164
if (currentCodeJSON) {
165+
// filter out outdated fields before merging
166+
const filteredExisting = filterValidFields(currentCodeJSON);
167+
151168
finalCodeJSON = {
152169
...baselineCodeJSON,
153-
...currentCodeJSON,
170+
...filteredExisting,
154171
...metaData,
155172
};
156173
} else {
@@ -160,8 +177,6 @@ export async function run(): Promise<void> {
160177
};
161178
}
162179

163-
finalCodeJSON = stripOutdatedFields(finalCodeJSON)
164-
165180
core.info("Generated code.json successfully!");
166181

167182
const baseBranchName = await helpers.getBaseBranch();
@@ -188,4 +203,4 @@ export async function run(): Promise<void> {
188203
} catch (error) {
189204
core.setFailed(`Action failed: ${error}`);
190205
}
191-
}
206+
}

src/validation.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,3 @@ export function validateCodeJSON(codeJSON: any): string[] {
127127
return `${field}: ${err.message}`;
128128
});
129129
}
130-
131-
export function stripOutdatedFields(codeJSON: any): any {
132-
try {
133-
return CodeJSONSchema.loose().parse(codeJSON)
134-
} catch (error) {
135-
return codeJSON
136-
}
137-
}

0 commit comments

Comments
 (0)