diff --git a/action.yml b/action.yml index fc328ab..5f31d32 100644 --- a/action.yml +++ b/action.yml @@ -2,8 +2,8 @@ name: "Optic" description: "Run Optic against the current commit" inputs: optic_token: - description: "Your organization's Optic token" - required: true + description: "Your organization's Optic token to use Optic cloud" + required: false github_token: description: "A GitHub token that can append comments to a PR" required: true diff --git a/build/index.js b/build/index.js index c546c21..b9475fd 100644 --- a/build/index.js +++ b/build/index.js @@ -4001,7 +4001,7 @@ async function execCommand(command, args, options = {}, logError = true) { } async function runAction(opticToken, githubToken, { additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha, refName, compareFromPush, compareFromPr, }) { const failOnCheckError = standardsFail === "true"; - const valid = verifyInput(opticToken, eventName, owner, repo); + const valid = verifyInput(eventName, owner, repo); if (!valid) { return 1; } @@ -4057,11 +4057,7 @@ async function runAction(opticToken, githubToken, { additionalArgs, standardsFai return 0; } exports.runAction = runAction; -function verifyInput(token, eventName, owner, repo) { - if (!token) { - core.error("No token was provided. You can generate a token through our app at https://app.useoptic.com"); - return false; - } +function verifyInput(eventName, owner, repo) { if (eventName !== "push" && eventName !== "pull_request") { core.error("Only 'push' and 'pull_request' events are supported."); return false; @@ -4115,11 +4111,11 @@ async function diffAll(token, from, additionalArgs, headTag) { "--compare-from", from, "--check", - "--upload", + ...(token ? ["--upload"] : []), ...(headTag ? ["--head-tag", headTag] : []), ...(additionalArgs ? [...additionalArgs.split(" ")] : []), ], { - env: Object.assign(Object.assign({}, process.env), { OPTIC_TOKEN: token }), + env: Object.assign(Object.assign({}, process.env), (token ? { OPTIC_TOKEN: token } : {})), }, false); } async function prComment(githubToken, owner, repo, pr, sha) { diff --git a/package.json b/package.json index 39822c8..d22d972 100644 --- a/package.json +++ b/package.json @@ -46,5 +46,6 @@ "dependencies": { "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1" - } + }, + "prettier": {} } diff --git a/src/action.ts b/src/action.ts index f190f80..bccee3a 100644 --- a/src/action.ts +++ b/src/action.ts @@ -20,7 +20,7 @@ async function execCommand( } export async function runAction( - opticToken: string, + opticToken: string | undefined, githubToken: string, { additionalArgs, @@ -50,7 +50,7 @@ export async function runAction( ): Promise { const failOnCheckError = standardsFail === "true"; - const valid = verifyInput(opticToken, eventName, owner, repo); + const valid = verifyInput(eventName, owner, repo); if (!valid) { return 1; } @@ -129,18 +129,10 @@ export async function runAction( } function verifyInput( - token: string, eventName: string | undefined, owner: string | undefined, repo: string | undefined ): boolean { - if (!token) { - core.error( - "No token was provided. You can generate a token through our app at https://app.useoptic.com" - ); - return false; - } - if (eventName !== "push" && eventName !== "pull_request") { core.error("Only 'push' and 'pull_request' events are supported."); return false; @@ -196,7 +188,7 @@ async function parseAndEnsureRef(ref: string): Promise { } async function diffAll( - token: string, + token: string | undefined, from: string, additionalArgs: string | undefined, headTag: string | undefined @@ -210,14 +202,14 @@ async function diffAll( "--compare-from", from, "--check", - "--upload", + ...(token ? ["--upload"] : []), ...(headTag ? ["--head-tag", headTag] : []), ...(additionalArgs ? [...additionalArgs.split(" ")] : []), ], { env: { ...process.env, - OPTIC_TOKEN: token, + ...(token ? { OPTIC_TOKEN: token } : {}), }, }, false