From dda94a5dea7663a63509dd62b0478e49d1c5844b Mon Sep 17 00:00:00 2001 From: Norwin Date: Fri, 25 Mar 2022 21:41:08 +0800 Subject: [PATCH] Refactor errorhandling in `getReleaseByTag()` (#477) small refactor for consistency Co-authored-by: Norwin Reviewed-on: https://gitea.com/gitea/tea/pulls/477 Reviewed-by: Lunny Xiao Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: Norwin Co-committed-by: Norwin --- cmd/releases/delete.go | 4 ---- cmd/releases/edit.go | 4 ---- cmd/releases/list.go | 6 ++---- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/cmd/releases/delete.go b/cmd/releases/delete.go index ced12b7..5d1d224 100644 --- a/cmd/releases/delete.go +++ b/cmd/releases/delete.go @@ -54,10 +54,6 @@ func runReleaseDelete(cmd *cli.Context) error { if err != nil { return err } - if release == nil { - return nil - } - _, err = client.DeleteRelease(ctx.Owner, ctx.Repo, release.ID) if err != nil { return err diff --git a/cmd/releases/edit.go b/cmd/releases/edit.go index 8cc0bfa..0c7e4f3 100644 --- a/cmd/releases/edit.go +++ b/cmd/releases/edit.go @@ -72,10 +72,6 @@ func runReleaseEdit(cmd *cli.Context) error { if err != nil { return err } - if release == nil { - return nil - } - var isDraft, isPre *bool if ctx.IsSet("draft") { isDraft = gitea.OptionalBool(strings.ToLower(ctx.String("draft"))[:1] == "t") diff --git a/cmd/releases/list.go b/cmd/releases/list.go index 5302707..859d619 100644 --- a/cmd/releases/list.go +++ b/cmd/releases/list.go @@ -50,14 +50,12 @@ func getReleaseByTag(owner, repo, tag string, client *gitea.Client) (*gitea.Rele return nil, err } if len(rl) == 0 { - fmt.Println("Repo does not have any release") - return nil, nil + return nil, fmt.Errorf("Repo does not have any release") } for _, r := range rl { if r.TagName == tag { return r, nil } } - fmt.Println("Release tag does not exist") - return nil, nil + return nil, fmt.Errorf("Release tag does not exist") }