|
| 1 | +// @ts-check |
| 2 | + |
| 3 | +(async () => { |
| 4 | + const { Octokit } = require('@octokit/rest'); |
| 5 | + |
| 6 | + const octokit = new Octokit({ |
| 7 | + userAgent: 'Arduino IDE compose-changelog.js', |
| 8 | + }); |
| 9 | + |
| 10 | + const response = await octokit.rest.repos.listReleases({ |
| 11 | + owner: 'arduino', |
| 12 | + repo: 'arduino-ide', |
| 13 | + }); |
| 14 | + |
| 15 | + if (!response || response.status !== 200) { |
| 16 | + console.log('fancù'); |
| 17 | + return; |
| 18 | + } |
| 19 | + const releases = response.data; |
| 20 | + |
| 21 | + let fullChangelog = releases.reduce((acc, item) => { |
| 22 | + return acc + `\n\n${item.body}`; |
| 23 | + }, ''); |
| 24 | + |
| 25 | + fullChangelog = replaceIssueNumber(fullChangelog); |
| 26 | + fullChangelog = replaceIssueLink(fullChangelog); |
| 27 | + fullChangelog = replaceCompareLink(fullChangelog); |
| 28 | + |
| 29 | + console.log(fullChangelog); |
| 30 | +})(); |
| 31 | + |
| 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 | +}; |
0 commit comments