This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chore): generating detailed changelog
changelog with issue and commit details will be generated GH-19
- Loading branch information
1 parent
6f4ed1c
commit a328261
Showing
10 changed files
with
2,801 additions
and
1,193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
___ | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |