From d7c9c707f1fd6ed7e298af80bb48d57a72383840 Mon Sep 17 00:00:00 2001 From: 7Hazard Date: Tue, 29 Aug 2023 01:41:32 +0200 Subject: [PATCH 1/2] Get GitHub API URL from env var --- lib/main.js | 4 ++++ lib/post.js | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 977fcf8..9469fd8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -4,6 +4,10 @@ import core from "@actions/core"; import { createAppAuth } from "@octokit/auth-app"; import { request } from "@octokit/request"; +request.defaults({ + baseUrl: process.env["GITHUB_API_URL"], +}); + /** * @param {string} appId * @param {string} privateKey diff --git a/lib/post.js b/lib/post.js index a0efe15..7c702fa 100644 --- a/lib/post.js +++ b/lib/post.js @@ -3,6 +3,10 @@ import core from "@actions/core"; import { request } from "@octokit/request"; +request.defaults({ + baseUrl: process.env["GITHUB_API_URL"], +}); + /** * @param {core} core * @param {request} request @@ -11,7 +15,7 @@ export async function post(core, request) { const token = core.getState("token"); if (!token) return; - + await request("DELETE /installation/token", { headers: { authorization: `token ${token}`, From c209b0b69cc795f9fe7d5de5fce8a1d7496d49ab Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Tue, 29 Aug 2023 08:34:35 -0700 Subject: [PATCH 2/2] move `request.defaults()` into entry files --- lib/main.js | 4 ---- lib/post.js | 4 ---- main.js | 19 +++++++++++++------ post.js | 15 +++++++++------ 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/main.js b/lib/main.js index 9469fd8..977fcf8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -4,10 +4,6 @@ import core from "@actions/core"; import { createAppAuth } from "@octokit/auth-app"; import { request } from "@octokit/request"; -request.defaults({ - baseUrl: process.env["GITHUB_API_URL"], -}); - /** * @param {string} appId * @param {string} privateKey diff --git a/lib/post.js b/lib/post.js index 7c702fa..bfbae77 100644 --- a/lib/post.js +++ b/lib/post.js @@ -3,10 +3,6 @@ import core from "@actions/core"; import { request } from "@octokit/request"; -request.defaults({ - baseUrl: process.env["GITHUB_API_URL"], -}); - /** * @param {core} core * @param {request} request diff --git a/main.js b/main.js index 02ffcc2..eb480d4 100644 --- a/main.js +++ b/main.js @@ -15,9 +15,16 @@ const privateKey = core.getInput("private_key"); const repository = process.env.GITHUB_REPOSITORY; -main(appId, privateKey, repository, core, createAppAuth, request).catch( - (error) => { - console.error(error); - core.setFailed(error.message); - } -); +main( + appId, + privateKey, + repository, + core, + createAppAuth, + request.defaults({ + baseUrl: process.env["GITHUB_API_URL"], + }) +).catch((error) => { + console.error(error); + core.setFailed(error.message); +}); diff --git a/post.js b/post.js index 0e34a59..145bc7e 100644 --- a/post.js +++ b/post.js @@ -5,9 +5,12 @@ import { request } from "@octokit/request"; import { post } from "./lib/post.js"; -post(core, request).catch( - (error) => { - console.error(error); - core.setFailed(error.message); - } -); +post( + core, + request.defaults({ + baseUrl: process.env["GITHUB_API_URL"], + }) +).catch((error) => { + console.error(error); + core.setFailed(error.message); +});