|
1 |
| -const fs = require('fs'); |
2 |
| -const _ = require('lodash'); |
3 |
| -const childProcess = require('child_process'); |
4 |
| -const fetch = require('node-fetch'); |
5 |
| -const readline = require('readline'); |
6 |
| - |
7 | 1 | const GITHUB_TOKEN = 'xxxx';
|
8 |
| -let LATEST_VERSION = '5.14.0'; |
9 |
| -let NEW_VERSION = '5.15.0'; |
10 |
| -let releaseNotes; |
11 |
| - |
12 |
| -const rl = readline.createInterface({ |
13 |
| - input: process.stdin, |
14 |
| - output: process.stdout |
15 |
| -}); |
16 |
| - |
17 |
| -rl.question(`What is the current version? `, currentVersion => { |
18 |
| - rl.question('What is the next version for release? ', newVersion => { |
19 |
| - LATEST_VERSION = currentVersion; |
20 |
| - NEW_VERSION = newVersion; |
21 |
| - rl.close(); |
22 |
| - }); |
23 |
| -}); |
24 |
| - |
25 |
| -rl.on('close', () => { |
26 |
| - console.info(`Current latest version is v${LATEST_VERSION}`); |
27 |
| - console.info(`Generating release notes out or PRs for v${NEW_VERSION}`); |
28 |
| - run(); |
29 |
| -}); |
30 |
| - |
31 |
| -async function run() { |
32 |
| - const latestReleaseDate = await fetchLatestReleaseDate(LATEST_VERSION); |
33 |
| - const PRs = await fetchMergedPRs(latestReleaseDate); |
34 |
| - generateNotes(PRs); |
35 |
| -} |
36 |
| - |
37 |
| -async function fetchLatestReleaseDate(version) { |
38 |
| - const relesae = childProcess.execSync(`gh release view ${version}`).toString(); |
39 |
| - const releaseMetaData = relesae.split('--')[0]; |
40 |
| - const createDate = _.flow(data => _.split(data, '\n'), |
41 |
| - linesData => _.find(linesData, l => l.startsWith('created')), |
42 |
| - createdData => _.split(createdData, '\t'), |
43 |
| - _.last)(releaseMetaData); |
44 |
| - |
45 |
| - return new Date(createDate); |
46 |
| -} |
47 |
| - |
48 |
| -async function fetchMergedPRs(postMergedDate) { |
49 |
| - const page = 1; |
50 |
| - // process.stderr.write(`Loading page ${page}..`); |
51 |
| - const url = |
52 |
| - 'https://api.github.com/repos/wix/react-native-ui-lib/pulls?' + |
53 |
| - `state=closed&base=master&page=${page}&per_page=100`; |
54 |
| - const headers = {Authorization: `token ${GITHUB_TOKEN}`}; |
55 |
| - const response = await fetch(url, {headers}); |
56 |
| - const PRs = await response.json(); |
57 |
| - |
58 |
| - const relevantPRs = _.flow(prs => _.filter(prs, pr => !!pr.merged_at && new Date(pr.merged_at) > postMergedDate), |
59 |
| - prs => _.sortBy(prs, 'merged_at'), |
60 |
| - prs => |
61 |
| - _.map(prs, pr => ({ |
62 |
| - state: pr.state, |
63 |
| - merged_at: pr.merged_at, |
64 |
| - html_url: pr.html_url, |
65 |
| - branch: pr.head.ref, |
66 |
| - number: pr.number, |
67 |
| - title: pr.title, |
68 |
| - info: parsePR(pr.body) |
69 |
| - })))(PRs); |
70 |
| - |
71 |
| - return relevantPRs; |
72 |
| -} |
73 |
| - |
74 |
| -function parsePR(prContent) { |
75 |
| - const sections = prContent.split('##'); |
76 |
| - |
77 |
| - const PRInfo = {}; |
78 |
| - sections.forEach(section => { |
79 |
| - const lines = section.trim().split('\r\n'); |
80 |
| - const title = lines.splice(0, 1)[0].toLowerCase(); |
81 |
| - const body = lines.join('\r\n'); |
82 |
| - if (title && body) { |
83 |
| - PRInfo[title] = body; |
84 |
| - } |
85 |
| - }); |
86 |
| - |
87 |
| - return PRInfo; |
88 |
| -} |
89 |
| - |
90 |
| -function generateNotes(PRs) { |
91 |
| - const features = [], |
92 |
| - fixes = [], |
93 |
| - infra = [], |
94 |
| - others = []; |
95 |
| - |
96 |
| - PRs.forEach(pr => { |
97 |
| - if (pr.branch.startsWith('feat/')) { |
98 |
| - fixes.push(pr); |
99 |
| - } else if (pr.branch.startsWith('fix/')) { |
100 |
| - features.push(pr); |
101 |
| - } else if (pr.branch.startsWith('infra/')) { |
102 |
| - infra.push(pr); |
103 |
| - } else { |
104 |
| - others.push(pr); |
105 |
| - } |
106 |
| - }); |
107 |
| - |
108 |
| - // features |
109 |
| - addTitle(':gift: Features'); |
110 |
| - features.forEach(addEntry); |
111 |
| - // bug fixes |
112 |
| - addTitle(':wrench: Fixes'); |
113 |
| - fixes.forEach(addEntry); |
114 |
| - // migrations |
115 |
| - addTitle(':bulb: Deprecations & Migrations'); |
116 |
| - infra.forEach(addEntry); |
117 |
| - // Maintenance & Infra |
118 |
| - addTitle(':gear: Maintenance & Infra'); |
119 |
| - // others |
120 |
| - addTitle('OTHERS'); |
121 |
| - others.forEach(addEntry); |
122 |
| - |
123 |
| - fs.writeFileSync(`${process.env.HOME}/Downloads/uilib-release-notes_${NEW_VERSION}.txt`, releaseNotes, { |
124 |
| - encoding: 'utf8' |
125 |
| - }); |
126 |
| - |
127 |
| - console.log(`\x1b[1m\x1b[32m✔\x1b[0m \x1b[32muilib-release-notes.txt was successfully written to ${process.env.HOME}/Downloads\x1b[0m \x1b[1m\x1b[32m✔\x1b[0m`); |
128 |
| -} |
129 |
| - |
130 |
| -function addTitle(title) { |
131 |
| - releaseNotes += `\n\n${title}\n\n`; |
132 |
| -} |
| 2 | +const LATEST_VERSION = '7.3.0'; |
| 3 | +const NEW_VERSION = '7.4.0'; |
| 4 | +const PREFIX = 'uilib'; |
| 5 | +const REPO = 'wix/react-native-ui-lib'; |
133 | 6 |
|
134 |
| -function addEntry(pr) { |
135 |
| - releaseNotes += `• ${pr.info.changelog || pr.title} (#${pr.number}) \n`; |
136 |
| -} |
| 7 | +require('./prReleaseNotesCommon').generateReleaseNotes(LATEST_VERSION, NEW_VERSION, GITHUB_TOKEN, PREFIX, REPO); |
0 commit comments