2020-09-30 05:11:33 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package releases
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
2020-12-15 17:38:22 +00:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-09-30 05:11:33 +00:00
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CmdReleaseDelete represents a sub command of Release to delete a release
|
|
|
|
var CmdReleaseDelete = cli.Command{
|
|
|
|
Name: "delete",
|
2020-12-16 16:47:40 +00:00
|
|
|
Aliases: []string{"rm"},
|
2022-09-26 20:35:59 +00:00
|
|
|
Usage: "Delete one or more releases",
|
|
|
|
Description: `Delete one or more releases`,
|
|
|
|
ArgsUsage: "<release tag> [<release tag>...]",
|
2020-09-30 05:11:33 +00:00
|
|
|
Action: runReleaseDelete,
|
2020-12-09 21:51:07 +00:00
|
|
|
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...),
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
func runReleaseDelete(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
|
|
|
client := ctx.Login.Client()
|
2020-09-30 05:11:33 +00:00
|
|
|
|
2022-09-26 20:35:59 +00:00
|
|
|
if !ctx.Args().Present() {
|
|
|
|
fmt.Println("Release tag needed to edit")
|
2020-09-30 05:11:33 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-09 21:51:07 +00:00
|
|
|
if !ctx.Bool("confirm") {
|
|
|
|
fmt.Println("Are you sure? Please confirm with -y or --confirm.")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-26 20:35:59 +00:00
|
|
|
for _, tag := range ctx.Args().Slice() {
|
|
|
|
release, err := getReleaseByTag(ctx.Owner, ctx.Repo, tag, client)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = client.DeleteRelease(ctx.Owner, ctx.Repo, release.ID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-09 21:51:07 +00:00
|
|
|
|
2022-09-26 20:35:59 +00:00
|
|
|
if ctx.Bool("delete-tag") {
|
|
|
|
_, err = client.DeleteTag(ctx.Owner, ctx.Repo, tag)
|
|
|
|
return err
|
|
|
|
}
|
2020-12-09 21:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|