Skip to content

Commit

Permalink
build: added custom changelog generation & improved danger checks (#45)
Browse files Browse the repository at this point in the history
* build: added custom changelog generation & improved danger checks

* ci: fixed snapshot table collapsible title

* ci: added full file path to linked filenames
  • Loading branch information
lbragile authored Jan 28, 2022
1 parent b51afba commit fa485b8
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 113 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
*.yaml linguist-detectable=false
*.md linguist-detectable=false
*.sh linguist-detectable=false
*.hbs linguist-detectable=false
.env linguist-detectable=false
.env.example linguist-detectable=false
.husky/* linguist-detectable=false
50 changes: 33 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@ All notable changes to TabMerger will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and TabMerger adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/lbragile/TabMerger/compare/v2.0.0...HEAD) (11 January 2022)
<!-- add-changelog-start -->

<!-- add-changelog-end -->

## [Unreleased](https://github.com/lbragile/TabMerger/compare/v2.0.0...HEAD) (Jan 26 2022)

### Added

- Global settings menu [`!42`](https://github.com/lbragile/TabMerger/pull/42)
- Success button on save [`#41`](https://github.com/lbragile/TabMerger/issues/41)
- Basic theme logic & colors in `ThemeProvider` [`#41`](https://github.com/lbragile/TabMerger/issues/41)
- `removeFile` and `erase` history abilities based on user input [`#41`](https://github.com/lbragile/TabMerger/issues/41)
- Auto export and sync functionality [`#41`](https://github.com/lbragile/TabMerger/issues/41)
- UI to `General` & `Filter` tabs [`#41`](https://github.com/lbragile/TabMerger/issues/41)
- Default group info change & extracted common values into constants [`#41`](https://github.com/lbragile/TabMerger/issues/41)
- Ability to focus search bar using shortcuts [`#41`](https://github.com/lbragile/TabMerger/issues/41)
- Keyboard shortcut commands [`#41`](https://github.com/lbragile/TabMerger/issues/41)
- `enter` (blur) vs `ctrl + enter` (show dropdown) in window title edit mode [`#38`](https://github.com/lbragile/TabMerger/issues/38)
- Window renaming abilities [`#38`](https://github.com/lbragile/TabMerger/issues/38)
- Color Picker [`e3af217`](https://github.com/lbragile/TabMerger/commit/e3af2178d456e106e304186abec5082ad7ee43a9)
- Import Functionality [`7fc174c`](https://github.com/lbragile/TabMerger/commit/7fc174c8f031b3874b8c781d93ac37ce7e90caa7)
- HTML export logic - note about downloads folder & copy indicator [`3423a6d`](https://github.com/lbragile/TabMerger/commit/3423a6dee2753259dc4001ce83046d80f63ceb1c)
Expand All @@ -27,6 +42,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Fixed

- Local storage for enabling/disabling keyboard shortcuts [`#41`](https://github.com/lbragile/TabMerger/issues/41)
- Tab and window delete logic [`4fa8c8b`](https://github.com/lbragile/TabMerger/commit/4fa8c8bb1e531daea444190670382b7eba8b8a85)
- Color picker issues [`2dc7057`](https://github.com/lbragile/TabMerger/commit/2dc70577fb0fa9f2d119a61caf71bc2c1f05dbdf)
- Settings dropdown styling & used outside click to hide window context menu [`3df317e`](https://github.com/lbragile/TabMerger/commit/3df317e5a0cb58c72df1c407a996c89a8c01f398)
Expand All @@ -43,6 +59,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Changed

- Theme values & improved tab index mobility for groups [`#41`](https://github.com/lbragile/TabMerger/issues/41)
- Dark mode theme for many components [`#41`](https://github.com/lbragile/TabMerger/issues/41)
- Position of close icon in window & shape in tab [`8bbbd5e`](https://github.com/lbragile/TabMerger/commit/8bbbd5eec0405e2ce1d6cd07f71fc7c7389c20ab)
- Visibility of tabs on window drag [`fb386c7`](https://github.com/lbragile/TabMerger/commit/fb386c76494c74ac94904f51a49cdf097d42f88f)
- Improved element keyboard focus [`4fa8c8b`](https://github.com/lbragile/TabMerger/commit/4fa8c8bb1e531daea444190670382b7eba8b8a85)
Expand All @@ -51,9 +69,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Styling of window [`060fb8c`](https://github.com/lbragile/TabMerger/commit/060fb8c61a6911c94edc62b64ad26c3681ab5641)
- Icon for search with a button toggle. Tab count for each window within a group [`060fb8c`](https://github.com/lbragile/TabMerger/commit/060fb8c61a6911c94edc62b64ad26c3681ab5641)

<!-- auto-changelog-above -->

## [v2.0.0](https://github.com/lbragile/TabMerger/compare/v1.6.2...v2.0.0) (06 March 2021)
## [v2.0.0](https://github.com/lbragile/TabMerger/compare/v1.6.2...v2.0.0) (Mar 06 2021)

### Added

Expand All @@ -73,7 +89,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Confirmation boxes with sleek notification menus
- Extra details on main page that are relevant to each user

## [v1.6.2](https://github.com/lbragile/TabMerger/compare/v1.6.1...v1.6.2) (16 February 2021)
## [v1.6.2](https://github.com/lbragile/TabMerger/compare/v1.6.1...v1.6.2) (Feb 16 2021)

### Added

Expand All @@ -90,7 +106,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

- Merge button icons to remove confusion on direction of merging and popup text

## [v1.6.1](https://github.com/lbragile/TabMerger/compare/v1.6.0...v1.6.1) (06 February 2021)
## [v1.6.1](https://github.com/lbragile/TabMerger/compare/v1.6.0...v1.6.1) (Feb 06 2021)

### Fixed

Expand All @@ -100,7 +116,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

- Hidden/empty (no tab) groups from the print friendly PDF

## [v1.6.0](https://github.com/lbragile/TabMerger/compare/v1.5.0...v1.6.0) (04 February 2021)
## [v1.6.0](https://github.com/lbragile/TabMerger/compare/v1.5.0...v1.6.0) (Feb 04 2021)

### Added

Expand Down Expand Up @@ -130,7 +146,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Page UI improvements
- Fail safe JSON property names to allow better imports from similarly structured JSON files generated by other applications

## [v1.5.0](https://github.com/lbragile/TabMerger/compare/v1.4.3...v1.5.0) (08 January 2021)
## [v1.5.0](https://github.com/lbragile/TabMerger/compare/v1.4.3...v1.5.0) (Jan 08 2021)

### Changed

Expand All @@ -140,13 +156,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Scroll to bottom upon adding group
- New homepage website which loads much faster, providing better User Experience

## [v1.4.1 - v1.4.3](https://github.com/lbragile/TabMerger/compare/v1.4.0...v1.4.3) (22 December 2020)
## [v1.4.3](https://github.com/lbragile/TabMerger/compare/v1.4.0...v1.4.3) (Dec 22 2020)

### Fixed

- Bugs in sync & incognito operation (stable as of v1.4.3)

## [v1.4.0](https://github.com/lbragile/TabMerger/compare/v1.3.0...v1.4.0) (21 December 2020)
## [v1.4.0](https://github.com/lbragile/TabMerger/compare/v1.3.0...v1.4.0) (Dec 21 2020)

### Changed

Expand All @@ -158,7 +174,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

- Deprecated PDF Export

## [v1.3.0 - v1.3.1](https://github.com/lbragile/TabMerger/compare/v1.2.1...v1.3.0) (14 December 2020)
## [v1.3.1](https://github.com/lbragile/TabMerger/compare/v1.2.1...v1.3.0) (Dec 14 2020)

### Added

Expand All @@ -175,7 +191,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

- Can restore settings back to default

## [v1.2.1](https://github.com/lbragile/TabMerger/compare/v1.2.0...v1.2.1) (06 December 2020)
## [v1.2.1](https://github.com/lbragile/TabMerger/compare/v1.2.0...v1.2.1) (Dec 06 2020)

## Added

Expand All @@ -189,7 +205,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Better UI for both FireFox and Chrome versions
- Further support for languages added

## [v1.2.0](https://github.com/lbragile/TabMerger/compare/bd7f947...v1.2.0) (03 December 2020)
## [v1.2.0](https://github.com/lbragile/TabMerger/compare/bd7f947...v1.2.0) (Dec 03 2020)

### Added

Expand All @@ -200,27 +216,27 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- New tab merging functionality allows user to merge within each group directly
- Better logic for merging prevents extension page from "moving around"

## [v1.1.3](https://github.com/lbragile/TabMerger/compare/20533f0...bd7f947) (01 December 2020)
## [v1.1.3](https://github.com/lbragile/TabMerger/compare/20533f0...bd7f947) (Dec 01 2020)

### Fixed

- Issue where extension icon click caused items to close without being merged in FireFox
- Group title change persistence

## [v1.1.0 - v1.1.2](https://github.com/lbragile/TabMerger/compare/f61488f...20533f0) (30 November 2020)
## [v1.1.2](https://github.com/lbragile/TabMerger/compare/f61488f...20533f0) (Nov 30 2020)

### Added

- Dark Mode
- [FireFox](https://addons.mozilla.org/en-CA/firefox/addon/tabmerger/) support

## [v1.0.1](https://github.com/lbragile/TabMerger/compare/bae006f...f61488f) (28 November 2020)
## [v1.0.1](https://github.com/lbragile/TabMerger/compare/bae006f...f61488f) (Nov 28 2020)

### Added

- Demo video and improved UI
- Broader language support

## [v1.0.0](https://github.com/lbragile/TabMerger/compare/5ffab12...bae006f) (28 November 2020)
## [v1.0.0](https://github.com/lbragile/TabMerger/compare/5ffab12...bae006f) (Nov 28 2020)

- Initial release includes core merging, grouping, restoring functionality
119 changes: 119 additions & 0 deletions autoChangeLog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { execSync } = require("child_process");
const fs = require("fs");

/**
* @see https://stackoverflow.com/questions/14618022/how-does-git-log-since-count
*/
const afterDate = "2022-01-26T00:00:00-08:00";

const data = execSync(`git log --after=${afterDate}`, { encoding: "utf-8" });
const latestTag = execSync("git describe --tags --abbrev=0", { encoding: "utf-8" }).replace("\n", "");

const commitArr: string[] = data
.replace(/(?<=commit\s\w{40}\n)(?:.+\n){2,3}/g, "")
.split(/commit\s/)
.filter((x: string) => x !== "");

function addMarkdownEntries(type: keyof typeof keepAChangeLog, title: string) {
if (keepAChangeLog[type].length > 0) {
markdownStr += `\n${title}\n\n`;

keepAChangeLog[type].forEach((item) => {
const baseURL = `https://github.com/lbragile/TabMerger/${
item.type === "pr" ? "pull" : item.type === "issue" ? "issues" : "commit"
}`;

const id = item.type === "pr" ? `!${item.id}` : item.type === "issue" ? `#${item.id}` : item.hash.slice(0, 7);
const path = item.type === "regular" ? item.hash : item.id;
markdownStr += `- ${item.subject[0].toUpperCase() + item.subject.slice(1)} [\`${id}\`](${baseURL}/${path})\n`;
});
}
}

const keepAChangeLog: Record<
"added" | "fixed" | "changed" | "removed",
{ type: "pr" | "issue" | "regular"; hash: string; subject: string; id?: string }[]
> = {
added: [],
fixed: [],
changed: [],
removed: []
};

const getRegExp = (ending: string) => new RegExp(`(feat|fix|perf|refactor|test)(\\(.+?\\))?:\\s${ending}`, "i");

const insertIntoChangeLog = (type: keyof typeof keepAChangeLog, commit: string) => {
const hash = commit.slice(0, 40);

const result = commit.match(/((feat|fix|perf|refactor|test)(\(.+?\))?:\s.+?\s(?<subject>.+))\n/);
const { subject } = result?.groups ?? {};

if (commit.includes("Merge pull request #")) {
const result = commit.match(/Merge pull request #(?<id>\d+)\s/);
const { id } = result?.groups ?? {};
keepAChangeLog[type].push({ type: "pr", hash, subject, id });
} else if (commit.includes("Refs: #")) {
const result = commit.match(/Refs: #(?<id>\d+)\s/);
const { id } = result?.groups ?? {};
keepAChangeLog[type].push({ type: "issue", hash, subject, id });
} else {
keepAChangeLog[type].push({ type: "regular", hash, subject });
}
};

function formatByteStr(bytes: number) {
const [kiloBytes, megaBytes, gigaBytes] = [1, 2, 3].map((exp) => 1e3 ** exp);

const outputStr =
bytes < kiloBytes
? bytes + " B"
: bytes < megaBytes
? (bytes / kiloBytes).toFixed(2) + " KB"
: bytes < gigaBytes
? (bytes / megaBytes).toFixed(2) + " MB"
: (bytes / gigaBytes).toFixed(2) + " GB";

return outputStr;
}

commitArr.forEach((commit) => {
if (getRegExp("add(ed)?").test(commit)) {
insertIntoChangeLog("added", commit);
} else if (getRegExp("fix(ed)?").test(commit)) {
insertIntoChangeLog("fixed", commit);
} else if (getRegExp("(changed?|adjust(ed)?|updated?|upgraded?)").test(commit)) {
insertIntoChangeLog("changed", commit);
} else if (getRegExp("removed?").test(commit)) {
insertIntoChangeLog("removed", commit);
}
});

const dateStr = new Date().toDateString().slice(4);
let markdownStr = `\n## [Unreleased](https://github.com/lbragile/TabMerger/compare/${latestTag}...HEAD) (${dateStr})\n`;

addMarkdownEntries("added", "### Added");
addMarkdownEntries("fixed", "### Fixed");
addMarkdownEntries("changed", "### Changed");
addMarkdownEntries("removed", "### Removed");

const CHANGELOG_PATH = "CHANGELOG.md";
fs.readFile(CHANGELOG_PATH, "utf8", function (err: Error, data: string) {
if (err) return console.error(err);

const startComment = "<!-- add-changelog-start -->";
const endComment = "<!-- add-changelog-end -->";
const replaceText = new RegExp(`(?<=${startComment})(.*)(?=${endComment})`, "s");
const match = data.match(replaceText);

if (match) {
const text = data.replace(replaceText, markdownStr);

fs.writeFile(CHANGELOG_PATH, text, (err: Error) => {
if (err) return console.error(err);
console.info(`[Auto Changelog]: Success 🎉 - wrote ${formatByteStr(markdownStr.length)}`);
});
} else {
console.info(`[Auto Changelog]: Failure ❌ - could not find start/end comments`);
}
});
7 changes: 0 additions & 7 deletions config/auto-changelog.json

This file was deleted.

15 changes: 10 additions & 5 deletions dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function generateCollapsibleList(items: string[], summary: string): string {
<details>
<summary>${summary}</summary>
<ul>
${items.map((item) => `<li>${danger.github.utils.fileLinks([item])}</li>`).join("\n")}
${items.map((item) => `<li>${danger.github.utils.fileLinks([item], false)}</li>`).join("\n")}
</ul>
</details>
`;
Expand Down Expand Up @@ -46,16 +46,15 @@ function formatByteStr(bytes: number, addPrefix = false) {
const subject = commit.message.split("\n")[0];

return (
(!subject.match(/^(feat|fix|build|chore|ci|style|refactor|perf|test|docs):/i) &&
(!subject.match(/^(feat|fix|build|chore|ci|style|refactor|perf|test|docs)(\(.+?\))?:/i) &&
!subject.includes("Merge pull request")) ||
subject.length > LONG_COMMIT_MESSAGE_THRESHOLD
);
});

const MALFORMED_COMMIT_MESSAGE = `
Some commit messages do not match the expected format (helps us generate changelogs).
<br />
<br />
<details>
<summary>Violating Commits</summary>
<ul>
Expand All @@ -64,6 +63,7 @@ function formatByteStr(bytes: number, addPrefix = false) {
.join("\n")}
</ul>
</details>
See ${danger.utils.href(
"https://www.conventionalcommits.org/en/v1.0.0/",
"Conventional Commits"
Expand Down Expand Up @@ -110,14 +110,17 @@ function formatByteStr(bytes: number, addPrefix = false) {
Comparing: ${danger.git.base.slice(0, 7)}...${danger.git.head.slice(0, 7)}
<details>
<summary>Insights</summary>
<b>Note:</b> the following excludes changes to \`pnpm-lock.yaml\` due to its volatile nature.
| Filename | Base | Current | +/- | % |
|---------:|:----:|:-------:|:---|:---|
${fileSizeMapper
.map(
(item) =>
`| ${danger.github.utils.fileLinks([item.filename])} | ${item.base} | ${item.current} | ${item.diff} | ${
`| ${danger.github.utils.fileLinks([item.filename], false)} | ${item.base} | ${item.current} | ${item.diff} | ${
item.percent
} |`
)
Expand All @@ -127,6 +130,8 @@ function formatByteStr(bytes: number, addPrefix = false) {
true
)} | ${getPrefixSymbol(totalPercentage)}${totalPercentage.toFixed(2)}% |
</details>
### Summary
${generateCollapsibleList(danger.git.modified_files, "Changed Files")}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"stylelint-processor-styled-components": "^1.10.0",
"stylelint-webpack-plugin": "^3.1.1",
"ts-loader": "^9.2.6",
"ts-node-dev": "^1.1.8",
"tsconfig-paths-webpack-plugin": "^3.5.2",
"typescript": "^4.5.4",
"url-loader": "^4.1.1",
Expand All @@ -83,7 +84,7 @@
"webpack": "webpack --config config/webpack.config.js --progress",
"start": "cross-env NODE_ENV=development pnpm webpack",
"build": "cross-env NODE_ENV=production pnpm webpack",
"changelog": "auto-changelog --config ./config/auto-changelog.json"
"changelog": "pnpm ts-node-dev autoChangeLog.ts"
},
"babel": {
"extends": "./config/.babelrc.json"
Expand Down
Loading

0 comments on commit fa485b8

Please sign in to comment.