From e2d78f6dbf10ba7b5d7cc5a321db4a98a9e792e9 Mon Sep 17 00:00:00 2001 From: Richard Gee Date: Mon, 18 Apr 2022 17:27:46 +0100 Subject: [PATCH] Remove pre-releases from release_notes Initially the release notes were being generated from the current tagged release (n) and the n-1 release, irrespective of whether n-1 was a full release. This change causes `getWorkingReleases()` to ignore any previous releases where `PreRelease` is set to `true`. The processing beyond this determination will continue to consider all commits between the two identified points, resulting in a fuller set of changes for a full release where Pre-Releases have occured in between. Signed-off-by: Richard Gee --- USER_GUIDE.md | 2 +- handler/release_handler.go | 24 +++++++++---- handler/release_handler_test.go | 61 +++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 8 deletions(-) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 544a3c8..72d1368 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -51,7 +51,7 @@ This file enables Derek usage for `rgee0` and `alexellis`, it also turns on all ### Feature: `release_notes` -Derek will collate closed PRs since the last release and then put together a summary and set it for your release text body. +Derek will collate closed PRs since the previous full release and then put together a summary and set it for your release text body. Example from [openfaas/faas-cli](https://github.com/openfaas/faas-cli/releases/tag/0.9.5): diff --git a/handler/release_handler.go b/handler/release_handler.go index cc7bac4..6f9cfea 100644 --- a/handler/release_handler.go +++ b/handler/release_handler.go @@ -172,19 +172,29 @@ func buildClosedPRs(client *github.Client, workingReleases WorkingRelease, owner func getWorkingReleases(releases []*github.RepositoryRelease, owner, repo, tag string) WorkingRelease { rel := WorkingRelease{} - var count int - var r *github.RepositoryRelease + //var position int + //var r *github.RepositoryRelease - for count, r = range releases { + for position, r := range releases { if r.GetTagName() == tag { rel.CurrentDate = r.CreatedAt.Time rel.CurrentTag = tag rel.CurrentRelease = r - if count+1 < len(releases) { - prior := releases[count+1] - rel.PreviousDate = prior.CreatedAt.Time - rel.PreviousTag = prior.GetTagName() + prevRel := position + 1 + + for prevRel < len(releases) { + + prior := releases[prevRel] + + if !*prior.Prerelease { + rel.PreviousDate = prior.CreatedAt.Time + rel.PreviousTag = prior.GetTagName() + break + } + + prevRel++ + } break diff --git a/handler/release_handler_test.go b/handler/release_handler_test.go index 4961f40..07a790e 100644 --- a/handler/release_handler_test.go +++ b/handler/release_handler_test.go @@ -77,6 +77,7 @@ func Test_getWorkingReleases_TwoReleases(t *testing.T) { repo := "derek" tag := "0.2.0" lastTag := "0.1.0" + prerelease := false releases := []*github.RepositoryRelease{ &github.RepositoryRelease{ @@ -84,12 +85,14 @@ func Test_getWorkingReleases_TwoReleases(t *testing.T) { CreatedAt: &github.Timestamp{ Time: time.Now(), }, + Prerelease: &prerelease, }, &github.RepositoryRelease{ TagName: &lastTag, CreatedAt: &github.Timestamp{ Time: time.Now().Add(time.Hour * -1), }, + Prerelease: &prerelease, }, } workingReleases := getWorkingReleases(releases, owner, repo, tag) @@ -120,6 +123,7 @@ func Test_getWorkingReleases_OneRelease(t *testing.T) { owner := "alexellis" repo := "derek" tag := "0.2.0" + prerelease := false releases := []*github.RepositoryRelease{ &github.RepositoryRelease{ @@ -127,6 +131,7 @@ func Test_getWorkingReleases_OneRelease(t *testing.T) { CreatedAt: &github.Timestamp{ Time: time.Now(), }, + Prerelease: &prerelease, }, } workingReleases := getWorkingReleases(releases, owner, repo, tag) @@ -203,3 +208,59 @@ func Test_includeCommit_WithinCurrentRange(t *testing.T) { t.Fail() } } + +func Test_getWorkingReleases_ThreeReleasesOnePreRelease(t *testing.T) { + owner := "alexellis" + repo := "derek" + tag := "0.2.0" + midTag := "0.1.5" + midPreRelease := true + lastTag := "0.1.0" + preRelease := false + + releases := []*github.RepositoryRelease{ + &github.RepositoryRelease{ + TagName: &tag, + CreatedAt: &github.Timestamp{ + Time: time.Now(), + }, + Prerelease: &preRelease, + }, + &github.RepositoryRelease{ + TagName: &midTag, + CreatedAt: &github.Timestamp{ + Time: time.Now().Add(time.Hour * -1), + }, + Prerelease: &midPreRelease, + }, + &github.RepositoryRelease{ + TagName: &lastTag, + CreatedAt: &github.Timestamp{ + Time: time.Now().Add(time.Hour * -2), + }, + Prerelease: &preRelease, + }, + } + workingReleases := getWorkingReleases(releases, owner, repo, tag) + + gotCurrentDate := workingReleases.CurrentDate + wantCurrentDate := releases[0].GetCreatedAt().Time + + if gotCurrentDate != wantCurrentDate { + t.Errorf("current date, got: %s, want: %s", gotCurrentDate, wantCurrentDate) + } + + gotPreviousDate := workingReleases.PreviousDate + wantPreviousDate := releases[2].GetCreatedAt().Time + + if gotPreviousDate != wantPreviousDate { + t.Errorf("previous date, got: %s, want: %s", gotPreviousDate, wantPreviousDate) + } + + gotPreviousTag := workingReleases.PreviousTag + wantPreviousTag := *releases[2].TagName + + if gotPreviousTag != wantPreviousTag { + t.Errorf("previous tag, got: %s, want: %s", gotPreviousTag, wantPreviousTag) + } +}