fix: check response status code before continuing

This commit is contained in:
myrqs 2023-05-04 15:02:03 +02:00
parent e5d338f4c5
commit 6f80894884

View file

@ -132,11 +132,14 @@ func getFiles(parentDir, files string) ([]string, error) {
func createOrGetRelease(ctx *gha.GitHubContext, c *gitea.Client, owner, repo string, opts gitea.CreateReleaseOption) (*gitea.Release, error) { func createOrGetRelease(ctx *gha.GitHubContext, c *gitea.Client, owner, repo string, opts gitea.CreateReleaseOption) (*gitea.Release, error) {
// Get the release by tag // Get the release by tag
release, _, err := c.GetReleaseByTag(owner, repo, opts.TagName) release, resp, err := c.GetReleaseByTag(owner, repo, opts.TagName)
if err == nil { if err == nil {
return release, nil return release, nil
} }
errMessage := fmt.Errorf("failed to get release for tag: %s with error: %w", opts.TagName, err) errMessage := fmt.Errorf("failed to get release for tag: %s with error: %w", opts.TagName, err)
if resp.StatusCode != 404 {
return nil, errMessage
}
fmt.Printf("%s trying to create it", errMessage) fmt.Printf("%s trying to create it", errMessage)
// Create the release // Create the release
release, _, err = c.CreateRelease(owner, repo, opts) release, _, err = c.CreateRelease(owner, repo, opts)