Skip to content

Commit e8477b1

Browse files
committed
Fix substitutions issues with compose-changelog script
1 parent 0230071 commit e8477b1

File tree

3 files changed

+184
-29
lines changed

3 files changed

+184
-29
lines changed

arduino-ide-extension/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"which": "^1.3.1"
9393
},
9494
"devDependencies": {
95+
"@octokit/rest": "^18.12.0",
9596
"@types/chai": "^4.2.7",
9697
"@types/chai-string": "^1.4.2",
9798
"@types/mocha": "^5.2.7",

arduino-ide-extension/scripts/compose-changelog.js

+61-29
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,73 @@
1010
const response = await octokit.rest.repos.listReleases({
1111
owner: 'arduino',
1212
repo: 'arduino-ide',
13-
});
13+
}).catch(err => {
14+
console.error(err);
15+
process.exit(1);
16+
})
1417

15-
if (!response || response.status !== 200) {
16-
console.log('fancù');
17-
return;
18-
}
1918
const releases = response.data;
2019

2120
let fullChangelog = releases.reduce((acc, item) => {
22-
return acc + `\n\n${item.body}`;
21+
// Process each line separately
22+
const body = item.body.split('\n').map(processLine).join('\n')
23+
// item.name is the name of the release changelog
24+
return acc + `# ${item.name}\n\n${body}\n\n---\n\n`;
2325
}, '');
2426

25-
fullChangelog = replaceIssueNumber(fullChangelog);
26-
fullChangelog = replaceIssueLink(fullChangelog);
27-
fullChangelog = replaceCompareLink(fullChangelog);
28-
2927
console.log(fullChangelog);
3028
})();
3129

