-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add generated changelog to the documentation site (#1234)
- Loading branch information
1 parent
c054541
commit 5de31d9
Showing
9 changed files
with
3,159 additions
and
19 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
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
{ | ||
"branches": ["master", "next"] | ||
"branches": ["master", "next"], | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
"@semantic-release/changelog", | ||
"@semantic-release/npm", | ||
"@semantic-release/git" | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const { program } = require('commander'); | ||
const { execSync } = require('child_process'); | ||
const fs = require('fs'); | ||
|
||
program | ||
.requiredOption('--repoUrl <name>', 'Provide a git repo url', 'https://github.com/openedx/paragon') | ||
.action((options) => { | ||
if (fs.existsSync('CHANGELOG.md')) { | ||
throw new Error('CHANGELOG file already exists.'); | ||
} | ||
|
||
const { repoUrl } = options; | ||
const cmd = 'git log --pretty=format:"%h|%H|%ad|%s|%d|%b||" --date=short'; | ||
const commitLog = execSync(cmd, { encoding: 'utf8' }).split('||\n'); | ||
|
||
// store information of the current release while we go over all | ||
// commits between this release and previous one | ||
let bugFixes = ''; | ||
let features = ''; | ||
let header = ''; | ||
let breakingChanges = ''; | ||
let currentTag; | ||
|
||
commitLog.forEach(entry => { | ||
const [shaShort, shaFull, date, commitSubject, refNames, body] = entry.split('|'); | ||
|
||
if (!header) { | ||
header = `## %RELEASE_LINK% (${date})\n\n`; | ||
} | ||
|
||
// check if commit has a tag attached which would indicate a new release | ||
let prevTag = refNames && refNames.match(/tag: (.*?)(,|\))/g); | ||
if (prevTag) { | ||
prevTag = prevTag[0].split(':')[1].trim().slice(0, -1); | ||
} | ||
|
||
// we found a previous release! time to add an entry to CHANGELOG.md | ||
// with all the collected changes between releases | ||
if (prevTag && currentTag) { | ||
fs.appendFileSync('./CHANGELOG.md', header.replace('%RELEASE_LINK%', `[${currentTag}](${repoUrl}/compare/${prevTag}...${currentTag})`)); | ||
if (features) { | ||
fs.appendFileSync('./CHANGELOG.md', `### Features\n${features}\n\n`); | ||
features = ''; | ||
} | ||
if (bugFixes) { | ||
fs.appendFileSync('./CHANGELOG.md', `### Bug Fixes\n${bugFixes}\n\n`); | ||
bugFixes = ''; | ||
} | ||
if (breakingChanges) { | ||
fs.appendFileSync('./CHANGELOG.md', `### BREAKING CHANGES\n${breakingChanges}\n\n`); | ||
breakingChanges = ''; | ||
} | ||
fs.appendFileSync('./CHANGELOG.md', '\n\n'); | ||
header = `## %RELEASE_LINK% (${date})\n\n`; | ||
} | ||
|
||
if (commitSubject) { | ||
let commitMsgToAdd = commitSubject.trim(); | ||
const issue = commitSubject && commitSubject.match(/\(#\d+\)$/g); | ||
|
||
if (issue && issue.length > 0) { | ||
const issueId = issue[0].trim().slice(1, -1); | ||
commitMsgToAdd = commitMsgToAdd.replace(issue[0], `([${issueId}](${repoUrl}/issues/${issueId.slice(1)}))`); | ||
} | ||
|
||
// add link to the commit | ||
commitMsgToAdd = `${commitMsgToAdd} ([${shaShort}](${repoUrl}/commit/${shaFull}))`; | ||
|
||
if (commitMsgToAdd.startsWith('feat:')) { | ||
features += `\n* ${commitMsgToAdd.slice(5)}`; | ||
} else if (commitMsgToAdd.startsWith('fix:')) { | ||
bugFixes += `\n* ${commitMsgToAdd.slice(4)} `; | ||
} | ||
} | ||
|
||
if (body) { | ||
breakingChanges = body.includes('BREAKING CHANGE') && body.split('BREAKING CHANGE').pop().slice(2); | ||
} | ||
|
||
if (prevTag) { | ||
currentTag = prevTag; | ||
} | ||
}); | ||
}); | ||
|
||
program.parse(process.argv); |
Oops, something went wrong.