Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Add PRs to changelog #2138

Merged
merged 2 commits into from
Aug 9, 2021

Conversation

rmunn
Copy link
Contributor

@rmunn rmunn commented Aug 9, 2021

As per discussion in #2116, I created a script to look up PR numbers in GitHub commit messages and add them to the changelog entries. This is the result.

While I was at it, I also fixed one obvious typo in a changeset and its corresponding changelog entry. I put that in a separate commit (22c1880) so that if modifying a changeset file after-the-fact will cause tooling issues, I can easily remove that commit from this PR. Just let me know if that's needed.

No changeset included in this PR since it doesn't make any code changes.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Aug 9, 2021

⚠️ No Changeset found

Latest commit: ec744e9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@rmunn
Copy link
Contributor Author

rmunn commented Aug 9, 2021

Here's the script I used to update the changelogs:

import { readFileSync, writeFileSync } from 'fs';
import { execSync } from 'child_process';

function getLogSubject(sha) {
    return execSync(`git log -1 --pretty=%s ${sha}`, { encoding: 'utf-8' }).replace(/(\r\n|\n)/, '');
}

let changelog = readFileSync('CHANGELOG.md', 'utf-8');

const lineRe = /^-\s([0-9a-f]+):(.*)$/;
const prRe = /.*(\s\(#\d+\))$/;
let lines = changelog.split(/(\r\n|\n)/);
let result = [];
for (const line of lines) {
    if (line.length <= 2) {
        result.push(line);
        continue;
    }
    let lineMatch = lineRe.exec(line);
    if (lineMatch) {
        if (prRe.test(line)) {
            result.push(line);
            continue;
        }
        let commit = getLogSubject(lineMatch[1]);
        let prMatch = prRe.exec(commit);
        if (prMatch) {
            result.push(line + prMatch[1]);
        } else {
            result.push(line);
        }
    } else {
        result.push(line);
    }
}

writeFileSync('CHANGELOG.md.out', result.join(''), 'utf-8');

I tried to write the script to be idempotent: if more changesets get added without PR numbers, the script can be re-run and it will only touch the lines that have commit IDs without a PR number. That way if it takes a little while to resolve #2116, and more changesets are added that create changelog lines with no PR numbers, it should be easy to just run this script again to touch up just those few lines.

@benmccann
Copy link
Member

Thanks! This is a nice change. The other half of this is adding links to PRs in the future. Can you add a script to keep it up-to-date as well? See https://github.com/sveltejs/vite-plugin-svelte/blob/1ea98c3436aca2fb8e9e3cba5913c7fa28d6eee4/.changeset/config.json#L3 for an example of how to do that

@benmccann
Copy link
Member

I'll merge this and then add the script to keep up-to-date. Thanks again!

@benmccann benmccann merged commit 21edce7 into sveltejs:master Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants