From c08c5ace340664df431bf7f11d51b61d92358c2b Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Tue, 29 Aug 2023 22:29:41 -0700 Subject: [PATCH] fix(GHES): respect `GITHUB_API_URL` when creating installation access token (#38) Follow up to #36. I just wanted to do some refactoring but turns out I missed to pass the custom `request` instance to `createAppAuth`. It will fallback to the default `request` which does not respect `GITHUB_API_URL` --- lib/main.js | 11 ++++------- lib/post.js | 7 ++----- lib/request.js | 8 ++++++++ main.js | 2 +- post.js | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 lib/request.js diff --git a/lib/main.js b/lib/main.js index 977fcf8..3db4fd4 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,16 +1,12 @@ // @ts-check -import core from "@actions/core"; -import { createAppAuth } from "@octokit/auth-app"; -import { request } from "@octokit/request"; - /** * @param {string} appId * @param {string} privateKey * @param {string} repository - * @param {core} core - * @param {createAppAuth} createAppAuth - * @param {request} request + * @param {import("@actions/core")} core + * @param {import("@octokit/auth-app").createAppAuth} createAppAuth + * @param {import("@octokit/request").request} request */ export async function main( appId, @@ -26,6 +22,7 @@ export async function main( const auth = createAppAuth({ appId, privateKey, + request, }); const appAuthentication = await auth({ diff --git a/lib/post.js b/lib/post.js index bfbae77..f02d0e5 100644 --- a/lib/post.js +++ b/lib/post.js @@ -1,11 +1,8 @@ // @ts-check -import core from "@actions/core"; -import { request } from "@octokit/request"; - /** - * @param {core} core - * @param {request} request + * @param {import("@actions/core")} core + * @param {import("@octokit/request").request} request */ export async function post(core, request) { const token = core.getState("token"); diff --git a/lib/request.js b/lib/request.js new file mode 100644 index 0000000..729cc19 --- /dev/null +++ b/lib/request.js @@ -0,0 +1,8 @@ +import { request } from "@octokit/request"; + +export default request.defaults({ + baseUrl: process.env["GITHUB_API_URL"], + headers: { + "user-agent": "actions/create-github-app-token", + }, +}); diff --git a/main.js b/main.js index eb480d4..9b269a1 100644 --- a/main.js +++ b/main.js @@ -2,9 +2,9 @@ import core from "@actions/core"; import { createAppAuth } from "@octokit/auth-app"; -import { request } from "@octokit/request"; import { main } from "./lib/main.js"; +import request from "./lib/request.js"; if (!process.env.GITHUB_REPOSITORY) { throw new Error("GITHUB_REPOSITORY missing, must be set to '/'"); diff --git a/post.js b/post.js index 145bc7e..66e37eb 100644 --- a/post.js +++ b/post.js @@ -1,9 +1,9 @@ // @ts-check import core from "@actions/core"; -import { request } from "@octokit/request"; import { post } from "./lib/post.js"; +import request from "./lib/request.js"; post( core,