Skip to content
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("getting the existing relase: %w", err)
return fmt.Errorf("getting the existing relase: %w", err)
Suggested change
return fmt.Errorf("getting the existing relase: %w", err)
return fmt.Errorf("getting the existing release: %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