Add Changelog generator
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
"jest": "^26.4.2",
|
||||
"lint-staged": "^10.5.3",
|
||||
"minimist": "^1.2.5",
|
||||
"node-fetch": "^2.6.1",
|
||||
"prettier": "1.17.1",
|
||||
"rollup": "^2.7.3",
|
||||
"rollup-plugin-commonjs": "^10.1.0",
|
||||
|
||||
@@ -1,29 +1,76 @@
|
||||
// 'https://api.github.com/repos/lucide-icons/lucide/compare/v0.13.0...master'
|
||||
import output from './tempOutput.json';
|
||||
import githubApi from './githubApi';
|
||||
|
||||
const iconFolderRegex = /icons\/(.*)\.svg/g;
|
||||
const fetchCompareTags = oldTag =>
|
||||
githubApi(`https://api.github.com/repos/lucide-icons/lucide/compare/${oldTag}...master`);
|
||||
|
||||
const changedFiles = output.files.filter(
|
||||
({ filename }) => !filename.match(/site\/(.*)|(.*)package\.json/g),
|
||||
const iconRegex = /icons\/(.*)\.svg/g;
|
||||
const iconTemplate = ({ name, pullNumber, author }) =>
|
||||
`- \`${name}\` (${pullNumber}) by @${author}`;
|
||||
|
||||
const topics = [
|
||||
{
|
||||
title: 'New icons 🎨',
|
||||
template: iconTemplate,
|
||||
filter: ({ status, filename }) => status === 'added' && filename.match(iconRegex),
|
||||
},
|
||||
{
|
||||
title: 'Modified Icons 🔨',
|
||||
template: iconTemplate,
|
||||
filter: ({ status, filename }) => status === 'modified' && filename.match(iconRegex),
|
||||
},
|
||||
{
|
||||
title: 'Code improvements ⚡',
|
||||
template: ({ title, pullNumber, author }) => `- ${title} (${pullNumber}) by @${author}`,
|
||||
filter: ({ filename }, index, self) =>
|
||||
!filename.match(iconRegex) && self.indexOf(filename) === index,
|
||||
},
|
||||
];
|
||||
|
||||
const fetchCommits = async file => {
|
||||
const commits = await githubApi(
|
||||
`https://api.github.com/repos/lucide-icons/lucide/commits?path=${file.filename}`,
|
||||
);
|
||||
|
||||
const addedIcons = changedFiles.filter(
|
||||
({ status, filename }) => status === 'added' && filename.match(iconFolderRegex),
|
||||
);
|
||||
|
||||
const modifiedIcons = changedFiles.filter(
|
||||
({ status, filename }) => status === 'modified' && filename.match(iconFolderRegex),
|
||||
);
|
||||
|
||||
// const addedIconsWithcommits
|
||||
// console.log(modifiedIcons);
|
||||
|
||||
const topics = {
|
||||
newIcons: 'New Icons',
|
||||
modifiedIcons: 'Modified Icons',
|
||||
codeChanges: 'Code improvements',
|
||||
docs: 'Docs',
|
||||
lucide: 'Lucide Package',
|
||||
lucideReact: 'Lucide React Package',
|
||||
lucideVue: 'Lucide Vue Package',
|
||||
return { ...file, commits };
|
||||
};
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
(async function() {
|
||||
const output = await fetchCompareTags('v0.13.0');
|
||||
const changedFiles = output.files.filter(
|
||||
({ filename }) => !filename.match(/site\/(.*)|(.*)package\.json|tags.json/g),
|
||||
);
|
||||
|
||||
const commits = await Promise.all(changedFiles.map(fetchCommits));
|
||||
|
||||
const mappedCommits = commits
|
||||
.map(({ commits: [pr], filename, sha, status }) => {
|
||||
const pullNumber = /(.*)\((#[0-9]*)\)/gm.exec(pr.commit.message);
|
||||
const nameRegex = /^\/?(.+\/)*(.+)\.(.+)$/g.exec(filename);
|
||||
|
||||
return {
|
||||
filename,
|
||||
name: nameRegex && nameRegex[2] ? nameRegex[2] : null,
|
||||
title: pullNumber && pullNumber[1] ? pullNumber[1].trim() : null,
|
||||
pullNumber: pullNumber && pullNumber[2] ? pullNumber[2].trim() : null,
|
||||
author: pr.author.login,
|
||||
sha,
|
||||
status,
|
||||
};
|
||||
})
|
||||
.filter(({ pullNumber }) => !!pullNumber);
|
||||
|
||||
const changelog = topics.map(({ title, filter, template }) => {
|
||||
const lines = mappedCommits.filter(filter).map(template);
|
||||
|
||||
if (lines.length) {
|
||||
return [`## ${title}`, ' ', ...lines, ' '];
|
||||
}
|
||||
|
||||
return [''];
|
||||
});
|
||||
|
||||
const changelogMarkown = changelog.flat().join('\n');
|
||||
|
||||
console.log(changelogMarkown);
|
||||
})();
|
||||
|
||||
22
scripts/githubApi.js
Normal file
22
scripts/githubApi.js
Normal file
@@ -0,0 +1,22 @@
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import fetch, { Headers } from 'node-fetch';
|
||||
|
||||
const githubApi = async endpoint => {
|
||||
const headers = new Headers();
|
||||
const username = 'ericfennis';
|
||||
const password = process.env.GITHUB_API_KEY;
|
||||
|
||||
headers.set(
|
||||
'Authorization',
|
||||
`Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`,
|
||||
);
|
||||
|
||||
const res = await fetch(endpoint, {
|
||||
method: 'GET',
|
||||
headers,
|
||||
});
|
||||
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export default githubApi;
|
||||
@@ -4636,6 +4636,11 @@ node-environment-flags@^1.0.5:
|
||||
object.getownpropertydescriptors "^2.0.3"
|
||||
semver "^5.7.0"
|
||||
|
||||
node-fetch@^2.6.1:
|
||||
version "2.6.1"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
|
||||
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
|
||||
|
||||
node-int64@^0.4.0:
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
|
||||
|
||||
Reference in New Issue
Block a user