Skip to content

Commit

Permalink
do not filter commits by defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
sylc committed Feb 26, 2023
1 parent 40a8238 commit 38287f9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
10 changes: 3 additions & 7 deletions plugins/changelog/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from "./deps.ts";
import type { ReleasePlugin } from "../../plugin.ts";
import {
Document,
filters,
defaultFilters,
polyfillVersion,
pushHeader,
pushTag,
Expand All @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/github/mod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReleasePlugin } from "../../plugin.ts";
import {
Document,
filters,
defaultFilters,
polyfillVersion,
pushTag,
render,
Expand Down Expand Up @@ -53,7 +53,7 @@ const plugin: ReleasePlugin<GithubConfig> = {
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)!;
Expand Down
47 changes: 36 additions & 11 deletions src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
{
Expand All @@ -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",
},
];

Expand All @@ -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;
Expand Down Expand Up @@ -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}]`);
Expand Down

0 comments on commit 38287f9

Please sign in to comment.