Skip to content

Commit

Permalink
chore: make the changelog format less noisy (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaiwat10 authored May 29, 2023
1 parent ac9362c commit 3f969c7
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .changeset/breezy-snakes-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
7 changes: 1 addition & 6 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json",
"changelog": [
"@changesets/changelog-github",
{
"repo": "FuelLabs/fuels-ts"
}
],
"changelog": "../scripts/changelog.js",
"commit": false,
"fixed": [["@fuel-ts/*", "fuels"]],
"linked": [],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
},
"homepage": "https://github.com/FuelLabs/fuels-ts#readme",
"devDependencies": {
"@changesets/changelog-github": "^0.4.7",
"@changesets/cli": "^2.25.0",
"@changesets/get-github-info": "^0.5.2",
"@ethersproject/bytes": "^5.7.0",
"@jest/types": "^29.5.0",
"@types/jest": "^29.5.0",
Expand Down
40 changes: 18 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions scripts/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/**
* This script was copied from https://github.com/formidablelabs/urql
*/
const { getInfo } = require('@changesets/get-github-info');
const { config } = require('dotenv');

config();

const REPO = 'FuelLabs/fuels-ts';
const SEE_LINE = /^See:\s*(.*)/i;
const TRAILING_CHAR = /[.;:]$/g;
const listFormatter = new Intl.ListFormat('en-US');

const getSummaryLines = (cs) => {
const lines = cs.summary
.trim()
.split(/[\r\n]+/)
.map((l) => l.trim())
.filter(Boolean);
const size = lines.length;
if (size > 0) {
lines[size - 1] = lines[size - 1].replace(TRAILING_CHAR, '');
}

return lines;
};

/** Creates a "(See X)" string from a template */
const templateSeeRef = (links) => {
const humanReadableLinks = links.filter(Boolean).map((link) => {
if (typeof link === 'string') return link;
return link.pull || link.commit;
});

const size = humanReadableLinks.length;
if (size === 0) return '';

const str = listFormatter.format(humanReadableLinks);
return `(See ${str})`;
};

const changelogFunctions = {
// eslint-disable-next-line @typescript-eslint/require-await
getDependencyReleaseLine: async () => '',
getReleaseLine: async (changeset, _type) => {
let pull;
let commit;
let user;

const lines = getSummaryLines(changeset);
const prLineIndex = lines.findIndex((line) => SEE_LINE.test(line));
if (prLineIndex > -1) {
const match = lines[prLineIndex].match(SEE_LINE);
pull = (match && match[1].trim()) || undefined;
lines.splice(prLineIndex, 1);
}

const [firstLine, ...futureLines] = lines;

if (changeset.commit && !pull) {
const { links } = await getInfo({
repo: REPO,
commit: changeset.commit,
});

pull = links.pull || undefined;
commit = links.commit || undefined;
user = links.user || undefined;
}

let annotation = '';
if (/^\s*fix/i.test(firstLine)) {
annotation = '🐞 ';
}
if (/^\s*feat/i.test(firstLine)) {
annotation = '✨ ';
}
if (/^\s*style/i.test(firstLine)) {
annotation = '💅🏻 ';
}
if (/^\s*doc/i.test(firstLine)) {
annotation = '📃 ';
}

let str = `- ${annotation}${firstLine}`;
if (futureLines.length > 0) {
str += `\n${futureLines.map((l) => ` ${l}`).join('\n')}`;
}

if (user) {
str += `, by ${user}`;
}

if (pull || commit) {
const seeRef = templateSeeRef([pull || commit]);
if (seeRef) str += ` ${seeRef}`;
}

return str;
},
};

module.exports = {
...changelogFunctions,
default: changelogFunctions,
};

0 comments on commit 3f969c7

Please sign in to comment.