Skip to content

Commit

Permalink
Remove pre-releases from release_notes
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rgee0 committed Apr 18, 2022
1 parent 0ef9a3d commit 58ebcd9
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 9 deletions.
2 changes: 1 addition & 1 deletion USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
23 changes: 15 additions & 8 deletions handler/release_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,26 @@ 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

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
Expand Down
61 changes: 61 additions & 0 deletions handler/release_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,22 @@ func Test_getWorkingReleases_TwoReleases(t *testing.T) {
repo := "derek"
tag := "0.2.0"
lastTag := "0.1.0"
prerelease := false

releases := []*github.RepositoryRelease{
&github.RepositoryRelease{
TagName: &tag,
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)
Expand Down Expand Up @@ -120,13 +123,15 @@ func Test_getWorkingReleases_OneRelease(t *testing.T) {
owner := "alexellis"
repo := "derek"
tag := "0.2.0"
prerelease := false

releases := []*github.RepositoryRelease{
&github.RepositoryRelease{
TagName: &tag,
CreatedAt: &github.Timestamp{
Time: time.Now(),
},
Prerelease: &prerelease,
},
}
workingReleases := getWorkingReleases(releases, owner, repo, tag)
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 58ebcd9

Please sign in to comment.