Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1"
}
},
"prettier": {}
}
18 changes: 5 additions & 13 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function execCommand(
}

export async function runAction(
opticToken: string,
opticToken: string | undefined,
githubToken: string,
{
additionalArgs,
Expand Down Expand Up @@ -50,7 +50,7 @@ export async function runAction(
): Promise<number> {
const failOnCheckError = standardsFail === "true";

const valid = verifyInput(opticToken, eventName, owner, repo);
const valid = verifyInput(eventName, owner, repo);
if (!valid) {
return 1;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -196,7 +188,7 @@ async function parseAndEnsureRef(ref: string): Promise<string | false> {
}

async function diffAll(
token: string,
token: string | undefined,
from: string,
additionalArgs: string | undefined,
headTag: string | undefined
Expand All @@ -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
Expand Down