-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.tsx
94 lines (85 loc) · 2.61 KB
/
page.tsx
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/** @jsx h */
/** @jsxFrag Fragment */
import { Fragment, h } from "https://deno.land/x/[email protected]/mod.ts";
import { getLinkForJiraIssue, searchLinkForIssueKeys } from "./jira.ts";
import { getComparison } from "./github.ts";
import { getCommitsAndIssueData } from "./commit.tsx";
import { getAllChecks } from "./checks.tsx";
function getCss(): Promise<string> {
// load css from styles.css
return Deno.readTextFile("styles.css");
}
export async function page(
title: string,
content: JSX.Element,
): Promise<JSX.Element> {
return (
<html>
<head>
<title>{title}</title>
<style dangerouslySetInnerHTML={{ __html: await getCss() }}></style>
</head>
<body>{content}</body>
</html>
);
}
export async function getPage(
base: string,
head: string,
): Promise<JSX.Element> {
const comparison = await getComparison(base, head);
const commitMessages = comparison.commits.reverse().map((commit) =>
commit.commit.message
);
const { commits, issues } = await getCommitsAndIssueData(commitMessages);
const issueStatuses: { [key: string]: string } = {};
for (const issue of issues) {
issueStatuses[issue.key] = issue.resolution;
}
const issueKeys = issues.map((issue) => issue.key);
const issuesByResolution: { [key: string]: string[] } = {};
for (const issue of issues) {
const resolution = issue.resolution ?? "Unresolved";
if (issuesByResolution[resolution] === undefined) {
issuesByResolution[resolution] = [];
}
issuesByResolution[resolution].push(issue.key);
}
const title = `Comparison between ${base} and ${head}`;
return page(
title,
<Fragment>
<h1>{title}</h1>
<h2>Shipability checks</h2>
{await getAllChecks(comparison, base, head)}
<h2>Issues ({issueKeys.length})</h2>
<p>
<a href={searchLinkForIssueKeys(issueKeys)} target="_blank">
Open issues in Jira
</a>
<ul>
{issueKeys.map((issueKey) => (
<li>
<a href={getLinkForJiraIssue(issueKey)} target="_blank">
{issueKey}
</a>{" "}
{issueStatuses[issueKey]}
</li>
))}
</ul>
<h3>Issue status summary</h3>
<ul>
{Object.entries(issuesByResolution).map(([resolution, issueKeys]) => (
<li>
<a href={searchLinkForIssueKeys(issueKeys)} target="_blank">
{resolution}: {issueKeys.length}
</a>
</li>
))}
</ul>
</p>
<h2>Commits ({commits.length})</h2>
{commits.map((c) => c.element)}
</Fragment>,
);
}