Skip to content

Commit

Permalink
chore: use custom changelog-stylelint
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Aug 17, 2022
1 parent 8a48536 commit 4448fed
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 40 deletions.
98 changes: 98 additions & 0 deletions .changeset/changelog-stylelint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// @ts-check

// based on https://github.com/changesets/changesets/blob/main/packages/changelog-github/src/index.ts

const { getInfo, getInfoFromPullRequest } = require('@changesets/get-github-info');

/**
* @type {import('@changesets/types').ChangelogFunctions}
*/
const changelogFunctions = {
async getReleaseLine(changeset, _type, options) {
if (!options || !options.repo) {
throw new Error(
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]',
);
}

/**
* @type {number | undefined}
*/
let prFromSummary;
/**
* @type {string | undefined}
*/
let commitFromSummary;
/**
* @type {string[]}
*/
let usersFromSummary = [];

const replacedChangelog = changeset.summary
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
let num = Number(pr);
if (!isNaN(num)) prFromSummary = num;
return '';
})
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
commitFromSummary = commit;
return '';
})
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
usersFromSummary.push(user);
return '';
})
.trim();

const [firstLine, ...futureLines] = replacedChangelog.split('\n').map((l) => l.trimEnd());

const links = await (async () => {
if (prFromSummary !== undefined) {
let { links } = await getInfoFromPullRequest({
repo: options.repo,
pull: prFromSummary,
});
if (commitFromSummary) {
links = {
...links,
commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
};
}
return links;
}
const commitToFetchFrom = commitFromSummary || changeset.commit;
if (commitToFetchFrom) {
let { links } = await getInfo({
repo: options.repo,
commit: commitToFetchFrom,
});
return links;
}
return {
commit: null,
pull: null,
user: null,
};
})();

const users = usersFromSummary.length
? usersFromSummary
.map((userFromSummary) => `[@${userFromSummary}](https://github.com/${userFromSummary})`)
.join(', ')
: links.user;

const suffix = [
links.pull === null ? '' : ` ${links.pull}`,
users === null ? '' : ` Thanks ${users}!`,
].join('');

return `\n\n- ${firstLine}${futureLines.map((l) => ` ${l}`).join('\n')}${
suffix ? ' (' + suffix + ')' : ''
}.\n`;
},
async getDependencyReleaseLine() {
return '';
},
};

module.exports = changelogFunctions;
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://unpkg.com/@changesets/config/schema.json",
"changelog": [
"@changesets/changelog-github",
"./changelog-stylelint",
{
"repo": "stylelint/stylelint"
}
Expand Down
39 changes: 1 addition & 38 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@
"write-file-atomic": "^4.0.1"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.6",
"@changesets/cli": "^2.24.3",
"@changesets/get-github-info": "^0.5.1",
"@stylelint/prettier-config": "^2.0.0",
"@stylelint/remark-preset": "^3.0.0",
"@types/balanced-match": "^1.0.2",
Expand Down

0 comments on commit 4448fed

Please sign in to comment.