Skip to content

Commit

Permalink
feat: add excludeScopes + restrictToTypes options
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Sep 26, 2023
1 parent 78710fd commit dba389d
Show file tree
Hide file tree
Showing 6 changed files with 896 additions and 507 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ jobs:
| `fromTag` | The tag from which the changelog is to be determined (latest) | :white_check_mark: <br> *(unless using `tag`)* | |
| `toTag` | The tag up to which the changelog is to be determined (oldest) | :white_check_mark: <br> *(unless using `tag`)* | |
| `excludeTypes` | A comma-separated list of commit types you want to exclude from the changelog (e.g. `doc,chore,perf`) | :x: | `build,docs,other,style` |
| `excludeScopes` | A comma-separated list of commit scopes you want to include in the changelog (e.g. `dev,release`) | :x: | |
| `restrictToTypes` | A comma-separated list of commit types you want to restrict to for the changelog (e.g. `feat,fix,refactor`). Overrides `excludeTypes` if defined. | :x: | |
| `writeToFile` | Should CHANGELOG.md be updated with latest changelog | :x: | `true` |
| `includeRefIssues` | Should the changelog include the issues referenced for each PR. | :x: | `true` |
| `useGitmojis` | Should type headers be prepended with their related gitmoji | :x: | `true` |
Expand Down
10 changes: 9 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ inputs:
description: Types to exclude from the Changelog
required: false
default: build,docs,other,style
excludeScopes:
description: Scopes to exclude from the Changelog
required: false
default: ''
restrictToTypes:
description: Types to restrict to for the Changelog (overrides excludeTypes if defined)
required: false
default: ''
writeToFile:
description: Should CHANGELOG.md be updated with latest changelog
required: false
Expand All @@ -42,7 +50,7 @@ outputs:
changes:
description: Generated changelog
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'
branding:
icon: wind
Expand Down
28 changes: 23 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ class OidcClient {
.catch(error => {
throw new Error(`Failed to get ID Token. \n
Error Code : ${error.statusCode}\n
Error Message: ${error.result.message}`);
Error Message: ${error.message}`);
});
const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value;
if (!id_token) {
Expand Down Expand Up @@ -27916,7 +27916,7 @@ const { setTimeout } = __nccwpck_require__(8670)

const githubServerUrl = process.env.GITHUB_SERVER_URL || 'https://github.com'

const types = [
const allTypes = [
{ types: ['feat', 'feature'], header: 'New Features', icon: ':sparkles:' },
{ types: ['fix', 'bugfix'], header: 'Bug Fixes', icon: ':bug:', relIssuePrefix: 'fixes' },
{ types: ['perf'], header: 'Performance Improvements', icon: ':zap:' },
Expand Down Expand Up @@ -27976,6 +27976,8 @@ async function main () {
const fromTag = core.getInput('fromTag')
const toTag = core.getInput('toTag')
const excludeTypes = (core.getInput('excludeTypes') || '').split(',').map(t => t.trim())
const excludeScopes = (core.getInput('excludeScopes') || '').split(',').map(t => t.trim())
const restrictToTypes = (core.getInput('restrictToTypes') || '').split(',').map(t => t.trim())
const writeToFile = core.getBooleanInput('writeToFile')
const includeRefIssues = core.getBooleanInput('includeRefIssues')
const useGitmojis = core.getBooleanInput('useGitmojis')
Expand Down Expand Up @@ -28130,6 +28132,7 @@ async function main () {
const changesVar = []
let idx = 0

// -> Handle breaking changes
if (breakingChanges.length > 0) {
changesFile.push(useGitmojis ? '### :boom: BREAKING CHANGES' : '### BREAKING CHANGES')
changesVar.push(useGitmojis ? '### :boom: BREAKING CHANGES' : '### BREAKING CHANGES')
Expand Down Expand Up @@ -28157,10 +28160,22 @@ async function main () {
idx++
}

for (const type of types) {
if (_.intersection(type.types, excludeTypes).length > 0) {
continue
// -> Filter types
const types = []
for (const type of allTypes) {
if (restrictToTypes.length > 0) {
if (_.intersection(type.types, restrictToTypes).length > 0) {
types.push(type)
}
} else {
if (_.intersection(type.types, excludeTypes).length === 0) {
types.push(type)
}
}
}

// -> Group commits by type
for (const type of types) {
const matchingCommits = commitsParsed.filter(c => type.types.includes(c.type))
if (matchingCommits.length < 1) {
continue
Expand All @@ -28175,6 +28190,9 @@ async function main () {
const relIssuePrefix = type.relIssuePrefix || 'addresses'

for (const commit of matchingCommits) {
if (excludeScopes.length > 0 && excludeScopes.includes(commit.scope)) {
continue
}
const scope = commit.scope ? `**${commit.scope}**: ` : ''
const subjectFile = buildSubject({
writeToFile: true,
Expand Down
26 changes: 22 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { setTimeout } = require('timers/promises')

const githubServerUrl = process.env.GITHUB_SERVER_URL || 'https://github.com'

const types = [
const allTypes = [
{ types: ['feat', 'feature'], header: 'New Features', icon: ':sparkles:' },
{ types: ['fix', 'bugfix'], header: 'Bug Fixes', icon: ':bug:', relIssuePrefix: 'fixes' },
{ types: ['perf'], header: 'Performance Improvements', icon: ':zap:' },
Expand Down Expand Up @@ -68,6 +68,8 @@ async function main () {
const fromTag = core.getInput('fromTag')
const toTag = core.getInput('toTag')
const excludeTypes = (core.getInput('excludeTypes') || '').split(',').map(t => t.trim())
const excludeScopes = (core.getInput('excludeScopes') || '').split(',').map(t => t.trim())
const restrictToTypes = (core.getInput('restrictToTypes') || '').split(',').map(t => t.trim())
const writeToFile = core.getBooleanInput('writeToFile')
const includeRefIssues = core.getBooleanInput('includeRefIssues')
const useGitmojis = core.getBooleanInput('useGitmojis')
Expand Down Expand Up @@ -222,6 +224,7 @@ async function main () {
const changesVar = []
let idx = 0

// -> Handle breaking changes
if (breakingChanges.length > 0) {
changesFile.push(useGitmojis ? '### :boom: BREAKING CHANGES' : '### BREAKING CHANGES')
changesVar.push(useGitmojis ? '### :boom: BREAKING CHANGES' : '### BREAKING CHANGES')
Expand Down Expand Up @@ -249,10 +252,22 @@ async function main () {
idx++
}

for (const type of types) {
if (_.intersection(type.types, excludeTypes).length > 0) {
continue
// -> Filter types
const types = []
for (const type of allTypes) {
if (restrictToTypes.length > 0) {
if (_.intersection(type.types, restrictToTypes).length > 0) {
types.push(type)
}
} else {
if (_.intersection(type.types, excludeTypes).length === 0) {
types.push(type)
}
}
}

// -> Group commits by type
for (const type of types) {
const matchingCommits = commitsParsed.filter(c => type.types.includes(c.type))
if (matchingCommits.length < 1) {
continue
Expand All @@ -267,6 +282,9 @@ async function main () {
const relIssuePrefix = type.relIssuePrefix || 'addresses'

for (const commit of matchingCommits) {
if (excludeScopes.length > 0 && excludeScopes.includes(commit.scope)) {
continue
}
const scope = commit.scope ? `**${commit.scope}**: ` : ''
const subjectFile = buildSubject({
writeToFile: true,
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@
},
"homepage": "https://github.com/Requarks/changelog-action#readme",
"dependencies": {
"@actions/core": "1.10.0",
"@actions/core": "1.10.1",
"@actions/github": "5.1.1",
"@conventional-commits/parser": "0.4.1",
"jest": "29.5.0",
"lodash": "4.17.21"
},
"devDependencies": {
"@vercel/ncc": "0.36.1",
"eslint": "8.36.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.27.5",
"@vercel/ncc": "0.38.0",
"eslint": "8.50.0",
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "2.28.1",
"eslint-plugin-n": "16.1.0",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "6.1.1"
"eslint-plugin-promise": "6.1.1",
"jest": "29.7.0"
}
}
Loading

0 comments on commit dba389d

Please sign in to comment.