Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
feat(chore): generating detailed changelog
Browse files Browse the repository at this point in the history
changelog with issue and commit details will be generated

GH-19
  • Loading branch information
yeshamavani committed Feb 20, 2023
1 parent 6f4ed1c commit a328261
Show file tree
Hide file tree
Showing 10 changed files with 2,801 additions and 1,193 deletions.
3 changes: 2 additions & 1 deletion .cz-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {

scopes: [
{name: 'deps'},
{name: 'chore'},
{name: 'ci-cd'},
{name: 'component'},
{name: 'providers'},
Expand All @@ -48,7 +49,7 @@ module.exports = {
// used if allowCustomScopes is true
customScope: 'Denote the SCOPE of this change:',
subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n',
body: 'Provide a LONGER description of the change (optional). Use "|" to break new line:\n',
body: 'Provide a LONGER description of the change (mandatory). Use "\\n" to break new line:\n',
breaking: 'List any BREAKING CHANGES (optional):\n',
footer: 'List any ISSUES CLOSED by this change (optional). E.g.: GH-144:\n',
confirmCommit: 'Are you sure you want to proceed with the commit above?',
Expand Down
Empty file modified .husky/commit-msg
100644 → 100755
Empty file.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
Empty file modified .husky/prepare-commit-msg
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
'body-leading-blank': [2, 'always'],
'footer-leading-blank': [0, 'always'],
'references-empty': [2, 'never'],
'body-empty': [2, 'never'],
},
parserPreset: {
parserOpts: {
Expand Down
3,833 changes: 2,642 additions & 1,191 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@
"cz-customizable": "^7.0.0",
"cz-customizable-ghooks": "^2.0.0",
"eslint": "^8.33.0",
"git-release-notes": "^5.0.0",
"husky": "^8.0.3",
"jsdom": "^21.1.0",
"pg": "^8.8.0",
"pg-hstore": "^2.3.4",
"semantic-release": "^19.0.5",
"simple-git": "^3.16.1",
"source-map-support": "^0.5.21",
"sqlite3": "^5.1.4",
"typedoc": "^0.23.24",
Expand All @@ -94,7 +97,11 @@
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"override":{
"overrides": {
"git-release-notes": {
"ejs": "^3.1.8",
"yargs": "^17.6.2"
},
"@semantic-release/npm": {
"npm": "^9.4.2"
}
Expand Down
12 changes: 12 additions & 0 deletions src/release_notes/mymarkdown.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Release [<%= range.split('..')[1] %>](https://github.com/sourcefuse/loopback4-sequelize/compare/<%= range %>) <%= new Date().toLocaleDateString('en-us', {year:"numeric", month:"long", day:"numeric"})
;%>
Welcome to the <%= new Date().toLocaleDateString('en-us', {year:"numeric", month:"long", day:"numeric"});%> release of loopback4-sequelize. There are many updates in this version that we hope you will like, the key highlights include:
<% commits.forEach(function (commit) { %>
- [<%= commit.issueTitle %>](https://github.com/sourcefuse/loopback4-sequelize/issues/<%= commit.issueno %>) :- [<%= commit.title %>](https://github.com/sourcefuse/loopback4-sequelize/commit/<%= commit.sha1%>) was commited on <%= commit.committerDate %> by [<%= commit.authorName %>](mailto:<%= commit.authorEmail %>)
<% commit.messageLines.forEach(function (message) { %>
- <%= message %>
<% }) %>
<% }) %>
Clink on the above links to understand the changes in detail.
___
77 changes: 77 additions & 0 deletions src/release_notes/post-processing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const https = require('node:https');
const jsdom = require('jsdom');
module.exports = async function (data, callback) {
const rewritten = [];
for (const commit of data.commits) {
if (commit.title.indexOf('chore(release)') !== -1) {
continue;
}

const commitTitle = commit.title;
commit.title = commitTitle.substring(0, commitTitle.indexOf('#') - 1);

commit.messageLines = commit.messageLines.filter(message => {
if (message.indexOf('efs/remotes/origin') === -1) return message;
});

commit.messageLines.forEach(message => {
commit.issueno = message.includes('GH-')
? message.replace('GH-', '').trim()
: null;
});

const issueDesc = await getIssueDesc(commit.issueno).then(res => {
return res;
});
commit.issueTitle = issueDesc;

commit.committerDate = new Date(commit.committerDate).toLocaleDateString(
'en-us',
{
year: 'numeric',
month: 'long',
day: 'numeric',
},
);
rewritten.push(commit);
}
callback({
commits: rewritten.filter(Boolean),
range: data.range,
});
};

function getIssueDesc(issueNo) {
return new Promise((resolve, reject) => {
let result = '';
const req = https.get(
`https://github.com/sourcefuse/loopback4-sequelize/issues/${encodeURIComponent(
issueNo,
)}`,
res => {
res.setEncoding('utf8');
res.on('data', chunk => {
result = result + chunk;
});
res.on('end', () => {
const {JSDOM} = jsdom;
const dom = new JSDOM(result);
const title = dom.window.document.getElementsByClassName(
'js-issue-title markdown-title',
);
let issueTitle = '';
for (const ele of title) {
if (ele.nodeName === 'BDI') {
issueTitle = ele.innerHTML;
}
}
resolve(issueTitle);
});
},
);
req.on('error', e => {
reject(e);
});
req.end();
});
}
59 changes: 59 additions & 0 deletions src/release_notes/release-notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const releaseNotes = require('git-release-notes');
const simpleGit = require('simple-git/promise');
const path = require('path');
const {readFile, writeFile, ensureFile} = require('fs-extra');

async function generateReleaseNotes() {
try {
const OPTIONS = {
branch: 'master',
s: './post-processing.js',
};
const RANGE = await getRange();
const TEMPLATE = './mymarkdown.ejs';

const changelog = await releaseNotes(OPTIONS, RANGE, TEMPLATE);

const changelogPath = path.resolve(__dirname, '../..', 'CHANGELOG.md');
await ensureFile(changelogPath);
const currentFile = (await readFile(changelogPath)).toString().trim();
if (currentFile) {
console.log('Update %s', changelogPath);
} else {
console.log('Create %s', changelogPath);
}

await writeFile(changelogPath, changelog);
await writeFile(changelogPath, currentFile, {flag: 'a+'});
await addAndCommit().then(() => {
console.log('Changelog has been updated');
});
} catch (ex) {
console.error(ex);
process.exit(1);
}
}

async function getRange() {
const git = simpleGit();
const tags = (await git.tag({'--sort': 'committerdate'})).split('\n');
tags.pop();

const startTag = tags.slice(-2)[0];
const endTag = tags.slice(-1)[0];
return `${startTag}..${endTag}`;
}

async function addAndCommit() {
const git = simpleGit();
await git.add(['../../CHANGELOG.md']);
await git.commit('chore(release): changelog file', {
'--no-verify': null,
});
await git.push('origin', 'master');
}

generateReleaseNotes().catch(ex => {
console.error(ex);
process.exit(1);
});

0 comments on commit a328261

Please sign in to comment.