-
Notifications
You must be signed in to change notification settings - Fork 7
/
cli.ts
45 lines (39 loc) · 1.29 KB
/
cli.ts
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
import { Command } from "@cliffy/command";
import { createMermaid } from "./src/workflow_gantt.ts";
import { Github, parseWorkflowRunUrl } from "@kesin11/gha-utils";
const { options, args } = await new Command()
.name("actions-timeline-cli")
.description("Command line tool of actions-timeline")
.option("-t, --token <token:string>", "GitHub token. ex: $(gh auth token)")
.option(
"-o, --output <output:file>",
"Output md file path. If not set output to STDOUT. ex: output.md",
)
.option(
"--show-waiting-runner <showWaitingRunner:boolean>",
"Show waiting runner time in the timeline. Default: true",
{ default: true },
)
.arguments("<url:string>")
.parse(Deno.args);
const url = args[0];
const runUrl = parseWorkflowRunUrl(url);
const host = (runUrl.origin !== "https://github.com")
? runUrl.origin
: undefined;
const client = new Github({ token: options.token, host });
const workflowRun = await client.fetchWorkflowRun(
runUrl.owner,
runUrl.repo,
runUrl.runId,
runUrl.runAttempt,
);
const workflowJobs = await client.fetchWorkflowJobs([workflowRun]);
const gantt = createMermaid(workflowRun, workflowJobs, {
showWaitingRunner: options.showWaitingRunner,
});
if (options.output) {
await Deno.writeTextFile(options.output, gantt);
} else {
console.log(gantt);
}