Skip to content

Commit f17f2e9

Browse files
ajafffnchen63
authored andcommitted
Make rule names in changelog clickable links (palantir#2639)
Convert all rule names to links to the docs while generating changelog. Also filter out [no-log]
1 parent b91bf19 commit f17f2e9

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

scripts/generate-changelog.ts

+34-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import * as fs from "fs";
2828
import * as os from "os";
2929
import * as path from "path";
3030

31+
import { camelize } from "../lib/utils";
32+
3133
const github = new GitHubApi({
3234
host: "api.github.com",
3335
protocol: "https",
@@ -89,7 +91,7 @@ github.repos.getLatestRelease(repoInfo).then((value) => {
8991
if (fieldMatch) {
9092
commit.fields.push({
9193
tag: fieldMatch[1],
92-
text: line + " (#" + commit.pushRequestNum + ")",
94+
text: addLinks(line) + " (#" + commit.pushRequestNum + ")",
9395
});
9496
}
9597
}
@@ -105,7 +107,9 @@ github.repos.getLatestRelease(repoInfo).then((value) => {
105107
for (const commit of commits) {
106108
if (commit.fields.length > 0) {
107109
for (const field of commit.fields) {
108-
entries.push(field);
110+
if (field.tag !== "[no-log]") {
111+
entries.push(field);
112+
}
109113
}
110114
} else {
111115
noFields.push(commit.title);
@@ -135,6 +139,34 @@ github.repos.getLatestRelease(repoInfo).then((value) => {
135139
console.log("Error:" + error);
136140
});
137141

142+
const cache = new Map<string, boolean>();
143+
144+
function isRule(ruleName: string): boolean {
145+
let result = cache.get(ruleName);
146+
if (result === undefined) {
147+
result = fs.existsSync(`./src/rules/${camelize(ruleName)}Rule.ts`);
148+
cache.set(ruleName, result);
149+
}
150+
return result;
151+
}
152+
153+
/** Replace rule names with links to the docs website */
154+
function addLinks(text: string): string {
155+
let result = "";
156+
let lastIndex = 0;
157+
// match everything that looks like a rule name and is enclosed in backticks
158+
const regex = /`([a-z][-a-z]*[a-z])+`/g;
159+
let match = regex.exec(text);
160+
while (match !== null) {
161+
if (isRule(match[1])) {
162+
result += text.slice(lastIndex, match.index) + `[${match[0]}](https://palantir.github.io/tslint/rules/${match[1]}/)`;
163+
lastIndex = regex.lastIndex;
164+
}
165+
match = regex.exec(text);
166+
}
167+
return result + text.slice(lastIndex);
168+
}
169+
138170
interface IField {
139171
tag: string;
140172
text: string;

0 commit comments

Comments
 (0)