Skip to content

Commit

Permalink
Fix Release descriptions assuming 1-commit to 1-changeset (#8337)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Cousens <[email protected]>
  • Loading branch information
dcousens and dcousens authored Feb 27, 2023
1 parent 663b8ac commit 279a50c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
8 changes: 4 additions & 4 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@

- [#8280](https://github.com/keystonejs/keystone/pull/8280) [`384748d85`](https://github.com/keystonejs/keystone/commit/384748d85f06755ee7c8aa6f74f0ffae486b82c1) Thanks [@dcousens](https://github.com/dcousens)! - Renames `isValidSession` on `pageMiddleware` to `wasAccessAllowed`, which is what it actually is

- [#8221](https://github.com/keystonejs/keystone/pull/8221) [`88a7c6986`](https://github.com/keystonejs/keystone/commit/88a7c6986fd421be2080cb29ca9c86e8bbc40ae5) Thanks [@borisno2](https://github.com/borisno2)! - Remove experimental `generateNextGraphqlAPI` - use `getContext` instead

### Minor Changes

- [#8321](https://github.com/keystonejs/keystone/pull/8321) [`8e7729880`](https://github.com/keystonejs/keystone/commit/8e7729880606363203d91b1c74a61e58295dadca) Thanks [@MurzNN](https://github.com/MurzNN)! - Extend `db.enableLogging` to support other Prisma log levels

- [#8264](https://github.com/keystonejs/keystone/pull/8264) [`5a9ca539f`](https://github.com/keystonejs/keystone/commit/5a9ca539f714f9dd3b70886710410c28d977045a) Thanks [@jhohlfeld](https://github.com/jhohlfeld)! - Add `acl` option for s3 storage configuration

- [#8241](https://github.com/keystonejs/keystone/pull/8241) [`25a1bf4ed`](https://github.com/keystonejs/keystone/commit/25a1bf4edb9844768e5e30027802365564cacd64) Thanks [@borisno2](https://github.com/borisno2)! - Adds an experimental `extendPrismaSchema` configuration option for lists and fields to mutate the prisma schema
Expand All @@ -32,14 +36,10 @@

- [#8313](https://github.com/keystonejs/keystone/pull/8313) [`75add09c7`](https://github.com/keystonejs/keystone/commit/75add09c7b136ca3f2920fc1d85ffdf10499b3b2) Thanks [@marekryb](https://github.com/marekryb)! - Add a `cursor` argument for `findMany` queries, enabling cursor-based pagination (see [Prisma.io documentation](https://www.prisma.io/docs/concepts/components/prisma-client/pagination#cursor-based-pagination) for how this works)

- [#8221](https://github.com/keystonejs/keystone/pull/8221) [`88a7c6986`](https://github.com/keystonejs/keystone/commit/88a7c6986fd421be2080cb29ca9c86e8bbc40ae5) Thanks [@borisno2](https://github.com/borisno2)! - Remove experimental `generateNextGraphqlAPI` - use `getContext` instead

### Patch Changes

- [#8177](https://github.com/keystonejs/keystone/pull/8177) [`3ef0d9d7d`](https://github.com/keystonejs/keystone/commit/3ef0d9d7d857c622cec95b702ea717fa920f8fc0) Thanks [@borisno2](https://github.com/borisno2)! - Fixes creating new relationships in card view on create item page

- [#8321](https://github.com/keystonejs/keystone/pull/8321) [`8e7729880`](https://github.com/keystonejs/keystone/commit/8e7729880606363203d91b1c74a61e58295dadca) Thanks [@MurzNN](https://github.com/MurzNN)! - Extend `db.enableLogging` to support other Prisma log levels

- [#8239](https://github.com/keystonejs/keystone/pull/8239) [`ebd725938`](https://github.com/keystonejs/keystone/commit/ebd7259383161225c9fcc8597d2e5a13eb2de015) Thanks [@borisno2](https://github.com/borisno2)! - Fixes error when deleting an item that has a file or image that is no longer on the filesystem

- [#8234](https://github.com/keystonejs/keystone/pull/8234) [`d074e42c4`](https://github.com/keystonejs/keystone/commit/d074e42c4cc45bf72aca7a9254057d56516fec58) Thanks [@borisno2](https://github.com/borisno2)! - Export `next/head` for use in auth package
Expand Down
66 changes: 40 additions & 26 deletions scripts/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,19 @@ async function fetchData(tag) {
const previousContributors = JSON.parse(
readFileSync('.changeset/contributors.json').toString('utf-8')
);
const changes = {};

const githubCommits = {};
for (const commit of revs) {
let { user, pull } = await getInfo({ repo: 'keystonejs/keystone', commit });
pull = pull || gitCommitDescription(commit).match(/#([0-9]+)/)?.[1];

console.error(`commit ${commit}, user ${user}, pull #${pull}`);
const change = { commit, user, pull };
changes[commit] = change;

if (previousContributors.includes(user)) continue;
change.first = true;
const first = !previousContributors.includes(user);
githubCommits[commit] = { commit, user, pull, first };
}

// join some of the changeset data with the commit information
// augment changesets with git information
const changes = [];
for (const changeset of changesets) {
const { releases, summary, commit } = changeset;

Expand All @@ -114,22 +113,29 @@ async function fetchData(tag) {
}
if (!type) throw new Error('Unknown type');

const change = changes[commit];
change.changeset = changeset.id;
change.summary = summary;
change.type = type;

// only public packages, then strip the namespace
change.packages = releases
const packages = releases
.filter(x => publicPackages.includes(x.name))
.map(x => x.name.replace('@keystone-6/', ''))
.sort();

const githubCommit = githubCommits[commit];
changes.push({
...githubCommit,
summary,
type,
packages,
});
}

// if no changeset was associated with a commit, we still want to acknowledge the work
for (const [commit, githubCommit] of Object.entries(githubCommits)) {
if (changes.find(x => x.commit === commit)) continue;
changes.push(githubCommit);
}

// tally contributions
const contributors = [
...new Set([...previousContributors, ...Object.values(changes).map(x => x.user)]),
];
// find the set of our contributors
const contributors = [...new Set([...previousContributors, ...changes.map(x => x.user)])];

// only public packages
const packages = releases
Expand All @@ -138,7 +144,7 @@ async function fetchData(tag) {
.map(x => `${x.name}@${x.newVersion}`)
.sort();

return { packages, changes: Object.values(changes), contributors };
return { packages, changes, contributors };
}

function formatPackagesChanged(packages) {
Expand All @@ -157,18 +163,24 @@ function formatCVE({ id, href, upstream, description }) {
return `- [\`${id}\`](${href}) - ${description}`;
}

function link(pull) {
function formatLink(pull) {
return `[#${pull}](https://github.com/keystonejs/keystone/pull/${pull})`;
}

function sortByCommit(a, b) {
return a.commit.localeCompare(b.commit);
}

function groupPullsByUser(list) {
const result = {};
for (const item of list) {
if (!item.pull) continue;
result[item.user] ||= [];
result[item.user].push(item.pull);
}
return Object.entries(result).map(([user, pulls]) => ({ user, pulls }));
return Object.entries(result)
.map(([user, pulls]) => ({ user, pulls }))
.sort((a, b) => a.user.localeCompare(b.user));
}

async function generateGitHubReleaseText(previousTag) {
Expand All @@ -184,9 +196,9 @@ async function generateGitHubReleaseText(previousTag) {
output.push(formatPackagesChanged(packages));
output.push('');

const breaking = changes.filter(x => x.type === 'major');
const features = changes.filter(x => x.type === 'minor');
const fixes = changes.filter(x => x.type === 'patch');
const breaking = changes.filter(x => x.type === 'major').sort(sortByCommit);
const features = changes.filter(x => x.type === 'minor').sort(sortByCommit);
const fixes = changes.filter(x => x.type === 'patch').sort(sortByCommit);

if (breaking.length) {
output.push(...[`#### Breaking Changes`, ...breaking.map(formatChange), ``]);
Expand Down Expand Up @@ -216,14 +228,16 @@ async function generateGitHubReleaseText(previousTag) {
const first = changes.filter(x => x.first);
const unattributed = changes.filter(x => !x.type && !x.first);

if (first.length || unattributed.length) {
if (first.length) {
const listf = groupPullsByUser(first);

output.push(`#### :seedling: New Contributors`);
output.push(
`Thanks to the following developers for making their first contributions to the project!`
);
output.push(...listf.map(({ user, pulls }) => `- @${user} (${pulls.map(link).join(',')})`));
output.push(
...listf.map(({ user, pulls }) => `- @${user} (${pulls.map(formatLink).join(',')})`)
);
output.push(``);
}

Expand All @@ -233,7 +247,7 @@ async function generateGitHubReleaseText(previousTag) {
output.push(`#### :blue_heart: Acknowledgements `);
output.push(
`Lastly, thanks to ${listu
.map(({ user, pulls }) => `@${user} (${pulls.map(link).join(',')})`)
.map(({ user, pulls }) => `@${user} (${pulls.map(formatLink).join(',')})`)
.join(', ')} for changes not shown above, but none-the-less appreciated.`
);
output.push(``);
Expand Down

0 comments on commit 279a50c

Please sign in to comment.