Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ jobs:

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

## GitHub Enterprise Support

This action supports GitHub Enterprise with the exception of the `github-username` input. You can use the `coder-username` input instead.

## License

[MIT](LICENSE)
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ runs:
core.setFailed('No issue number provided and no issue context available');
return;
}
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const serverUrl = '${{ github.server_url }}';
const runUrl = `${serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const comment = await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down Expand Up @@ -73,6 +74,7 @@ runs:
GITHUB_WORKFLOW_RUN_URL: ${{ steps.initial-comment.outputs.run_url }}
TEMPLATE_NAME: ${{ inputs.template-name }}
WORKSPACE_PARAMETERS: ${{ inputs.parameters }}
GITHUB_URL: ${{ github.api_url }}
run: |
node "${{ github.action_path }}/dist/index.js"

Expand Down
13 changes: 9 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Source hash: 502e316a739f1716d693e20b5f00db3e1fec499dd7ae21b8777097eb429691e8
// Source hash: 67ce94766a35d0d05fa9b4d38675d2f4deff7b82278c094b42d55ed2dfba6572
import { createRequire } from "node:module";
var __create = Object.create;
var __getProtoOf = Object.getPrototypeOf;
Expand Down Expand Up @@ -30481,7 +30481,8 @@ var ActionInputSchema = z.object({
githubToken: z.string().min(1),
githubWorkflowRunUrl: z.string().min(1),
templateName: z.string().min(1),
workspaceParameters: z.string().min(1)
workspaceParameters: z.string().min(1),
githubUrl: z.string().min(1)
});
var WorkspaceParametersSchema = z.record(z.string(), z.string());

Expand All @@ -30493,7 +30494,10 @@ class StartWorkspaceAction {
constructor(logger, input) {
this.logger = logger;
this.input = input;
this.octokit = new Octokit2({ auth: input.githubToken });
this.octokit = new Octokit2({
auth: input.githubToken,
baseUrl: input.githubUrl
});
this.coder = new CoderClient(input.coderUrl, input.coderToken);
}
async coderUsernameByGitHubId(githubUserId) {
Expand Down Expand Up @@ -30625,7 +30629,8 @@ var main = async () => {
githubToken: "GITHUB_TOKEN",
githubWorkflowRunUrl: "GITHUB_WORKFLOW_RUN_URL",
templateName: "TEMPLATE_NAME",
workspaceParameters: "WORKSPACE_PARAMETERS"
workspaceParameters: "WORKSPACE_PARAMETERS",
githubUrl: "GITHUB_URL"
};
const input = ActionInputSchema.parse(Object.fromEntries(Object.entries(inputEnv).map(([key, value]) => [
key,
Expand Down
37 changes: 1 addition & 36 deletions src/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
StartWorkspaceAction,
UserFacingError,
type ActionInput,
type ExecOutput,
type Logger,
} from "./action";
import dedent from "dedent";
Expand Down Expand Up @@ -31,30 +30,6 @@ interface ActionParams {
}

const newAction = (params?: ActionParams) => {
const defaults: ActionInput = {
githubUsername: "github-user",
coderUsername: "coder-user",
coderUrl: "https://example.com",
coderToken: "coder-token",
workspaceName: "workspace-name",
githubStatusCommentId: 123,
githubRepoOwner: "github-repo-owner",
githubRepoName: "github-repo-name",
githubToken: "github-token",
githubWorkflowRunUrl: "https://github.com/workflow-run",
templateName: "ubuntu",
workspaceParameters: dedent`
key: value
key2: value2
key3: value3
`.trim(),
};
// Loop through the input rather than use {...defaults, ...(params?.input ?? {})}
// to also allow overriding defaults with undefined values
for (const [key, value] of Object.entries(params?.input ?? {})) {
(defaults as any)[key] = value;
}

const action = new StartWorkspaceAction(params?.logger ?? new TestLogger(), {
githubUsername: "github-user",
coderUsername: undefined,
Expand All @@ -72,23 +47,13 @@ const newAction = (params?: ActionParams) => {
key2: value2
key3: value3
`.trim(),
githubUrl: "https://github.com",
...(params?.input ?? {}),
});

return action;
};

const identityExec = async (
strings: TemplateStringsArray,
...args: unknown[]
): Promise<ExecOutput> => {
let result = strings[0];
for (let i = 0; i < args.length; i++) {
result += String(args[i]) + strings[i + 1];
}
return { text: () => result ?? "" };
};

describe("StartWorkspaceAction", () => {
it("coderUsernameByGitHubId", async () => {
const logger = new TestLogger();
Expand Down
6 changes: 5 additions & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const ActionInputSchema = z.object({
githubWorkflowRunUrl: z.string().min(1),
templateName: z.string().min(1),
workspaceParameters: z.string().min(1),
githubUrl: z.string().min(1),
});

export type ActionInput = z.infer<typeof ActionInputSchema>;
Expand All @@ -56,7 +57,10 @@ export class StartWorkspaceAction {
private readonly logger: Logger,
private readonly input: ActionInput
) {
this.octokit = new Octokit({ auth: input.githubToken });
this.octokit = new Octokit({
auth: input.githubToken,
baseUrl: input.githubUrl,
});
this.coder = new CoderClient(input.coderUrl, input.coderToken);
}

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const main = async () => {
githubWorkflowRunUrl: "GITHUB_WORKFLOW_RUN_URL",
templateName: "TEMPLATE_NAME",
workspaceParameters: "WORKSPACE_PARAMETERS",
githubUrl: "GITHUB_URL",
};

const input = ActionInputSchema.parse(
Expand Down