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

feat: enable adding the chart to existing releases #407

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 21 additions & 1 deletion pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package github

import (
"context"
"fmt"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -115,7 +116,14 @@ func (c *Client) CreateRelease(_ context.Context, input *Release) error {

release, _, err := c.Repositories.CreateRelease(context.TODO(), c.owner, c.repo, req)
if err != nil {
return err
if !isErrTagAlreadyExist(err) {
return err
}

release, _, err = c.Repositories.GetReleaseByTag(context.TODO(), c.owner, c.repo, input.Name)
if err != nil {
return fmt.Errorf("getting the existing relase: %w", err)
}
}

for _, asset := range input.Assets {
Expand All @@ -126,6 +134,18 @@ func (c *Client) CreateRelease(_ context.Context, input *Release) error {
return nil
}

func isErrTagAlreadyExist(err error) bool {
var ghErrs *github.ErrorResponse
if errors.As(err, &ghErrs) {
for _, ghErr := range ghErrs.Errors {
if ghErr.Code == "already_exists" && ghErr.Field == "tag_name" {
return true
}
}
}
return false
}

// CreatePullRequest creates a pull request in the repository specified by repoURL.
// The return value is the pull request URL.
func (c *Client) CreatePullRequest(owner string, repo string, message string, head string, base string) (string, error) {
Expand Down