-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmermaid-node.ts
51 lines (40 loc) · 1.37 KB
/
mermaid-node.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
46
47
48
49
50
51
import { GitHubIssue } from "./models";
import { wrapString } from "./utils";
export type MermaidNodeStatus = "default" | "notstarted" | "started" | "completed";
export class MermaidNode {
constructor(
public readonly nodeId: string,
public readonly title: string,
public readonly status: MermaidNodeStatus,
public readonly url?: string
) {}
public getFormattedTitle(): string {
let result = this.title;
result = result.replaceAll('"', "'");
result = wrapString(result, 40);
return result;
}
public static createFromGitHubIssue(issue: GitHubIssue): MermaidNode {
return new MermaidNode(
`issue${issue.id}`,
issue.title,
MermaidNode.getNodeStatusFromGitHubIssue(issue),
issue.html_url
);
}
private static getNodeStatusFromGitHubIssue(issue: GitHubIssue): MermaidNodeStatus {
if (issue.state !== "open") {
return "completed";
}
if (issue.assignees && issue.assignees.length > 0) {
return "started";
}
return "notstarted";
}
public static createStartNode(): MermaidNode {
return new MermaidNode("start", "Start", "default");
}
public static createFinishNode(): MermaidNode {
return new MermaidNode("finish", "Finish", "default");
}
}