From 0230071b5f5fccaff1309ef7e189ae8864e457d0 Mon Sep 17 00:00:00 2001 From: Alberto Iannaccone Date: Mon, 24 Jan 2022 15:51:25 +0100 Subject: [PATCH] add script to compose full changelog --- .../scripts/compose-changelog.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 arduino-ide-extension/scripts/compose-changelog.js diff --git a/arduino-ide-extension/scripts/compose-changelog.js b/arduino-ide-extension/scripts/compose-changelog.js new file mode 100755 index 00000000..a1539ce3 --- /dev/null +++ b/arduino-ide-extension/scripts/compose-changelog.js @@ -0,0 +1,50 @@ +// @ts-check + +(async () => { + const { Octokit } = require('@octokit/rest'); + + const octokit = new Octokit({ + userAgent: 'Arduino IDE compose-changelog.js', + }); + + const response = await octokit.rest.repos.listReleases({ + owner: 'arduino', + repo: 'arduino-ide', + }); + + if (!response || response.status !== 200) { + console.log('fancù'); + return; + } + const releases = response.data; + + let fullChangelog = releases.reduce((acc, item) => { + return acc + `\n\n${item.body}`; + }, ''); + + fullChangelog = replaceIssueNumber(fullChangelog); + fullChangelog = replaceIssueLink(fullChangelog); + fullChangelog = replaceCompareLink(fullChangelog); + + console.log(fullChangelog); +})(); + +const replaceIssueLink = (str) => { + const regex = + /(https:\/\/github\.com\/arduino\/arduino-ide\/(issues|pull)\/(\d*))/gm; + const substr = `[#$3]($1)`; + return str.replace(regex, substr); +}; + +const replaceIssueNumber = (str) => { + const regex = /#(\d+)/gm; + const subst = `[#$1](https://github.com/arduino/arduino-ide/pull/$1)`; + return str.replace(regex, subst); +}; + +const replaceCompareLink = (str) => { + const regex = + /(https:\/\/github.com\/arduino\/arduino-ide\/compare\/(.*))\s/gm; + const subst = `[\`$2\`]($1)`; + return str.replace(regex, subst); +};