From 226d2ba38ecfc842943d36994b800f6fe30dcf07 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 20 Dec 2022 12:24:31 -0500 Subject: [PATCH] Do not create octokit if no github token (#42) Fixes https://github.com/cloudflare/pages-action/issues/41 --- index.js | 3 ++- package-lock.json | 4 ++-- src/index.ts | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 844ffba..e15008d 100644 --- a/index.js +++ b/index.js @@ -22067,7 +22067,7 @@ try { const directory = (0, import_core.getInput)("directory", { required: true }); const gitHubToken = (0, import_core.getInput)("gitHubToken", { required: false }); const branch = (0, import_core.getInput)("branch", { required: false }); - const octokit = (0, import_github.getOctokit)(gitHubToken); + let octokit; const getProject = async () => { const response = await (0, import_undici.fetch)( `https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}`, @@ -22133,6 +22133,7 @@ try { return; } const project = await getProject(); + octokit = (0, import_github.getOctokit)(gitHubToken); const githubBranch = import_process.env.GITHUB_REF_NAME; const productionEnvironment = githubBranch === project.production_branch; let environmentName; diff --git a/package-lock.json b/package-lock.json index 7f2c6ea..1f25408 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pages-action", - "version": "1.0.0", + "version": "1.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "pages-action", - "version": "1.0.0", + "version": "1.2.0", "license": "MIT", "dependencies": { "@actions/core": "^1.10.0", diff --git a/src/index.ts b/src/index.ts index f4fd01f..49c5300 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,7 @@ try { const gitHubToken = getInput("gitHubToken", { required: false }); const branch = getInput("branch", { required: false }); - const octokit = getOctokit(gitHubToken); + let octokit; const getProject = async () => { const response = await fetch( @@ -96,6 +96,7 @@ try { } const project = await getProject(); + octokit = getOctokit(gitHubToken); const githubBranch = env.GITHUB_REF_NAME; const productionEnvironment = githubBranch === project.production_branch;