11import * as core from "@actions/core" ;
22import { CodeJSON } from "./model.js" ;
33import * as helpers from "./helper.js" ;
4- import { stripOutdatedFields } from "./validation.js" ;
54
65const 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+
7084async 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+ }
0 commit comments