forked from microsoft/BotFramework-Composer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-changelog.js
170 lines (143 loc) · 3.94 KB
/
generate-changelog.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
const fs = require("fs");
const { execSync } = require("child_process");
const PULL_URL = "https://github.com/microsoft/BotFramework-Composer/pull";
const AUTHORS = {
"Andy Brown": "a-b-r-o-w-n",
"Ben Brown": "benbrown",
"Ben Yackley": "beyackle",
"Carlos Castro": "carlosscastro",
"Chris McConnell": "chrimc62",
"Chris Whitten": "cwhitten",
"Christiano Donke" :"cdonke",
Corina: "corinagum",
"Dong Lei": "boydc2014",
"Eric Dahlvang": "EricDahlvang",
"Fei Chen": "feich-ms",
"Filipe Teixeira" :"filipelteixeira",
"Gary Pretty": "garypretty",
"Geoff Cox (Microsoft)": "GeoffCoxMSFT",
"Hongyang Du (hond)": "Danieladu",
"Josh Gummersall": "joshgummersall",
"Kamran Iqbal": "Kaiqb",
leileizhang: "lei9444",
liweitian: "liweitian",
"Long Alan": "alanlong9278",
"Lu Han": "luhan2017",
mareekuh: "mareekuh",
mewa1024: "mewa1024",
natalgar :"natalgar",
pavolum: "pavolum",
"Peter Innes" :"peterinnesmsft",
"Pooja Nagpal": "p-nagpal",
"Qi Kang": "zidaneymar",
"Scott Gellock": "sgellock",
"Shuai Wang": "cosmicshuai",
Soroush: "hatpick",
"Srinaath Ravichandran": "srinaath",
taicchoumsft: "taicchoumsft",
"TJ Durnford": "tdurnford",
"Tony Anziano": "tonyanziano",
"Vamsi Modem": "VamsiModem",
VanyLaw: "VanyLaw",
"Weitian Li": "liweitian",
xieofxie: "xieofxie",
"Yan Liu": "zxyanliu",
zeye: "yeze322",
"Zhixiang Zhan": "zhixzhan",
"Zichuan Ma": "chon219",
zxyanliu: "zxyanliu",
};
const getLatestTag = () =>
execSync("git describe --tags $(git rev-list --tags --max-count=1)")
.toString()
.trim();
const getLog = (tag) =>
execSync(`git log --pretty=format:'%s | %an' ${tag}..main`)
.toString()
.split("\n");
const getDate = () => execSync('date +"%m-%d-%Y"').toString().trim();
const SECTIONS = {
Added: ["feat"],
Fixed: ["fix", "a11y"],
Changed: ["refactor", "style"],
Other: [],
};
const tagToSection = Object.keys(SECTIONS).reduce((acc, section) => {
const groupTags = SECTIONS[section].reduce(
(s, t) => ({
...s,
[t]: section,
}),
{}
);
return {
...acc,
...groupTags,
};
}, {});
const getCommitSection = (commit) => {
for (const tag in tagToSection) {
if (commit.startsWith(tag)) {
return tagToSection[tag];
} else if (!/^\w+:/.test(commit)) {
return "Uncategorized";
}
}
return "Other";
};
const formatMessage = (msg) =>
msg.replace(/\(\#(\d+)\)/, `([#$1](${PULL_URL}/$1))`);
const logCache = new Set();
const logOnce = (key, message) => {
if (!logCache.has(key)) {
process.stderr.write(message + "\n");
logCache.add(key);
}
};
const formatAuthor = (author) => {
const username = AUTHORS[author];
if (!username) {
logOnce(author, `${author} missing from username map`);
return `${author}`;
}
return `([@${username}](https://github.com/${username}))`;
};
const formatCommit = (commit) => {
const [message, author] = commit.split(" | ");
return [formatMessage(message), formatAuthor(author)];
};
function groupCommits(commits) {
return commits.reduce((groups, commit) => {
const section = getCommitSection(commit);
const [message, author] = formatCommit(commit);
if (!groups[section]) {
groups[section] = [];
}
groups[section].push(`${message} ${author}`);
return groups;
}, {});
}
const formatChangeLog = (groups) => {
const date = getDate();
let output = `### ${date}`;
for (const section in SECTIONS) {
if (groups[section] && groups[section].length > 0) {
output += `\n\n#### ${section}\n\n`;
output += groups[section].map((c) => `- ${c}`).join("\n");
}
}
// Uncategorized
if (groups.Uncategorized) {
output += "\n\n Uncategorized\n\n";
output += groups.Uncategorized.map((c) => `- ${c}`).join("\n");
}
return output;
};
function run() {
const tag = getLatestTag();
const commits = getLog(tag);
const groups = groupCommits(commits);
const output = formatChangeLog(groups);
console.log(output);
}
run();