-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
74 lines (65 loc) · 2.48 KB
/
index.ts
File metadata and controls
74 lines (65 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as core from "@actions/core";
import * as github from "@actions/github";
import { CoderTaskAction } from "./action";
import { RealCoderClient } from "./coder-client";
import { ActionInputsSchema } from "./schemas";
async function main() {
try {
// Parse and validate inputs
const githubUserIdInput = core.getInput("github-user-id");
const githubUserID = githubUserIdInput
? Number.parseInt(githubUserIdInput, 10)
: undefined;
const inputs = ActionInputsSchema.parse({
coderURL: core.getInput("coder-url", { required: true }),
coderToken: core.getInput("coder-token", { required: true }),
coderTemplateName: core.getInput("coder-template-name", {
required: true,
}),
coderTaskPrompt: core.getInput("coder-task-prompt", { required: true }),
coderOrganization: core.getInput("coder-organization", {
required: true,
}),
coderTaskNamePrefix: core.getInput("coder-task-name-prefix", {
required: true,
}),
githubIssueURL: core.getInput("github-issue-url", { required: true }),
githubToken: core.getInput("github-token", { required: true }),
githubUserID,
coderUsername: core.getInput("coder-username") || undefined,
coderTemplatePreset: core.getInput("coder-template-preset") || undefined,
commentOnIssue: core.getBooleanInput("comment-on-issue"),
});
core.debug("Inputs validated successfully");
core.debug(`Coder URL: ${inputs.coderURL}`);
core.debug(`Template: ${inputs.coderTemplateName}`);
core.debug(`Organization: ${inputs.coderOrganization}`);
// Initialize clients
const coder = new RealCoderClient(inputs.coderURL, inputs.coderToken);
const octokit = github.getOctokit(inputs.githubToken);
core.debug("Clients initialized");
// Execute action
const action = new CoderTaskAction(coder, octokit, inputs);
const outputs = await action.run();
// Set outputs
core.setOutput("coder-username", outputs.coderUsername);
core.setOutput("task-name", outputs.taskName);
core.setOutput("task-url", outputs.taskUrl);
core.setOutput("task-created", outputs.taskCreated.toString());
core.debug("Action completed successfully");
core.debug(`Outputs: ${JSON.stringify(outputs, null, 2)}`);
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
console.error("Action failed:", error);
if (error.stack) {
console.error("Stack trace:", error.stack);
}
} else {
core.setFailed("Unknown error occurred");
console.error("Unknown error:", error);
}
process.exit(1);
}
}
main();