This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
forked from streamich/git-cz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 use semver from default theme for release notes
- Loading branch information
1 parent
699c5bc
commit f2f4b5d
Showing
3 changed files
with
1,017 additions
and
32 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,23 +1,129 @@ | ||
/* eslint-disable object-property-newline */ | ||
/* eslint-disable indent */ | ||
/* eslint-disable operator-linebreak */ | ||
const types = require('@jeromefitz/git-cz/data/gitmoji').types | ||
const GraphemeSplitter = require('grapheme-splitter') | ||
const isCI = require('is-ci') | ||
// eslint-disable-next-line id-match | ||
const _pullAt = require('lodash/pullAt') | ||
// eslint-disable-next-line global-require, no-unused-expressions | ||
!isCI && require('dotenv').config({ path: './.env' }) | ||
|
||
const splitter = new GraphemeSplitter() | ||
|
||
const typeSpecs = [] | ||
const releaseRules = [] | ||
|
||
Object.keys(types).map((type) => { | ||
typeSpecs.push({ | ||
emoji: types[type].emoji, | ||
section: types[type].section, | ||
semver: types[type].semver, | ||
type: types[type].value, | ||
value: types[type].value, | ||
}) | ||
releaseRules.push({ | ||
release: types[type].release, | ||
type: types[type].emoji, | ||
}) | ||
|
||
return true | ||
}) | ||
|
||
// // semver: major, minor, patch, null | ||
// // sort by above | ||
// typeSpecs = _orderBy(typeSpecs, ['semver'], ['desc']) | ||
|
||
const parserOpts = { | ||
headerPattern: /^(.*?)(?:\((.*)\))?:?\s(.*)$/, | ||
referenceActions: typeSpecs.map(({ type }) => type), | ||
revertPattern: /^Revert\s"([\s\S]*)"\s*This reverts commit (\w*)\./, | ||
} | ||
|
||
const writerOpts = { | ||
// eslint-disable-next-line complexity | ||
transform: (commit) => { | ||
const { type } = commit | ||
|
||
// Rewrite types | ||
const typeSpecIndex = typeSpecs.findIndex( | ||
// eslint-disable-next-line id-length | ||
({ emoji: e, type: t, value: v }) => type === e || type === t || type === v | ||
) | ||
|
||
// eslint-disable-next-line curly, nonblock-statement-body-position | ||
if (typeSpecIndex === -1) return | ||
|
||
const typeSpec = typeSpecs[typeSpecIndex] | ||
|
||
commit.type = `${typeSpec.emoji} ${typeSpec.section}` | ||
commit.typeSpecIndex = typeSpecIndex | ||
|
||
// @note(semver) | ||
if (typeSpec.semver === 'major' || typeSpec.semver === 'breaking') { | ||
commit.order = 1 | ||
} | ||
if (typeSpec.semver === 'minor' || typeSpec.semver === 'feature') { | ||
commit.order = 3 | ||
} | ||
if (typeSpec.semver === 'patch') { | ||
commit.order = 5 | ||
} | ||
if (typeSpec.semver === null) { | ||
commit.order = 7 | ||
} | ||
if (!Boolean(typeSpec.semver)) { | ||
commit.order = 9 | ||
} | ||
|
||
if (typeof commit.hash === 'string') { | ||
commit.hash = commit.hash.substring(0, 7) | ||
} | ||
|
||
const subjectTemp = splitter.splitGraphemes(commit.subject) | ||
const isEmojiMatch = subjectTemp[0] === typeSpec.emoji | ||
const subject = isEmojiMatch | ||
? commit.subject | ||
.replace(_pullAt(subjectTemp, [0]), '') | ||
.replace(_pullAt(subjectTemp, [0]), '') | ||
: commit.subject | ||
|
||
commit.subject = subject | ||
|
||
// eslint-disable-next-line consistent-return | ||
return commit | ||
}, | ||
// eslint-disable-next-line sort-keys | ||
commitsSort: ['order'], | ||
} | ||
|
||
module.exports = { | ||
// eslint-disable-next-line object-property-newline | ||
branches: [{ name: 'main' }, { name: 'canary', prerelease: 'canary' }], | ||
extends: [], | ||
extends: ['semantic-release-commit-filter'], | ||
plugins: [ | ||
[ | ||
'@semantic-release/commit-analyzer', | ||
{ | ||
parserOpts: { | ||
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING'], | ||
}, | ||
parserOpts, | ||
releaseRules, | ||
}, | ||
], | ||
[ | ||
'@semantic-release/release-notes-generator', | ||
{ | ||
parserOpts, | ||
writerOpts, | ||
}, | ||
], | ||
['@semantic-release/npm'], | ||
['@semantic-release/github'], | ||
[ | ||
'@jeromefitz/semantic-release-git', | ||
{ | ||
assets: ['package.json'], | ||
// eslint-disable-next-line quotes | ||
message: `🔖️ {RELEASE_TAG} [skip ci]\n\n{RELEASE_URL}/releases/tag/{RELEASE_TAG}\n\n{RELEASE_NOTES}`, | ||
}, | ||
], | ||
'@semantic-release/release-notes-generator', | ||
'@semantic-release/npm', | ||
'@semantic-release/github', | ||
'@semantic-release/git', | ||
], | ||
} |
Oops, something went wrong.