32-
const replaceIssueLink = (str) => {
33-
const regex =
34-
/(https:\/\/github\.com\/arduino\/arduino-ide\/(issues|pull)\/(\d*))/gm;
35-
const substr = `[#$3]($1)`;
36-
return str.replace(regex, substr);
37-
};
38-
39-
const replaceIssueNumber = (str) => {
40-
const regex = /#(\d+)/gm;
41-
const subst = `[#$1](https://github.com/arduino/arduino-ide/pull/$1)`;
42-
return str.replace(regex, subst);
43-
};
44-
45-
const replaceCompareLink = (str) => {
46-
const regex =
47-
/(https:\/\/github.com\/arduino\/arduino-ide\/compare\/(.*))\s/gm;
48-
const subst = `[\`$2\`]($1)`;
49-
return str.replace(regex, subst);
50-
};
30+
31+
// processLine applies different substitutions to line string.
32+
// We're assuming that there are no more than one substitution
33+
// per line to be applied.
34+
const processLine = (line) => {
35+
// Check if a link with one of the following format exists:
36+
// * [#123](https://github.com/arduino/arduino-ide/pull/123)
37+
// * [#123](https://github.com/arduino/arduino-ide/issues/123)
38+
// * [#123](https://github.com/arduino/arduino-ide/pull/123/)
39+
// * [#123](https://github.com/arduino/arduino-ide/issues/123/)
40+
// If it does return the line as is.
41+
let r = /(\(|\[)#\d+(\)|\])(\(|\[)https:\/\/github\.com\/arduino\/arduino-ide\/(pull|issues)\/(\d+)\/?(\)|\])/gm;
42+
if (r.test(line)) {
43+
return line;
44+
}
45+
46+
// Check if a issue or PR link with the following format exists:
47+
// * #123
48+
// If it does it's changed to:
49+
// * [#123](https://github.com/arduino/arduino-ide/pull/123)
50+
r = /#(\d+)/gm;
51+
if (r.test(line)) {
52+
return line.replace(r, `[#$1](https://github.com/arduino/arduino-ide/pull/$1)`)
53+
}
54+
55+
// Check if a link with one of the following format exists:
56+
// * https://github.com/arduino/arduino-ide/pull/123
57+
// * https://github.com/arduino/arduino-ide/issues/123
58+
// * https://github.com/arduino/arduino-ide/pull/123/
59+
// * https://github.com/arduino/arduino-ide/issues/123/
60+
// If it does it's changed respectively to:
61+
// * [#123](https://github.com/arduino/arduino-ide/pull/123)
62+
// * [#123](https://github.com/arduino/arduino-ide/issues/123)
63+
// * [#123](https://github.com/arduino/arduino-ide/pull/123/)
64+
// * [#123](https://github.com/arduino/arduino-ide/issues/123/)
65+
r = /(https:\/\/github\.com\/arduino\/arduino-ide\/(pull|issues)\/(\d+)\/?)/gm;
66+
if (r.test(line)) {
67+
return line.replace(r, `[#$3]($1)`);
68+
}
69+
70+
// Check if a link with the following format exists:
71+
// * https://github.com/arduino/arduino-ide/compare/2.0.0-rc2...2.0.0-rc3
72+
// * https://github.com/arduino/arduino-ide/compare/2.0.0-rc2...2.0.0-rc3/
73+
// If it does it's changed to:
74+
// * [`2.0.0-rc2...2.0.0-rc3`](https://github.com/arduino/arduino-ide/compare/2.0.0-rc2...2.0.0-rc3)
75+
r = /(https:\/\/github\.com\/arduino\/arduino-ide\/compare\/([^\/]*))\/?\s?/gm;
76+
if (r.test(line)) {
77+
return line.replace(r, '[`$2`]($1)');;
78+
}
79+
80+
// If nothing matches just return the line as is
81+
return line;
82+
}

yarn.lock

+122
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,26 @@
18241824
dependencies:
18251825
"@octokit/types" "^6.0.3"
18261826

1827+
"@octokit/auth-token@^2.4.4":
1828+
version "2.5.0"
1829+
resolved "https://registry.yarnpkg.com/@octokit/auth-token/-/auth-token-2.5.0.tgz#27c37ea26c205f28443402477ffd261311f21e36"
1830+
integrity sha512-r5FVUJCOLl19AxiuZD2VRZ/ORjp/4IN98Of6YJoJOkY75CIBuYfmiNHGrDwXr+aLGG55igl9QrxX3hbiXlLb+g==
1831+
dependencies:
1832+
"@octokit/types" "^6.0.3"
1833+
1834+
"@octokit/core@^3.5.1":
1835+
version "3.5.1"
1836+
resolved "https://registry.yarnpkg.com/@octokit/core/-/core-3.5.1.tgz#8601ceeb1ec0e1b1b8217b960a413ed8e947809b"
1837+
integrity sha512-omncwpLVxMP+GLpLPgeGJBF6IWJFjXDS5flY5VbppePYX9XehevbDykRH9PdCdvqt9TS5AOTiDide7h0qrkHjw==
1838+
dependencies:
1839+
"@octokit/auth-token" "^2.4.4"
1840+
"@octokit/graphql" "^4.5.8"
1841+
"@octokit/request" "^5.6.0"
1842+
"@octokit/request-error" "^2.0.5"
1843+
"@octokit/types" "^6.0.3"
1844+
before-after-hook "^2.2.0"
1845+
universal-user-agent "^6.0.0"
1846+
18271847
"@octokit/endpoint@^6.0.1":
18281848
version "6.0.11"
18291849
resolved "https://registry.yarnpkg.com/@octokit/endpoint/-/endpoint-6.0.11.tgz#082adc2aebca6dcefa1fb383f5efb3ed081949d1"
@@ -1833,6 +1853,20 @@
18331853
is-plain-object "^5.0.0"
18341854
universal-user-agent "^6.0.0"
18351855

1856+
"@octokit/graphql@^4.5.8":
1857+
version "4.8.0"
1858+
resolved "https://registry.yarnpkg.com/@octokit/graphql/-/graphql-4.8.0.tgz#664d9b11c0e12112cbf78e10f49a05959aa22cc3"
1859+
integrity sha512-0gv+qLSBLKF0z8TKaSKTsS39scVKF9dbMxJpj3U0vC7wjNWFuIpL/z76Qe2fiuCbDRcJSavkXsVtMS6/dtQQsg==
1860+
dependencies:
1861+
"@octokit/request" "^5.6.0"
1862+
"@octokit/types" "^6.0.3"
1863+
universal-user-agent "^6.0.0"
1864+
1865+
"@octokit/openapi-types@^11.2.0":
1866+
version "11.2.0"
1867+
resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-11.2.0.tgz#b38d7fc3736d52a1e96b230c1ccd4a58a2f400a6"
1868+
integrity sha512-PBsVO+15KSlGmiI8QAzaqvsNlZlrDlyAJYcrXBCvVUxCp7VnXjkwPoFHgjEJXx3WF9BAwkA6nfCUA7i9sODzKA==
1869+
18361870
"@octokit/openapi-types@^5.3.2":
18371871
version "5.3.2"
18381872
resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-5.3.2.tgz#b8ac43c5c3d00aef61a34cf744e315110c78deb4"
@@ -1850,11 +1884,23 @@
18501884
dependencies:
18511885
"@octokit/types" "^2.0.1"
18521886

1887+
"@octokit/plugin-paginate-rest@^2.16.8":
1888+
version "2.17.0"
1889+
resolved "https://registry.yarnpkg.com/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.17.0.tgz#32e9c7cab2a374421d3d0de239102287d791bce7"
1890+
integrity sha512-tzMbrbnam2Mt4AhuyCHvpRkS0oZ5MvwwcQPYGtMv4tUa5kkzG58SVB0fcsLulOZQeRnOgdkZWkRUiyBlh0Bkyw==
1891+
dependencies:
1892+
"@octokit/types" "^6.34.0"
1893+
18531894
"@octokit/plugin-request-log@^1.0.0":
18541895
version "1.0.3"
18551896
resolved "https://registry.yarnpkg.com/@octokit/plugin-request-log/-/plugin-request-log-1.0.3.tgz#70a62be213e1edc04bb8897ee48c311482f9700d"
18561897
integrity sha512-4RFU4li238jMJAzLgAwkBAw+4Loile5haQMQr+uhFq27BmyJXcXSKvoQKqh0agsZEiUlW6iSv3FAgvmGkur7OQ==
18571898

1899+
"@octokit/plugin-request-log@^1.0.4":
1900+
version "1.0.4"
1901+
resolved "https://registry.yarnpkg.com/@octokit/plugin-request-log/-/plugin-request-log-1.0.4.tgz#5e50ed7083a613816b1e4a28aeec5fb7f1462e85"
1902+
integrity sha512-mLUsMkgP7K/cnFEw07kWqXGF5LKrOkD+lhCrKvPHXWDywAwuDUeDwWBpc69XK3pNX0uKiVt8g5z96PJ6z9xCFA==
1903+
18581904
"@octokit/plugin-rest-endpoint-methods@2.4.0":
18591905
version "2.4.0"
18601906
resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-2.4.0.tgz#3288ecf5481f68c494dd0602fc15407a59faf61e"
@@ -1863,6 +1909,14 @@
18631909
"@octokit/types" "^2.0.1"
18641910
deprecation "^2.3.1"
18651911

1912+
"@octokit/plugin-rest-endpoint-methods@^5.12.0":
1913+
version "5.13.0"
1914+
resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.13.0.tgz#8c46109021a3412233f6f50d28786f8e552427ba"
1915+
integrity sha512-uJjMTkN1KaOIgNtUPMtIXDOjx6dGYysdIFhgA52x4xSadQCz3b/zJexvITDVpANnfKPW/+E0xkOvLntqMYpviA==
1916+
dependencies:
1917+
"@octokit/types" "^6.34.0"
1918+
deprecation "^2.3.1"
1919+
18661920
"@octokit/request-error@^1.0.2":
18671921
version "1.2.1"
18681922
resolved "https://registry.yarnpkg.com/@octokit/request-error/-/request-error-1.2.1.tgz#ede0714c773f32347576c25649dc013ae6b31801"
@@ -1881,6 +1935,15 @@
18811935
deprecation "^2.0.0"
18821936
once "^1.4.0"
18831937

1938+
"@octokit/request-error@^2.0.5", "@octokit/request-error@^2.1.0":
1939+
version "2.1.0"
1940+
resolved "https://registry.yarnpkg.com/@octokit/request-error/-/request-error-2.1.0.tgz#9e150357831bfc788d13a4fd4b1913d60c74d677"
1941+
integrity sha512-1VIvgXxs9WHSjicsRwq8PlR2LR2x6DwsJAaFgzdi0JfJoGSO8mYI/cHJQ+9FbN21aa+DrgNLnwObmyeSC8Rmpg==
1942+
dependencies:
1943+
"@octokit/types" "^6.0.3"
1944+
deprecation "^2.0.0"
1945+
once "^1.4.0"
1946+
18841947
"@octokit/request@^5.2.0":
18851948
version "5.4.14"
18861949
resolved "https://registry.yarnpkg.com/@octokit/request/-/request-5.4.14.tgz#ec5f96f78333bb2af390afa5ff66f114b063bc96"
@@ -1895,6 +1958,18 @@
18951958
once "^1.4.0"
18961959
universal-user-agent "^6.0.0"
18971960

1961+
"@octokit/request@^5.6.0":
1962+
version "5.6.3"
1963+
resolved "https://registry.yarnpkg.com/@octokit/request/-/request-5.6.3.tgz#19a022515a5bba965ac06c9d1334514eb50c48b0"
1964+
integrity sha512-bFJl0I1KVc9jYTe9tdGGpAMPy32dLBXXo1dS/YwSCTL/2nd9XeHsY616RE3HPXDVk+a+dBuzyz5YdlXwcDTr2A==
1965+
dependencies:
1966+
"@octokit/endpoint" "^6.0.1"
1967+
"@octokit/request-error" "^2.1.0"
1968+
"@octokit/types" "^6.16.1"
1969+
is-plain-object "^5.0.0"
1970+
node-fetch "^2.6.7"
1971+
universal-user-agent "^6.0.0"
1972+
18981973
"@octokit/rest@^16.28.4":
18991974
version "16.43.2"
19001975
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-16.43.2.tgz#c53426f1e1d1044dee967023e3279c50993dd91b"
@@ -1917,6 +1992,16 @@
19171992
once "^1.4.0"
19181993
universal-user-agent "^4.0.0"
19191994

1995+
"@octokit/rest@^18.12.0":
1996+
version "18.12.0"
1997+
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-18.12.0.tgz#f06bc4952fc87130308d810ca9d00e79f6988881"
1998+
integrity sha512-gDPiOHlyGavxr72y0guQEhLsemgVjwRePayJ+FcKc2SJqKUbxbkvf5kAZEWA/MKvsfYlQAMVzNJE3ezQcxMJ2Q==
1999+
dependencies:
2000+
"@octokit/core" "^3.5.1"
2001+
"@octokit/plugin-paginate-rest" "^2.16.8"
2002+
"@octokit/plugin-request-log" "^1.0.4"
2003+
"@octokit/plugin-rest-endpoint-methods" "^5.12.0"
2004+
19202005
"@octokit/types@^2.0.0", "@octokit/types@^2.0.1":
19212006
version "2.16.2"
19222007
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-2.16.2.tgz#4c5f8da3c6fecf3da1811aef678fda03edac35d2"
@@ -1931,6 +2016,13 @@
19312016
dependencies:
19322017
"@octokit/openapi-types" "^5.3.2"
19332018

2019+
"@octokit/types@^6.16.1", "@octokit/types@^6.34.0":
2020+
version "6.34.0"
2021+
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-6.34.0.tgz#c6021333334d1ecfb5d370a8798162ddf1ae8218"
2022+
integrity sha512-s1zLBjWhdEI2zwaoSgyOFoKSl109CUcVBCc7biPJ3aAf6LGLU6szDvi31JPU7bxfla2lqfhjbbg/5DdFNxOwHw==
2023+
dependencies:
2024+
"@octokit/openapi-types" "^11.2.0"
2025+
19342026
"@phosphor/algorithm@1", "@phosphor/algorithm@^1.2.0":
19352027
version "1.2.0"
19362028
resolved "https://registry.yarnpkg.com/@phosphor/algorithm/-/algorithm-1.2.0.tgz#4a19aa59261b7270be696672dc3f0663f7bef152"
@@ -4430,6 +4522,11 @@ before-after-hook@^2.0.0:
44304522
resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-2.2.0.tgz#09c40d92e936c64777aa385c4e9b904f8147eaf0"
44314523
integrity sha512-jH6rKQIfroBbhEXVmI7XmXe3ix5S/PgJqpzdDPnR8JGLHWNYLsYZ6tK5iWOF/Ra3oqEX0NobXGlzbiylIzVphQ==
44324524

4525+
before-after-hook@^2.2.0:
4526+
version "2.2.2"
4527+
resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-2.2.2.tgz#a6e8ca41028d90ee2c24222f201c90956091613e"
4528+
integrity sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ==
4529+
44334530
bent@^7.1.0:
44344531
version "7.3.12"
44354532
resolved "https://registry.yarnpkg.com/bent/-/bent-7.3.12.tgz#e0a2775d4425e7674c64b78b242af4f49da6b035"
@@ -10295,6 +10392,13 @@ node-fetch@^2.5.0, node-fetch@^2.6.0, node-fetch@^2.6.1:
1029510392
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
1029610393
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
1029710394

10395+
node-fetch@^2.6.7:
10396+
version "2.6.7"
10397+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
10398+
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
10399+
dependencies:
10400+
whatwg-url "^5.0.0"
10401+
1029810402
node-gyp@^5.0.2:
1029910403
version "5.1.1"
1030010404
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-5.1.1.tgz#eb915f7b631c937d282e33aed44cb7a025f62a3e"
@@ -13864,6 +13968,11 @@ tr46@^1.0.1:
1386413968
dependencies:
1386513969
punycode "^2.1.0"
1386613970

13971+
tr46@~0.0.3:
13972+
version "0.0.3"
13973+
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
13974+
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=
13975+
1386713976
trash@^6.1.1:
1386813977
version "6.1.1"
1386913978
resolved "https://registry.yarnpkg.com/trash/-/trash-6.1.1.tgz#8fb863421b31f32571f2650b53534934d5e63025"
@@ -14494,6 +14603,11 @@ wcwidth@^1.0.0, wcwidth@^1.0.1:
1449414603
dependencies:
1449514604
defaults "^1.0.3"
1449614605

14606+
webidl-conversions@^3.0.0:
14607+
version "3.0.1"
14608+
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
14609+
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=
14610+
1449714611
webidl-conversions@^4.0.2:
1449814612
version "4.0.2"
1449914613
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
@@ -14581,6 +14695,14 @@ whatwg-mimetype@^2.1.0, whatwg-mimetype@^2.2.0:
1458114695
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
1458214696
integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==
1458314697

14698+
whatwg-url@^5.0.0:
14699+
version "5.0.0"
14700+
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
14701+
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
14702+
dependencies:
14703+
tr46 "~0.0.3"
14704+
webidl-conversions "^3.0.0"
14705+
1458414706
whatwg-url@^6.4.1:
1458514707
version "6.5.0"
1458614708
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.5.0.tgz#f2df02bff176fd65070df74ad5ccbb5a199965a8"

0 commit comments

Comments
 (0)