From 39d5274f43b7f7a3cd79a025016e232a75924fa0 Mon Sep 17 00:00:00 2001 From: jjijon7000 Date: Wed, 15 Jul 2026 15:55:10 -0700 Subject: [PATCH] change that introduces fix to issue 107 --- src/__tests__/unit/main.test.ts | 24 ++++++++++++++++++++++++ src/main.ts | 18 ++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/__tests__/unit/main.test.ts b/src/__tests__/unit/main.test.ts index 475666be..d65be981 100644 --- a/src/__tests__/unit/main.test.ts +++ b/src/__tests__/unit/main.test.ts @@ -152,6 +152,30 @@ describe("runWithDeps", () => { expect(deps.setOutput).toHaveBeenCalledWith("method_used", "pull_request"); }); + it("includes enum keys in the generated blank code.json", async () => { + process.env.GITHUB_EVENT_NAME = "schedule"; + + const deps = createMockDeps({ + readFile: jest.fn().mockRejectedValue(new Error("no file")), + skipPR: false, + }); + + await runWithDeps(deps); + + const createPullRequestMock = deps.octokit.createPullRequest as jest.Mock; + const pullRequestArgs = createPullRequestMock.mock.calls[0][0] as any; + const codeJSONContent = pullRequestArgs.changes[0].files["code.json"]; + const generatedCodeJSON = JSON.parse(codeJSONContent); + + expect(generatedCodeJSON).toHaveProperty("status"); + expect(generatedCodeJSON).toHaveProperty("repositoryHost"); + expect(generatedCodeJSON).toHaveProperty("repositoryVisibility"); + expect(generatedCodeJSON).toHaveProperty("softwareType"); + expect(generatedCodeJSON).toHaveProperty("maintenance"); + expect(generatedCodeJSON).toHaveProperty("repositoryType"); + expect(generatedCodeJSON).toHaveProperty("fismaLevel"); + }); + it("attempts direct push when skipPR is true with admin token", async () => { process.env.GITHUB_EVENT_NAME = "workflow_dispatch"; diff --git a/src/main.ts b/src/main.ts index 496e5729..14c39b1b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,12 +3,14 @@ import { Dependencies } from "./types/Dependencies.js"; import { createHelpers, Helpers } from "./helper.js"; import { createProductionDeps } from "./create-deps.js"; +const blankEnumValue = "" as never; + const baselineCodeJSON: Partial = { name: "", version: "", description: "", longDescription: "", - status: undefined, + status: blankEnumValue, permissions: { licenses: [ { @@ -21,8 +23,8 @@ const baselineCodeJSON: Partial = { }, organization: "Centers for Medicare & Medicaid Services", repositoryURL: "", - repositoryHost: undefined, - repositoryVisibility: undefined, + repositoryHost: blankEnumValue, + repositoryVisibility: blankEnumValue, homepageURL: "", downloadURL: "", disclaimerURL: "", @@ -35,9 +37,9 @@ const baselineCodeJSON: Partial = { }, platforms: [], categories: [], - softwareType: undefined, + softwareType: blankEnumValue, languages: [], - maintenance: undefined, + maintenance: blankEnumValue, contractNumber: [], SBOM: "", relatedCode: [], @@ -56,9 +58,9 @@ const baselineCodeJSON: Partial = { feedbackMechanism: "", AIUseCaseID: "0", localisation: false, - repositoryType: undefined, + repositoryType: blankEnumValue, userInput: false, - fismaLevel: undefined, + fismaLevel: blankEnumValue, group: "", projects: [], systems: [], @@ -151,7 +153,7 @@ async function getMetaData( return { name: partialCodeJSON.name, description: description, - status: status, + status: status ?? blankEnumValue, repositoryURL: partialCodeJSON.repositoryURL, repositoryVisibility: partialCodeJSON.repositoryVisibility, laborHours: partialCodeJSON.laborHours,