Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sylc committed Mar 6, 2023
1 parent 06adf9a commit 05072ae
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion plugins/changelog/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { join } from "./deps.ts";

import type { ReleasePlugin } from "../../plugin.ts";
import {
significantCommits,
Document,
polyfillVersion,
pushHeader,
pushTag,
render,
significantCommits,
} from "../../src/changelog.ts";

const plugin: ReleasePlugin = {
Expand Down
2 changes: 1 addition & 1 deletion plugins/github/mod.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ReleasePlugin } from "../../plugin.ts";
import {
significantCommits,
Document,
polyfillVersion,
pushTag,
render,
significantCommits,
} from "../../src/changelog.ts";

import * as gh from "./api.ts";
Expand Down
41 changes: 24 additions & 17 deletions src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const significantCommits: Filter[] = [
{
type: "fix",
title: "Bug Fixes",
}
},
];

export interface Document {
Expand All @@ -40,7 +40,7 @@ All notable changes to this project will be documented in this file.`);
/**
* Push a list of commits in the section with a title
* @param title tile of the section in the document
* @param style Style formatting of the document. Github releases have links different from the changelog
* @param style Style formatting of the document. Github releases have links different from the changelog
*/
export function pushChanges(
doc: Document,
Expand Down Expand Up @@ -96,32 +96,39 @@ export function pushTag(
doc.sections.push(`## ${tag.version} - ${year}-${month}-${day}`);
}

const breaking: Commit[] = []
const sections: { [key: string]: Commit[] } = {}
const others: Commit[] = []
const breaking: Commit[] = [];
const sections: { [key: string]: Commit[] } = {};
const others: Commit[] = [];

let hasConventionalCommit = false;
for (const commit of commits) {
const type = commit.cc.type
const type = commit.cc.type;
if (type && commit.cc.header?.includes(`!:`)) {
breaking.push(commit)
hasConventionalCommit = true
} else if (type && significantCommits.map(t => t.type).includes(type)) {
if (!sections[type]) sections[type] = []
sections[type].push(commit)
hasConventionalCommit = true
breaking.push(commit);
hasConventionalCommit = true;
} else if (type && significantCommits.map((t) => t.type).includes(type)) {
if (!sections[type]) sections[type] = [];
sections[type].push(commit);
hasConventionalCommit = true;
} else {
others.push(commit)
others.push(commit);
}
}

if (breaking.length) pushChanges(doc, repo, 'Breaking', breaking, style);
if (breaking.length) pushChanges(doc, repo, "Breaking", breaking, style);
for (const significantCommit of significantCommits) {
if(sections[significantCommit.type]?.length) pushChanges(doc, repo, significantCommit.title, sections[significantCommit.type], style);
if (sections[significantCommit.type]?.length) {
pushChanges(
doc,
repo,
significantCommit.title,
sections[significantCommit.type],
style,
);
}
}
const othersTitle = hasConventionalCommit ? 'Others' : ''
const othersTitle = hasConventionalCommit ? "Others" : "";
if (others.length) pushChanges(doc, repo, othersTitle, others, style);


if (repo.remote && repo.remote.github && parent) {
const linkName = `${parent.version}...${tag.version}`;
Expand Down
4 changes: 3 additions & 1 deletion src/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export async function fetchRawCommits(
const body = `${title}\n${description}`;
const cc = ccparse(body, {
// Allow for ! after the scope
headerPattern: new RegExp(/^(\w*)(?:\(([\w\$\.\-\* ]*)\))?(?:\:|!\:) (.*)$/)
headerPattern: new RegExp(
/^(\w*)(?:\(([\w\$\.\-\* ]*)\))?(?:\:|!\:) (.*)$/,
),
});

return {
Expand Down

0 comments on commit 05072ae

Please sign in to comment.