Skip to content

Commit

Permalink
Add validation for inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
zachkirsch committed Jan 11, 2023
1 parent 7b9011c commit 877066d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { Collection, CollectionDefinition } from "postman-collection";
import { FernPostmanClient } from "@fern-fern/postman-sdk";
import { readFile } from "fs/promises";

void run();

async function run(): Promise<void> {
try {
const postmanApiKey: string = core.getInput("api-key");
const postmanWorkspaceId: string = core.getInput("workspace-id");
const postmanCollectionPath: string = core.getInput("collection-path");
const postmanApiKey = getStringInputOrThrow("api-key");
const postmanWorkspaceId = getStringInputOrThrow("workspace-id");
const postmanCollectionPath = getStringInputOrThrow("collection-path");

const rawPostmanCollection = JSON.parse(
(await readFile(postmanCollectionPath)).toString()
Expand Down Expand Up @@ -137,4 +139,13 @@ async function run(): Promise<void> {
}
}

run();
function getStringInputOrThrow(key: string): string {
const input: unknown = core.getInput(key);
if (input == null) {
throw new Error(`${key} is not defined.`);
}
if (typeof input !== "string") {
throw new Error(`${key} is not a string.`);
}
return input;
}

0 comments on commit 877066d

Please sign in to comment.