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`
This commit is contained in:
Gregor Martynus
2023-08-29 22:29:41 -07:00
committed by GitHub
parent c72844caa4
commit c08c5ace34
5 changed files with 16 additions and 14 deletions
+4 -7
View File
@@ -1,16 +1,12 @@
// @ts-check // @ts-check
import core from "@actions/core";
import { createAppAuth } from "@octokit/auth-app";
import { request } from "@octokit/request";
/** /**
* @param {string} appId * @param {string} appId
* @param {string} privateKey * @param {string} privateKey
* @param {string} repository * @param {string} repository
* @param {core} core * @param {import("@actions/core")} core
* @param {createAppAuth} createAppAuth * @param {import("@octokit/auth-app").createAppAuth} createAppAuth
* @param {request} request * @param {import("@octokit/request").request} request
*/ */
export async function main( export async function main(
appId, appId,
@@ -26,6 +22,7 @@ export async function main(
const auth = createAppAuth({ const auth = createAppAuth({
appId, appId,
privateKey, privateKey,
request,
}); });
const appAuthentication = await auth({ const appAuthentication = await auth({
+2 -5
View File
@@ -1,11 +1,8 @@
// @ts-check // @ts-check
import core from "@actions/core";
import { request } from "@octokit/request";
/** /**
* @param {core} core * @param {import("@actions/core")} core
* @param {request} request * @param {import("@octokit/request").request} request
*/ */
export async function post(core, request) { export async function post(core, request) {
const token = core.getState("token"); const token = core.getState("token");
+8
View File
@@ -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",
},
});
+1 -1
View File
@@ -2,9 +2,9 @@
import core from "@actions/core"; import core from "@actions/core";
import { createAppAuth } from "@octokit/auth-app"; import { createAppAuth } from "@octokit/auth-app";
import { request } from "@octokit/request";
import { main } from "./lib/main.js"; import { main } from "./lib/main.js";
import request from "./lib/request.js";
if (!process.env.GITHUB_REPOSITORY) { if (!process.env.GITHUB_REPOSITORY) {
throw new Error("GITHUB_REPOSITORY missing, must be set to '<owner>/<repo>'"); throw new Error("GITHUB_REPOSITORY missing, must be set to '<owner>/<repo>'");
+1 -1
View File
@@ -1,9 +1,9 @@
// @ts-check // @ts-check
import core from "@actions/core"; import core from "@actions/core";
import { request } from "@octokit/request";
import { post } from "./lib/post.js"; import { post } from "./lib/post.js";
import request from "./lib/request.js";
post( post(
core, core,