aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/link-readme.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/scripts/link-readme.js')
-rw-r--r--src/scripts/link-readme.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/scripts/link-readme.js b/src/scripts/link-readme.js
new file mode 100644
index 000000000..223451d84
--- /dev/null
+++ b/src/scripts/link-readme.js
@@ -0,0 +1,53 @@
1/**
2 * Script that automatically creates links to issues and users inside README.md
3 *
4 * e.g. "#123" => "[#123](https://github.com/getferdi/ferdi/issues/123)"
5 * and "franz/#123" => "[franz#123](https://github.com/meetfranz/franz/issues/123)"
6 * and "@abc" => "[@abc](https://github.com/abc)"
7 */
8
9const fs = require('fs-extra');
10const path = require('path');
11
12console.log('Linking issues and PRs in README.md');
13
14const readmepath = path.join(__dirname, '../../', 'README.md');
15
16// Read README.md
17let readme = fs.readFileSync(readmepath, 'utf-8');
18
19let replacements = 0;
20
21// Replace Ferdi issues
22// Regex matches strings that don't begin with a "[", i.e. are not already linked and
23// don't begin with "franz", i.e. are not Franz issues, followed by a "#" and 3 digits to indicate
24// a GitHub issue, and not ending with a "]"
25readme = readme.replace(/(?<!\[|franz)#\d{3}(?!\])/gi, (match) => {
26 const issueNr = match.replace('#', '');
27 replacements += 1;
28 return `[#${issueNr}](https://github.com/getferdi/ferdi/issues/${issueNr})`;
29});
30
31// Replace Franz issues
32// Regex matches strings that don't begin with a "[", i.e. are not already linked
33// followed by a "franz#" and 3 digits to indicate
34// a GitHub issue, and not ending with a "]"
35readme = readme.replace(/(?<!\[)franz#\d{3,}(?!\])/gi, (match) => {
36 const issueNr = match.replace('franz#', '');
37 replacements += 1;
38 return `[franz#${issueNr}](https://github.com/meetfranz/franz/issues/${issueNr})`;
39});
40
41// Link GitHub users
42// Regex matches strings that don't begin with a "[", i.e. are not already linked
43// followed by a "@" and at least one word character and not ending with a "]"
44readme = readme.replace(/(?<!\[)@\w+(?!\])/gi, (match) => {
45 const username = match.replace('@', '');
46 replacements += 1;
47 return `[@${username}](https://github.com/${username})`;
48});
49
50// Write to file
51fs.writeFileSync(readmepath, readme);
52
53console.log(`Added ${replacements} strings`);