Skip to content

Commit f97a681

Browse files
authored
feat: partial support for github enterprise (#4)
* add the github url input and remove unused code from the test file * obtain the api url from the github action octokit instance * obtain the github url from the github actions context * fix: pass github url to the start workspace step * remove reference to github url from the README * update readme
1 parent 35a4608 commit f97a681

6 files changed

Lines changed: 23 additions & 42 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ jobs:
112112

113113
This ensures the Coder API token is only accessible to workflows running on approved branches.
114114

115+
## GitHub Enterprise Support
116+
117+
This action supports GitHub Enterprise with the exception of the `github-username` input. You can use the `coder-username` input instead.
118+
115119
## License
116120

117121
[MIT](LICENSE)

action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ runs:
4444
core.setFailed('No issue number provided and no issue context available');
4545
return;
4646
}
47-
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
47+
const serverUrl = '${{ github.server_url }}';
48+
const runUrl = `${serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
4849
const comment = await github.rest.issues.createComment({
4950
owner: context.repo.owner,
5051
repo: context.repo.repo,
@@ -73,6 +74,7 @@ runs:
7374
GITHUB_WORKFLOW_RUN_URL: ${{ steps.initial-comment.outputs.run_url }}
7475
TEMPLATE_NAME: ${{ inputs.template-name }}
7576
WORKSPACE_PARAMETERS: ${{ inputs.parameters }}
77+
GITHUB_URL: ${{ github.api_url }}
7678
run: |
7779
node "${{ github.action_path }}/dist/index.js"
7880

dist/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Source hash: 502e316a739f1716d693e20b5f00db3e1fec499dd7ae21b8777097eb429691e8
1+
// Source hash: 67ce94766a35d0d05fa9b4d38675d2f4deff7b82278c094b42d55ed2dfba6572
22
import { createRequire } from "node:module";
33
var __create = Object.create;
44
var __getProtoOf = Object.getPrototypeOf;
@@ -30481,7 +30481,8 @@ var ActionInputSchema = z.object({
3048130481
githubToken: z.string().min(1),
3048230482
githubWorkflowRunUrl: z.string().min(1),
3048330483
templateName: z.string().min(1),
30484-
workspaceParameters: z.string().min(1)
30484+
workspaceParameters: z.string().min(1),
30485+
githubUrl: z.string().min(1)
3048530486
});
3048630487
var WorkspaceParametersSchema = z.record(z.string(), z.string());
3048730488

@@ -30493,7 +30494,10 @@ class StartWorkspaceAction {
3049330494
constructor(logger, input) {
3049430495
this.logger = logger;
3049530496
this.input = input;
30496-
this.octokit = new Octokit2({ auth: input.githubToken });
30497+
this.octokit = new Octokit2({
30498+
auth: input.githubToken,
30499+
baseUrl: input.githubUrl
30500+
});
3049730501
this.coder = new CoderClient(input.coderUrl, input.coderToken);
3049830502
}
3049930503
async coderUsernameByGitHubId(githubUserId) {
@@ -30625,7 +30629,8 @@ var main = async () => {
3062530629
githubToken: "GITHUB_TOKEN",
3062630630
githubWorkflowRunUrl: "GITHUB_WORKFLOW_RUN_URL",
3062730631
templateName: "TEMPLATE_NAME",
30628-
workspaceParameters: "WORKSPACE_PARAMETERS"
30632+
workspaceParameters: "WORKSPACE_PARAMETERS",
30633+
githubUrl: "GITHUB_URL"
3062930634
};
3063030635
const input = ActionInputSchema.parse(Object.fromEntries(Object.entries(inputEnv).map(([key, value]) => [
3063130636
key,

src/action.test.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
StartWorkspaceAction,
44
UserFacingError,
55
type ActionInput,
6-
type ExecOutput,
76
type Logger,
87
} from "./action";
98
import dedent from "dedent";
@@ -31,30 +30,6 @@ interface ActionParams {
3130
}
3231

3332
const newAction = (params?: ActionParams) => {
34-
const defaults: ActionInput = {
35-
githubUsername: "github-user",
36-
coderUsername: "coder-user",
37-
coderUrl: "https://example.com",
38-
coderToken: "coder-token",
39-
workspaceName: "workspace-name",
40-
githubStatusCommentId: 123,
41-
githubRepoOwner: "github-repo-owner",
42-
githubRepoName: "github-repo-name",
43-
githubToken: "github-token",
44-
githubWorkflowRunUrl: "https://github.com/workflow-run",
45-
templateName: "ubuntu",
46-
workspaceParameters: dedent`
47-
key: value
48-
key2: value2
49-
key3: value3
50-
`.trim(),
51-
};
52-
// Loop through the input rather than use {...defaults, ...(params?.input ?? {})}
53-
// to also allow overriding defaults with undefined values
54-
for (const [key, value] of Object.entries(params?.input ?? {})) {
55-
(defaults as any)[key] = value;
56-
}
57-
5833
const action = new StartWorkspaceAction(params?.logger ?? new TestLogger(), {
5934
githubUsername: "github-user",
6035
coderUsername: undefined,
@@ -72,23 +47,13 @@ const newAction = (params?: ActionParams) => {
7247
key2: value2
7348
key3: value3
7449
`.trim(),
50+
githubUrl: "https://github.com",
7551
...(params?.input ?? {}),
7652
});
7753

7854
return action;
7955
};
8056

81-
const identityExec = async (
82-
strings: TemplateStringsArray,
83-
...args: unknown[]
84-
): Promise<ExecOutput> => {
85-
let result = strings[0];
86-
for (let i = 0; i < args.length; i++) {
87-
result += String(args[i]) + strings[i + 1];
88-
}
89-
return { text: () => result ?? "" };
90-
};
91-
9257
describe("StartWorkspaceAction", () => {
9358
it("coderUsernameByGitHubId", async () => {
9459
const logger = new TestLogger();

src/action.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const ActionInputSchema = z.object({
4141
githubWorkflowRunUrl: z.string().min(1),
4242
templateName: z.string().min(1),
4343
workspaceParameters: z.string().min(1),
44+
githubUrl: z.string().min(1),
4445
});
4546

4647
export type ActionInput = z.infer<typeof ActionInputSchema>;
@@ -56,7 +57,10 @@ export class StartWorkspaceAction {
5657
private readonly logger: Logger,
5758
private readonly input: ActionInput
5859
) {
59-
this.octokit = new Octokit({ auth: input.githubToken });
60+
this.octokit = new Octokit({
61+
auth: input.githubToken,
62+
baseUrl: input.githubUrl,
63+
});
6064
this.coder = new CoderClient(input.coderUrl, input.coderToken);
6165
}
6266

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const main = async () => {
2424
githubWorkflowRunUrl: "GITHUB_WORKFLOW_RUN_URL",
2525
templateName: "TEMPLATE_NAME",
2626
workspaceParameters: "WORKSPACE_PARAMETERS",
27+
githubUrl: "GITHUB_URL",
2728
};
2829

2930
const input = ActionInputSchema.parse(

0 commit comments

Comments
 (0)