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

Remove pre-releases from release_notes #186

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
  • Loading branch information
rgee0 committed Apr 18, 2022
commit 58ebcd9a2ed88aa6968a43d858fdc0ba24fb7fca
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)
}
}