From 4a11cf455f67d547184ab4cf1f1eaeba823c49c8 Mon Sep 17 00:00:00 2001 From: Norwin Date: Thu, 10 Dec 2020 05:51:07 +0800 Subject: [PATCH] Release delete: add --delete-tag & --confirm (#286) vendor latest go-sdk tea release delete: add --delete-tag flag fixes #256 release delete: require confirmation fixes #237 Co-authored-by: Norwin Roosen Reviewed-on: https://gitea.com/gitea/tea/pulls/286 Reviewed-by: khmarbaise Reviewed-by: 6543 <6543@obermui.de> Co-Authored-By: Norwin Co-Committed-By: Norwin --- cmd/releases/delete.go | 28 +++++++++++++++++++++-- go.mod | 2 +- go.sum | 4 ++-- vendor/code.gitea.io/sdk/gitea/release.go | 13 ++++++++++- vendor/code.gitea.io/sdk/gitea/version.go | 1 + vendor/modules.txt | 2 +- 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/cmd/releases/delete.go b/cmd/releases/delete.go index 8c4f06f..db947c2 100644 --- a/cmd/releases/delete.go +++ b/cmd/releases/delete.go @@ -20,7 +20,17 @@ var CmdReleaseDelete = cli.Command{ Description: `Delete a release`, ArgsUsage: "", Action: runReleaseDelete, - Flags: flags.AllDefaultFlags, + Flags: append([]cli.Flag{ + &cli.BoolFlag{ + Name: "confirm", + Aliases: []string{"y"}, + Usage: "Confirm deletion (required)", + }, + &cli.BoolFlag{ + Name: "delete-tag", + Usage: "Also delete the git tag for this release", + }, + }, flags.AllDefaultFlags...), } func runReleaseDelete(ctx *cli.Context) error { @@ -33,6 +43,11 @@ func runReleaseDelete(ctx *cli.Context) error { return nil } + if !ctx.Bool("confirm") { + fmt.Println("Are you sure? Please confirm with -y or --confirm.") + return nil + } + release, err := getReleaseByTag(owner, repo, tag, client) if err != nil { return err @@ -42,5 +57,14 @@ func runReleaseDelete(ctx *cli.Context) error { } _, err = client.DeleteRelease(owner, repo, release.ID) - return err + if err != nil { + return err + } + + if ctx.Bool("delete-tag") { + _, err = client.DeleteReleaseTag(owner, repo, tag) + return err + } + + return nil } diff --git a/go.mod b/go.mod index 9a72574..1b5f86f 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.13 require ( code.gitea.io/gitea-vet v0.2.1 - code.gitea.io/sdk/gitea v0.13.1-0.20201129150736-6ea6e887f2fc + code.gitea.io/sdk/gitea v0.13.1-0.20201209180822-68eec69f472e github.com/AlecAivazis/survey/v2 v2.2.2 github.com/Microsoft/go-winio v0.4.15 // indirect github.com/adrg/xdg v0.2.2 diff --git a/go.sum b/go.sum index 4b76f08..d958507 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ code.gitea.io/gitea-vet v0.2.1 h1:b30by7+3SkmiftK0RjuXqFvZg2q4p68uoPGuxhzBN0s= code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE= -code.gitea.io/sdk/gitea v0.13.1-0.20201129150736-6ea6e887f2fc h1:Jy4PoO7T7tST6iYe7nvUwD2zkqbqVB34hLZsrG0EmLo= -code.gitea.io/sdk/gitea v0.13.1-0.20201129150736-6ea6e887f2fc/go.mod h1:89WiyOX1KEcvjP66sRHdu0RafojGo60bT9UqW17VbWs= +code.gitea.io/sdk/gitea v0.13.1-0.20201209180822-68eec69f472e h1:oJOoT5TGbSYRNGUhEiiEz3MqFjU6wELN0/liCZ3RmVg= +code.gitea.io/sdk/gitea v0.13.1-0.20201209180822-68eec69f472e/go.mod h1:89WiyOX1KEcvjP66sRHdu0RafojGo60bT9UqW17VbWs= github.com/AlecAivazis/survey/v2 v2.2.2 h1:1I4qBrNsHQE+91tQCqVlfrKe9DEL65949d1oKZWVELY= github.com/AlecAivazis/survey/v2 v2.2.2/go.mod h1:9FJRdMdDm8rnT+zHVbvQT2RTSTLq0Ttd6q3Vl2fahjk= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= diff --git a/vendor/code.gitea.io/sdk/gitea/release.go b/vendor/code.gitea.io/sdk/gitea/release.go index d8d28c5..502e5da 100644 --- a/vendor/code.gitea.io/sdk/gitea/release.go +++ b/vendor/code.gitea.io/sdk/gitea/release.go @@ -124,7 +124,7 @@ func (c *Client) EditRelease(user, repo string, id int64, form EditReleaseOption return r, resp, err } -// DeleteRelease delete a release from a repository +// DeleteRelease delete a release from a repository, keeping its tag func (c *Client) DeleteRelease(user, repo string, id int64) (*Response, error) { _, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/releases/%d", user, repo, id), @@ -132,6 +132,17 @@ func (c *Client) DeleteRelease(user, repo string, id int64) (*Response, error) { return resp, err } +// DeleteReleaseTag deletes a tag from a repository, if no release refers to it. +func (c *Client) DeleteReleaseTag(user, repo string, tag string) (*Response, error) { + if err := c.checkServerVersionGreaterThanOrEqual(version1_14_0); err != nil { + return nil, err + } + _, resp, err := c.getResponse("DELETE", + fmt.Sprintf("/repos/%s/%s/releases/tags/%s", user, repo, tag), + nil, nil) + return resp, err +} + // fallbackGetReleaseByTag is fallback for old gitea installations ( < 1.13.0 ) func (c *Client) fallbackGetReleaseByTag(user, repo string, tag string) (*Release, *Response, error) { for i := 1; ; i++ { diff --git a/vendor/code.gitea.io/sdk/gitea/version.go b/vendor/code.gitea.io/sdk/gitea/version.go index b5922ec..c96ef66 100644 --- a/vendor/code.gitea.io/sdk/gitea/version.go +++ b/vendor/code.gitea.io/sdk/gitea/version.go @@ -41,6 +41,7 @@ var ( version1_11_0, _ = version.NewVersion("1.11.0") version1_12_0, _ = version.NewVersion("1.12.0") version1_13_0, _ = version.NewVersion("1.13.0") + version1_14_0, _ = version.NewVersion("1.14.0") ) // checkServerVersionGreaterThanOrEqual is internally used to speed up things and ignore issues with prerelease diff --git a/vendor/modules.txt b/vendor/modules.txt index 432949d..5c8aa42 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,7 +1,7 @@ # code.gitea.io/gitea-vet v0.2.1 code.gitea.io/gitea-vet code.gitea.io/gitea-vet/checks -# code.gitea.io/sdk/gitea v0.13.1-0.20201129150736-6ea6e887f2fc +# code.gitea.io/sdk/gitea v0.13.1-0.20201209180822-68eec69f472e code.gitea.io/sdk/gitea # github.com/AlecAivazis/survey/v2 v2.2.2 github.com/AlecAivazis/survey/v2