Skip to content

Commit

Permalink
fix(GHES): respect GITHUB_API_URL when creating installation access…
Browse files Browse the repository at this point in the history
… token (actions#38)

Follow up to actions#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`
  • Loading branch information
gr2m authored Aug 30, 2023
1 parent c72844c commit c08c5ac
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
11 changes: 4 additions & 7 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -26,6 +22,7 @@ export async function main(
const auth = createAppAuth({
appId,
privateKey,
request,
});

const appAuthentication = await auth({
Expand Down
7 changes: 2 additions & 5 deletions lib/post.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
8 changes: 8 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
@@ -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",
},
});
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<owner>/<repo>'");
Expand Down
2 changes: 1 addition & 1 deletion post.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit c08c5ac

Please sign in to comment.