Skip to content

Commit

Permalink
handle case where no prior releases
Browse files Browse the repository at this point in the history
  • Loading branch information
qrkourier committed Oct 22, 2024
1 parent c019eb4 commit 0ce362f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
9 changes: 7 additions & 2 deletions pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import (
"golang.org/x/oauth2"
)

// Define a custom error for no releases found
var ErrNoReleasesFound = errors.New("no releases found")

type Release struct {
Name string
Description string
Expand Down Expand Up @@ -118,8 +121,6 @@ func (c *Client) GetLatestChartRelease(_ context.Context, prefix string) (*Relea
rels, resp, err := c.Repositories.ListReleases(context.TODO(), c.owner, c.repo, opt)
if err != nil {
return nil, err
} else if len(rels) == 0 {
return nil, errors.New("no releases found")
}
for _, rel := range rels {
if strings.HasPrefix(*rel.TagName, prefix) {
Expand All @@ -133,6 +134,10 @@ func (c *Client) GetLatestChartRelease(_ context.Context, prefix string) (*Relea
opt.Page = resp.NextPage
}

if len(versions) == 0 {
return nil, ErrNoReleasesFound
}

// Sort versions ascending
semver.Sort(versions)

Expand Down
20 changes: 3 additions & 17 deletions pkg/releaser/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,24 +253,10 @@ func (r *Releaser) getReleaseNotes(chart *chart.Chart) (string, error) {
if r.config.GenerateReleaseNotes {
latestRelease, err := r.github.GetLatestChartRelease(context.TODO(), chart.Metadata.Name)
if err != nil {
return "", errors.Wrapf(err, "failed to get latest release for chart %s", chart.Metadata.Name)
}
nextVersion := semver.MustParse(chart.Metadata.Version)
versions := []semver.Version{nextVersion, latestRelease.SemVer}
semver.Sort(versions)
highest := versions[len(versions)-1]
// skip generating notes if there's already a higher version in GitHub
if nextVersion.String() == highest.String() {
notes, err := r.github.GenerateReleaseNotes(context.TODO(), latestRelease, chart)
if err != nil {
return "", errors.Wrapf(err, "failed to generate release notes for chart %s", chart.Metadata.Name)
if errors.Is(err, github.ErrNoReleasesFound) {
// Handle the case where there are no releases found
return chart.Metadata.Description, nil
}
return notes, nil
}
}
if r.config.GenerateReleaseNotes {
latestRelease, err := r.github.GetLatestChartRelease(context.TODO(), chart.Metadata.Name)
if err != nil {
return "", errors.Wrapf(err, "failed to get latest release for chart %s", chart.Metadata.Name)
}
nextVersion := semver.MustParse(chart.Metadata.Version)
Expand Down

0 comments on commit 0ce362f

Please sign in to comment.