-
Notifications
You must be signed in to change notification settings - Fork 3
/
mod.ts
61 lines (53 loc) · 1.56 KB
/
mod.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
52
53
54
55
56
57
58
59
60
61
export { getChangeLog } from "./src/main.ts";
export type { Config } from "./src/main.ts";
import { getChangeLog } from "./src/main.ts";
import type { Config } from "./src/main.ts";
import { formatTime } from "./src/deps.ts";
export async function getDefaultChangelog(
repo: {
name: string;
base?: string;
head?: string;
},
release?: {
tag?: string;
name?: string;
date?: string;
},
config?: Config,
): Promise<string> {
const { _meta, changes } = await getChangeLog(
repo.name,
repo.base,
repo.head,
config,
);
const title = release?.name ? `# ${release?.name}\n\n` : "";
const counts = changes.map(({ emoji, count }) => `\`${emoji} ${count}\``);
const stats = [
`\`📆 ${release?.date ?? formatTime(new Date(), "dd.MM.yyyy")}\``,
`\`🏷️ ${release?.tag ?? "UNRELEASED"}\``,
`\`💾 ${_meta.commits.head.shortSha.toUpperCase()}\``,
`${counts.join(" ")}`,
`\`👥 ${_meta.contributors.length}\``,
].join(" ");
return `${title}${stats}
${
changes.length
? changes
.map(({ emoji, title, commits }) => {
const header = `## ${emoji} ${title}`;
const changes = commits
.map(({ shortSha, url, header, author }) => {
return `- [\`${shortSha.toUpperCase()}\`](${url}) ${header} (${author})`;
})
.join("\n");
return `\n${header}\n\n${changes}`;
})
.join("\n")
: "\nNo changes"
}
## 👥 Contributors
${_meta.contributors.map((name) => `- ${name}`).join("\n") || "No contributors"}
`;
}