From f947bd1c0f62f80054a66211f1a908f05f6ad77e Mon Sep 17 00:00:00 2001 From: Alkin Tezuysal Date: Mon, 14 Jun 2021 10:55:39 +0300 Subject: [PATCH] include squashed PRs in release notes Signed-off-by: Alkin Tezuysal --- go/tools/release-notes/release_notes.go | 19 +++++++++++++------ go/tools/release-notes/release_notes_test.go | 8 ++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/go/tools/release-notes/release_notes.go b/go/tools/release-notes/release_notes.go index 63acecd5ac0..f7025e3af8e 100644 --- a/go/tools/release-notes/release_notes.go +++ b/go/tools/release-notes/release_notes.go @@ -94,6 +94,7 @@ func loadMergedPRs(from, to string) (prs []string, authors []string, commitCount func parseGitLog(s string) (prs []string, authorCommits []string, commitCount int, err error) { rx := regexp.MustCompile(`(.+)\t(.+)\t(.+)\t(.+)`) mergePR := regexp.MustCompile(`Merge pull request #(\d+)`) + squashPR := regexp.MustCompile(`\(#(\d+)\)`) authMap := map[string]string{} // here we will store email <-> gh user mappings lines := strings.Split(s, "\n") for _, line := range lines { @@ -112,13 +113,19 @@ func parseGitLog(s string) (prs []string, authorCommits []string, commitCount in continue } - if len(parents) > lengthOfSingleSHA { - // if we have two parents, it means this is a merge commit. we only count non-merge commits - continue + if len(parents) <= lengthOfSingleSHA { + // we have a single parent, and the commit counts + commitCount++ + if _, exists := authMap[authorEmail]; !exists { + authMap[authorEmail] = sha + } } - commitCount++ - if _, exists := authMap[authorEmail]; !exists { - authMap[authorEmail] = sha + + squashed := squashPR.FindStringSubmatch(title) + if len(squashed) == 2 { + // this is a merged PR. remember the PR # + prs = append(prs, squashed[1]) + continue } } diff --git a/go/tools/release-notes/release_notes_test.go b/go/tools/release-notes/release_notes_test.go index 8b4a2299336..b4d358bba46 100644 --- a/go/tools/release-notes/release_notes_test.go +++ b/go/tools/release-notes/release_notes_test.go @@ -98,9 +98,9 @@ aquarapTEST@gmail.com Fix mysql80 docker build with dep. a28591577b8d432b9c5d78a TEST@planetscale.com Revert "docker/lite/install_dependencies.sh: Upgrade MySQL 8 to 8.0.24" 7858ff46545cff749b3663c92ae90ef27a5dfbc2 27a5dfbc2 TEST@planetscale.com docker/lite/install_dependencies.sh: Upgrade MySQL 8 to 8.0.24 c91d46782933292941a846fef2590ff1a6fa193f a6fa193f` - prs, authorCommits, count, err := parseGitLog(in) + prs, authorCommits, nonMergeCommits, err := parseGitLog(in) require.NoError(t, err) - assert.Equal(t, []string{"7629", "7831", "7912", "7943", "7951", "7959", "7964", "7968", "7970"}, prs) - assert.Equal(t, []string{"385d0b327", "3b744e782", "4a0a943b0", "538709da5", "616f5562c", "6b9a731a2", "e5242a88a", "edac2baf8"}, authorCommits) - assert.Equal(t, 28, count) + assert.Equal(t, prs, []string{"7629", "7831", "7912", "7934", "7943", "7951", "7959", "7964", "7968", "7970"}) + assert.Equal(t, authorCommits, []string{"385d0b327", "3b744e782", "4a0a943b0", "538709da5", "616f5562c", "6b9a731a2", "e5242a88a", "edac2baf8"}) + assert.Equal(t, 28, nonMergeCommits) }