-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcli.ts
More file actions
62 lines (55 loc) · 1.89 KB
/
cli.ts
File metadata and controls
62 lines (55 loc) · 1.89 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
import { Command } from "@cliffy/command";
import { createMermaid } from "./src/workflow_gantt.ts";
import { expandCompositeSteps } from "./src/composite.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 },
)
.option(
"--expand-composite-actions <expandCompositeActions:boolean>",
"Expand composite action steps in the timeline. Default: false",
{ default: false },
)
.option(
"--expand-composite-actions-threshold <thresholdSec:number>",
"Duration threshold in seconds for expanding composite action steps. Default: 20",
{ default: 20 },
)
.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.fetchWorkflowRunJobs(workflowRun);
const jobs = options.expandCompositeActions
? await expandCompositeSteps(client, workflowRun, workflowJobs, {
thresholdSec: options.expandCompositeActionsThreshold,
})
: workflowJobs;
const gantt = createMermaid(workflowRun, jobs, {
showWaitingRunner: options.showWaitingRunner,
});
if (options.output) {
await Deno.writeTextFile(options.output, gantt);
} else {
console.log(gantt);
}