Skip to content

Commit 21db08c

Browse files
authored
feat: support custom GitHub API base URL (#387)
GitHub Enterprise Server deployments require routing API calls to a custom endpoint instead of the default GitHub.com API. This commit adds a new 'github_api_url' action input and passes it to Octokit as baseUrl so check run calls target the configured GitHub API host. Additionally, it documents the input in README and adds a test case that validates requests using /api/v3 when a custom API URL is provided.
1 parent c02c9ba commit 21db08c

7 files changed

Lines changed: 81 additions & 19 deletions

File tree

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ jobs:
2929
3030
See the [examples workflow](.github/workflows/examples.yml) for more details and examples (and see the [associated runs](https://github.com/LouisBrunner/checks-action/actions?query=workflow%3Aexamples) to see how it will look like).
3131
32+
### GitHub Enterprise Server
33+
34+
When running on GitHub Enterprise Server, set `github_api_url` to your instance API endpoint:
35+
36+
```yaml
37+
name: "build-test"
38+
on: [push]
39+
40+
jobs:
41+
test_something:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v1
45+
- uses: LouisBrunner/checks-action@v2.0.0
46+
if: always()
47+
with:
48+
token: ${{ secrets.GITHUB_TOKEN }}
49+
github_api_url: https://github.example.com/api/v3
50+
name: Test XYZ
51+
conclusion: ${{ job.status }}
52+
```
53+
3254
### Permissions
3355

3456
When the action is run as part of a Pull Request, your workflow might fail with the following error: `Error: Resource not accessible by integration`.
@@ -80,6 +102,10 @@ _Optional_ The SHA of the target commit. Defaults to the current commit.
80102

81103
**Required** Your `GITHUB_TOKEN`
82104

105+
### `github_api_url`
106+
107+
_Optional_ The base API URL to use for GitHub API requests. Useful for GitHub Enterprise Server, e.g. `https://github.example.com/api/v3`.
108+
83109
### `name`
84110

85111
**Required** for creation, the name of the check to create (mutually exclusive with `check_id`)

__tests__/main.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ describe("run action", () => {
193193
};
194194

195195
const runAction = async ({
196+
githubAPIURL,
196197
repo,
197198
sha,
198199
token = "ABC",
@@ -204,6 +205,7 @@ describe("run action", () => {
204205
conclusion,
205206
testPort,
206207
}: {
208+
githubAPIURL: string | undefined;
207209
repo: string | undefined;
208210
sha: string | undefined;
209211
token: string | undefined;
@@ -221,6 +223,9 @@ describe("run action", () => {
221223
}> => {
222224
const entry = path.join(__dirname, "..", "dist", "index.js");
223225
const optional: Record<string, unknown> = {};
226+
if (githubAPIURL !== undefined) {
227+
optional.INPUT_GITHUB_API_URL = githubAPIURL;
228+
}
224229
if (repo !== undefined) {
225230
optional.INPUT_REPO = repo;
226231
}
@@ -283,6 +288,7 @@ describe("run action", () => {
283288
checkID?: string;
284289
eventName?: string;
285290
eventRecord?: Record<string, unknown>;
291+
githubAPIURL?: string;
286292
repo?: string;
287293
sha?: string;
288294
token?: string;
@@ -295,6 +301,26 @@ describe("run action", () => {
295301

296302
const cases = ((): Case[] => {
297303
return [
304+
{
305+
checkName: "testo",
306+
conclusion: Conclusion.Success,
307+
expectedCheckID: 456,
308+
expectedRequests: [
309+
{
310+
body: {
311+
conclusion: "success",
312+
head_sha: "SHA1",
313+
name: "testo",
314+
status: "completed",
315+
},
316+
method: "POST",
317+
url: "/api/v3/repos/LB/ABC/check-runs",
318+
},
319+
],
320+
githubAPIURL: "https://ghe.example.com/api/v3",
321+
name: "creation using custom github api url",
322+
status: Status.Completed,
323+
},
298324
{
299325
checkName: "testo",
300326
conclusion: Conclusion.Success,
@@ -452,6 +478,7 @@ describe("run action", () => {
452478
conclusion: rest.conclusion.toString(),
453479
eventName: rest.eventName,
454480
eventPath: rest.eventRecord ? filename : undefined,
481+
githubAPIURL: rest.githubAPIURL,
455482
id: rest.checkID,
456483
name: rest.checkName,
457484
repo: rest.repo,

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ branding:
55
icon: 'check-circle'
66
color: 'green'
77
inputs:
8+
github_api_url:
9+
description: 'the base GitHub API URL (for GitHub Enterprise, e.g. https://github.example.com/api/v3)'
10+
required: false
811
repo:
912
description: 'the target `owner/repo` to manage the check run on (defaults to the current repository)'
1013
required: false

dist/index.js

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/inputs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const parseJSON = <T>(getInput: GetInput, property: string): T | undefined => {
1919
};
2020

2121
export const parseInputs = (getInput: GetInput): Inputs.Args => {
22+
const githubAPIURL = getInput("github_api_url");
2223
const repo = getInput("repo");
2324
const sha = getInput("sha");
2425
const token = getInput("token", { required: true });
@@ -107,6 +108,7 @@ export const parseInputs = (getInput: GetInput): Inputs.Args => {
107108
checkID,
108109
conclusion,
109110
detailsURL,
111+
githubAPIURL,
110112
images,
111113
name,
112114

src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ async function run(): Promise<void> {
4646
const inputs = parseInputs(core.getInput);
4747

4848
core.debug(`Setting up OctoKit`);
49-
const octokit = github.getOctokit(inputs.token, options);
49+
const octokit = github.getOctokit(inputs.token, {
50+
...options,
51+
baseUrl: inputs.githubAPIURL ?? options.baseUrl,
52+
});
5053

5154
const ownership = {
5255
owner: github.context.repo.owner,

src/namespaces/Inputs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface ArgsBase {
77
annotations?: Annotations;
88
conclusion?: Conclusion;
99
detailsURL?: string;
10+
githubAPIURL?: string;
1011
images?: Images;
1112

1213
output?: Output;

0 commit comments

Comments
 (0)