From 38287f92d0845497701b50a9ed91e8f25009016b Mon Sep 17 00:00:00 2001 From: Sylvain Date: Sun, 26 Feb 2023 21:24:14 +0800 Subject: [PATCH] do not filter commits by defaults --- plugins/changelog/mod.ts | 10 +++------ plugins/github/mod.ts | 4 ++-- src/changelog.ts | 47 ++++++++++++++++++++++++++++++---------- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/plugins/changelog/mod.ts b/plugins/changelog/mod.ts index 03ea35d..5f9cadd 100644 --- a/plugins/changelog/mod.ts +++ b/plugins/changelog/mod.ts @@ -3,7 +3,7 @@ import { join } from "./deps.ts"; import type { ReleasePlugin } from "../../plugin.ts"; import { Document, - filters, + defaultFilters, polyfillVersion, pushHeader, pushTag, @@ -29,12 +29,8 @@ const plugin: ReleasePlugin = { const tag = tags[i]; const parent = i < tags.length - 1 ? tags[i + 1] : undefined; const belonging = commits.filter((_) => _.belongs?.hash === tag.hash); - const filteredTypes = filters.map((f) => f.type); - const filteredCommits = belonging.filter((_) => - filteredTypes.includes(_.cc.type || "") - ); - if (filteredCommits.length) { - pushTag(doc, repo, belonging, filters, tag, "md", parent); + if (belonging.length) { + pushTag(doc, repo, belonging, defaultFilters, tag, "md", parent); } } diff --git a/plugins/github/mod.ts b/plugins/github/mod.ts index 36098a2..bc3e0a2 100644 --- a/plugins/github/mod.ts +++ b/plugins/github/mod.ts @@ -1,7 +1,7 @@ import { ReleasePlugin } from "../../plugin.ts"; import { Document, - filters, + defaultFilters, polyfillVersion, pushTag, render, @@ -53,7 +53,7 @@ const plugin: ReleasePlugin = { const latest = tags[0]; const belonging = commits.filter((_) => _.belongs?.hash === latest.hash); const parent = tags.length > 0 ? tags[1] : undefined; - pushTag(doc, repo, belonging, filters, latest, "github", parent); + pushTag(doc, repo, belonging, defaultFilters, latest, "github", parent); if (!config.options.dry) { const token = Deno.env.get(GITHUB_TOKEN)!; diff --git a/src/changelog.ts b/src/changelog.ts index 4d7d0cb..24bf8bc 100644 --- a/src/changelog.ts +++ b/src/changelog.ts @@ -7,9 +7,13 @@ export interface Filter { title: string; } -export const filters: Filter[] = [ +/** + * Default list of commit type + */ +export const defaultFilters: Filter[] = [ { - type: "breaking", + // type ! means include ! + type: "!", title: "Breaking", }, { @@ -21,12 +25,9 @@ export const filters: Filter[] = [ title: "Bug Fixes", }, { - type: "docs", - title: "Docs", - }, - { - type: "core", - title: "Core", + // empty string means all + type: "", + title: "Others", }, ]; @@ -53,7 +54,7 @@ export function pushChanges( commits: Commit[], style: "github" | "md", ): void { - doc.sections.push(`### ${title}`); + if (title !== '') doc.sections.push(`### ${title}`); const list: string[] = []; for (const commit of commits) { const { hash } = commit; @@ -100,12 +101,36 @@ export function pushTag( doc.sections.push(`## ${tag.version} - ${year}-${month}-${day}`); } + let hasConventionalCommit = false; + // capture all commits by their types for (const filter of filters) { - const filtered = commits.filter((_) => _.cc.type === filter.type); + let title = filter.title + let filtered; + if (filter.type === '!') { + // process breaking change + filtered = commits.filter((commit) => commit.cc.type?.endsWith('!')); + if (filtered.length > 0) hasConventionalCommit = true + } else if (filter.type !== "") { + // use conventional commmits as defined in filters + filtered = commits.filter((commit) => + commit.cc.type?.toLocaleLowerCase() === filter.type.toLocaleLowerCase() + ); + if (filtered.length > 0) hasConventionalCommit = true + } else { + // capture other commits + const types = filters.map((f) => f.type); + filtered = commits.filter((commit) => + !types.includes(commit.cc.type?.toLocaleLowerCase() || "__any__") + ); + } if (filtered.length > 0) { - pushChanges(doc, repo, filter.title, filtered, style); + if (!hasConventionalCommit) { + title = '' + } + pushChanges(doc, repo, title, filtered, style); } } + if (repo.remote && repo.remote.github && parent) { const linkName = `${parent.version}...${tag.version}`; doc.sections.push(`Full Changelog: [${linkName}]`);