Skip to content

Commit b1d692e

Browse files
authored
Merge pull request #49 from gruntwork-io/caitlin/update-token
Add the ability to provide a separate auth token vs. patcher update token
2 parents d8e117a + fc47115 commit b1d692e

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

dist/index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13703,12 +13703,12 @@ function getPatcherEnvVars(gitCommiter, token) {
1370313703
GIT_AUTHOR_EMAIL: gitCommiter.email,
1370413704
};
1370513705
}
13706-
async function runPatcher(gitCommiter, command, { specFile, includeDirs, excludeDirs, updateStrategy, prBranch, prTitle, dependency, workingDir, token, dryRun, noColor, }) {
13706+
async function runPatcher(gitCommiter, command, { specFile, includeDirs, excludeDirs, updateStrategy, prBranch, prTitle, dependency, workingDir, updateToken, dryRun, noColor, }) {
1370713707
switch (command) {
1370813708
case REPORT_COMMAND: {
1370913709
core.startGroup("Running 'patcher report'");
1371013710
const reportOutput = await exec.getExecOutput("patcher", reportArgs(specFile, includeDirs, excludeDirs, workingDir, noColor), {
13711-
env: getPatcherEnvVars(gitCommiter, token),
13711+
env: getPatcherEnvVars(gitCommiter, updateToken),
1371213712
});
1371313713
core.endGroup();
1371413714
core.startGroup("Setting upgrade spec output");
@@ -13729,7 +13729,7 @@ async function runPatcher(gitCommiter, command, { specFile, includeDirs, exclude
1372913729
}
1373013730
core.startGroup(groupName);
1373113731
const updateOutput = await exec.getExecOutput("patcher", updateArgs(specFile, updateStrategy, prBranch, prTitle, dependency, workingDir, dryRun, noColor), {
13732-
env: getPatcherEnvVars(gitCommiter, token),
13732+
env: getPatcherEnvVars(gitCommiter, updateToken),
1373313733
});
1373413734
core.endGroup();
1373513735
core.startGroup("Setting 'updateResult' output");
@@ -13768,7 +13768,8 @@ async function validateAccessToPatcherCli(octokit) {
1376813768
}
1376913769
}
1377013770
async function run() {
13771-
const token = core.getInput("github_token");
13771+
const gruntworkToken = core.getInput("github_token");
13772+
const patcherUpdateToken = core.getInput("update_token");
1377213773
const command = core.getInput("patcher_command");
1377313774
const updateStrategy = core.getInput("update_strategy");
1377413775
const dependency = core.getInput("dependency");
@@ -13781,10 +13782,15 @@ async function run() {
1378113782
const prTitle = core.getInput("pull_request_title");
1378213783
const dryRun = core.getBooleanInput("dry_run");
1378313784
const noColor = core.getBooleanInput("no_color");
13784-
// Always mask the `token` string in the logs.
13785-
core.setSecret(token);
13785+
// if the user didn't specify a token specifically for `patcher update`,
13786+
// that's ok, we can try to use the github token instead. doing this adoption
13787+
// is for back compatibility reasons
13788+
const updateToken = patcherUpdateToken ? patcherUpdateToken : gruntworkToken;
13789+
// Always mask the token strings in the logs.
13790+
core.setSecret(gruntworkToken);
13791+
core.setSecret(updateToken);
1378613792
// Only run the action if the user has access to Patcher. Otherwise, the download won't work.
13787-
const octokit = github.getOctokit(token);
13793+
const octokit = github.getOctokit(gruntworkToken);
1378813794
await validateAccessToPatcherCli(octokit);
1378913795
// Validate if the 'patcher_command' provided is valid.
1379013796
if (!isPatcherCommandValid(command)) {
@@ -13794,7 +13800,7 @@ async function run() {
1379413800
// Validate if 'commit_author' has a valid format.
1379513801
const gitCommiter = parseCommitAuthor(commitAuthor);
1379613802
core.startGroup("Downloading Patcher and patch tools");
13797-
await downloadAndSetupTooling(octokit, token);
13803+
await downloadAndSetupTooling(octokit, gruntworkToken);
1379813804
core.endGroup();
1379913805
await runPatcher(gitCommiter, command, {
1380013806
specFile,
@@ -13805,7 +13811,7 @@ async function run() {
1380513811
prTitle,
1380613812
dependency,
1380713813
workingDir,
13808-
token,
13814+
updateToken,
1380913815
dryRun,
1381013816
noColor,
1381113817
});

src/action.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type PatcherCliArgs = {
5252
prTitle: string;
5353
dependency: string;
5454
workingDir: string;
55-
token: string;
55+
updateToken: string;
5656
dryRun: boolean;
5757
noColor: boolean;
5858
};
@@ -289,7 +289,7 @@ async function runPatcher(
289289
prTitle,
290290
dependency,
291291
workingDir,
292-
token,
292+
updateToken,
293293
dryRun,
294294
noColor,
295295
}: PatcherCliArgs
@@ -301,7 +301,7 @@ async function runPatcher(
301301
"patcher",
302302
reportArgs(specFile, includeDirs, excludeDirs, workingDir, noColor),
303303
{
304-
env: getPatcherEnvVars(gitCommiter, token),
304+
env: getPatcherEnvVars(gitCommiter, updateToken),
305305
}
306306
);
307307
core.endGroup();
@@ -329,7 +329,7 @@ async function runPatcher(
329329
"patcher",
330330
updateArgs(specFile, updateStrategy, prBranch, prTitle, dependency, workingDir, dryRun, noColor),
331331
{
332-
env: getPatcherEnvVars(gitCommiter, token),
332+
env: getPatcherEnvVars(gitCommiter, updateToken),
333333
}
334334
);
335335
core.endGroup();
@@ -379,7 +379,8 @@ async function validateAccessToPatcherCli(octokit: GitHub) {
379379
}
380380

381381
export async function run() {
382-
const token = core.getInput("github_token");
382+
const gruntworkToken = core.getInput("github_token");
383+
const patcherUpdateToken = core.getInput("update_token");
383384
const command = core.getInput("patcher_command");
384385
const updateStrategy = core.getInput("update_strategy");
385386
const dependency = core.getInput("dependency");
@@ -393,11 +394,17 @@ export async function run() {
393394
const dryRun = core.getBooleanInput("dry_run");
394395
const noColor = core.getBooleanInput("no_color");
395396

396-
// Always mask the `token` string in the logs.
397-
core.setSecret(token);
397+
// if the user didn't specify a token specifically for `patcher update`,
398+
// that's ok, we can try to use the github token instead. doing this adoption
399+
// is for back compatibility reasons
400+
const updateToken = patcherUpdateToken ? patcherUpdateToken : gruntworkToken;
401+
402+
// Always mask the token strings in the logs.
403+
core.setSecret(gruntworkToken);
404+
core.setSecret(updateToken);
398405

399406
// Only run the action if the user has access to Patcher. Otherwise, the download won't work.
400-
const octokit = github.getOctokit(token);
407+
const octokit = github.getOctokit(gruntworkToken);
401408
await validateAccessToPatcherCli(octokit);
402409

403410
// Validate if the 'patcher_command' provided is valid.
@@ -410,7 +417,7 @@ export async function run() {
410417
const gitCommiter = parseCommitAuthor(commitAuthor);
411418

412419
core.startGroup("Downloading Patcher and patch tools");
413-
await downloadAndSetupTooling(octokit, token);
420+
await downloadAndSetupTooling(octokit, gruntworkToken);
414421
core.endGroup();
415422

416423
await runPatcher(gitCommiter, command, {
@@ -422,7 +429,7 @@ export async function run() {
422429
prTitle,
423430
dependency,
424431
workingDir,
425-
token,
432+
updateToken,
426433
dryRun,
427434
noColor,
428435
});

0 commit comments

Comments
 (0)