mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-21 18:11:36 +01:00
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 <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/286 Reviewed-by: khmarbaise <khmarbaise@noreply.gitea.io> Reviewed-by: 6543 <6543@obermui.de> Co-Authored-By: Norwin <noerw@noreply.gitea.io> Co-Committed-By: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
parent
adb2382aa5
commit
4a11cf455f
@ -20,7 +20,17 @@ var CmdReleaseDelete = cli.Command{
|
||||
Description: `Delete a release`,
|
||||
ArgsUsage: "<release tag>",
|
||||
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
|
||||
}
|
||||
|
2
go.mod
2
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
|
||||
|
4
go.sum
4
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=
|
||||
|
13
vendor/code.gitea.io/sdk/gitea/release.go
generated
vendored
13
vendor/code.gitea.io/sdk/gitea/release.go
generated
vendored
@ -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++ {
|
||||
|
1
vendor/code.gitea.io/sdk/gitea/version.go
generated
vendored
1
vendor/code.gitea.io/sdk/gitea/version.go
generated
vendored
@ -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
|
||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user