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

handle no prior releases #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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