You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-05 00:59:04 +02:00
fix(github): do not fail branch creation if it already exists (#4471)
github api is eventually consistent... so, we might ask for the branch, it might say it does't exist, and when we try and create it, it might error because it already exists. this should avoid breaking it --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
3f54b5eb2f
commit
aa9986e826
@ -2,6 +2,7 @@ package client
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -231,7 +232,7 @@ func (c *githubClient) OpenPullRequest(
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
if res.StatusCode == 422 {
|
||||
if res.StatusCode == http.StatusUnprocessableEntity {
|
||||
log.WithError(err).Warn("pull request validation failed")
|
||||
return nil
|
||||
}
|
||||
@ -283,11 +284,11 @@ func (c *githubClient) CreateFile(
|
||||
|
||||
if defBranch != branch && branch != "" {
|
||||
_, res, err := c.client.Repositories.GetBranch(ctx, repo.Owner, repo.Name, branch, 100)
|
||||
if err != nil && (res == nil || res.StatusCode != 404) {
|
||||
if err != nil && (res == nil || res.StatusCode != http.StatusNotFound) {
|
||||
return fmt.Errorf("could not get branch %q: %w", branch, err)
|
||||
}
|
||||
|
||||
if res.StatusCode == 404 {
|
||||
if res.StatusCode == http.StatusNotFound {
|
||||
defRef, _, err := c.client.Git.GetRef(ctx, repo.Owner, repo.Name, "refs/heads/"+defBranch)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get ref %q: %w", "refs/heads/"+defBranch, err)
|
||||
@ -299,7 +300,10 @@ func (c *githubClient) CreateFile(
|
||||
SHA: defRef.Object.SHA,
|
||||
},
|
||||
}); err != nil {
|
||||
return fmt.Errorf("could not create ref %q from %q: %w", "refs/heads/"+branch, defRef.Object.GetSHA(), err)
|
||||
rerr := new(github.ErrorResponse)
|
||||
if !errors.As(err, &rerr) || rerr.Message != "Reference already exists" {
|
||||
return fmt.Errorf("could not create ref %q from %q: %w", "refs/heads/"+branch, defRef.Object.GetSHA(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -313,7 +317,7 @@ func (c *githubClient) CreateFile(
|
||||
Ref: branch,
|
||||
},
|
||||
)
|
||||
if err != nil && (res == nil || res.StatusCode != 404) {
|
||||
if err != nil && (res == nil || res.StatusCode != http.StatusNotFound) {
|
||||
return fmt.Errorf("could not get %q: %w", path, err)
|
||||
}
|
||||
|
||||
@ -475,7 +479,7 @@ func (c *githubClient) Upload(
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if resp != nil && resp.StatusCode == 422 {
|
||||
if resp != nil && resp.StatusCode == http.StatusUnprocessableEntity {
|
||||
return err
|
||||
}
|
||||
return RetriableError{err}
|
||||
|
Reference in New Issue
Block a user