Skip to content

Commit d1a9e5a

Browse files
Merge pull request #29 from opticdev/remove-token-check
make optic token optional, only upload when token is set
2 parents eeb5f5c + 244d557 commit d1a9e5a

File tree

4 files changed

+13
-24
lines changed

4 files changed

+13
-24
lines changed

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: "Optic"
22
description: "Run Optic against the current commit"
33
inputs:
44
optic_token:
5-
description: "Your organization's Optic token"
6-
required: true
5+
description: "Your organization's Optic token to use Optic cloud"
6+
required: false
77
github_token:
88
description: "A GitHub token that can append comments to a PR"
99
required: true

build/index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4001,7 +4001,7 @@ async function execCommand(command, args, options = {}, logError = true) {
40014001
}
40024002
async function runAction(opticToken, githubToken, { additionalArgs, standardsFail, eventName, headRef, baseRef, owner, repo, sha, refName, compareFromPush, compareFromPr, }) {
40034003
const failOnCheckError = standardsFail === "true";
4004-
const valid = verifyInput(opticToken, eventName, owner, repo);
4004+
const valid = verifyInput(eventName, owner, repo);
40054005
if (!valid) {
40064006
return 1;
40074007
}
@@ -4057,11 +4057,7 @@ async function runAction(opticToken, githubToken, { additionalArgs, standardsFai
40574057
return 0;
40584058
}
40594059
exports.runAction = runAction;
4060-
function verifyInput(token, eventName, owner, repo) {
4061-
if (!token) {
4062-
core.error("No token was provided. You can generate a token through our app at https://app.useoptic.com");
4063-
return false;
4064-
}
4060+
function verifyInput(eventName, owner, repo) {
40654061
if (eventName !== "push" && eventName !== "pull_request") {
40664062
core.error("Only 'push' and 'pull_request' events are supported.");
40674063
return false;
@@ -4115,11 +4111,11 @@ async function diffAll(token, from, additionalArgs, headTag) {
41154111
"--compare-from",
41164112
from,
41174113
"--check",
4118-
"--upload",
4114+
...(token ? ["--upload"] : []),
41194115
...(headTag ? ["--head-tag", headTag] : []),
41204116
...(additionalArgs ? [...additionalArgs.split(" ")] : []),
41214117
], {
4122-
env: Object.assign(Object.assign({}, process.env), { OPTIC_TOKEN: token }),
4118+
env: Object.assign(Object.assign({}, process.env), (token ? { OPTIC_TOKEN: token } : {})),
41234119
}, false);
41244120
}
41254121
async function prComment(githubToken, owner, repo, pr, sha) {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@
4646
"dependencies": {
4747
"@actions/core": "^1.10.0",
4848
"@actions/exec": "^1.1.1"
49-
}
49+
},
50+
"prettier": {}
5051
}

src/action.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function execCommand(
2020
}
2121

2222
export async function runAction(
23-
opticToken: string,
23+
opticToken: string | undefined,
2424
githubToken: string,
2525
{
2626
additionalArgs,
@@ -50,7 +50,7 @@ export async function runAction(
5050
): Promise<number> {
5151
const failOnCheckError = standardsFail === "true";
5252

53-
const valid = verifyInput(opticToken, eventName, owner, repo);
53+
const valid = verifyInput(eventName, owner, repo);
5454
if (!valid) {
5555
return 1;
5656
}
@@ -129,18 +129,10 @@ export async function runAction(
129129
}
130130

131131
function verifyInput(
132-
token: string,
133132
eventName: string | undefined,
134133
owner: string | undefined,
135134
repo: string | undefined
136135
): boolean {
137-
if (!token) {
138-
core.error(
139-
"No token was provided. You can generate a token through our app at https://app.useoptic.com"
140-
);
141-
return false;
142-
}
143-
144136
if (eventName !== "push" && eventName !== "pull_request") {
145137
core.error("Only 'push' and 'pull_request' events are supported.");
146138
return false;
@@ -196,7 +188,7 @@ async function parseAndEnsureRef(ref: string): Promise<string | false> {
196188
}
197189

198190
async function diffAll(
199-
token: string,
191+
token: string | undefined,
200192
from: string,
201193
additionalArgs: string | undefined,
202194
headTag: string | undefined
@@ -210,14 +202,14 @@ async function diffAll(
210202
"--compare-from",
211203
from,
212204
"--check",
213-
"--upload",
205+
...(token ? ["--upload"] : []),
214206
...(headTag ? ["--head-tag", headTag] : []),
215207
...(additionalArgs ? [...additionalArgs.split(" ")] : []),
216208
],
217209
{
218210
env: {
219211
...process.env,
220-
OPTIC_TOKEN: token,
212+
...(token ? { OPTIC_TOKEN: token } : {}),
221213
},
222214
},
223215
false

0 commit comments

Comments
 (0)