-
-
Notifications
You must be signed in to change notification settings - Fork 928
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use custom changelog-stylelint
- Loading branch information
Showing
4 changed files
with
101 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters