2020-09-30 07:11:33 +02:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2023-09-08 03:40:02 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-09-30 07:11:33 +02:00
|
|
|
|
|
|
|
package releases
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
2020-12-15 18:38:22 +01:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-09-30 07:11:33 +02: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 17:47:40 +01:00
|
|
|
Aliases: []string{"rm"},
|
2022-09-26 22:35:59 +02:00
|
|
|
Usage: "Delete one or more releases",
|
|
|
|
Description: `Delete one or more releases`,
|
|
|
|
ArgsUsage: "<release tag> [<release tag>...]",
|
2020-09-30 07:11:33 +02:00
|
|
|
Action: runReleaseDelete,
|
2020-12-09 22:51:07 +01: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 07:11:33 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 18:38:22 +01:00
|
|
|
func runReleaseDelete(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
|
|
|
client := ctx.Login.Client()
|
2020-09-30 07:11:33 +02:00
|
|
|
|
2022-09-26 22:35:59 +02:00
|
|
|
if !ctx.Args().Present() {
|
|
|
|
fmt.Println("Release tag needed to edit")
|
2020-09-30 07:11:33 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-09 22:51:07 +01:00
|
|
|
if !ctx.Bool("confirm") {
|
|
|
|
fmt.Println("Are you sure? Please confirm with -y or --confirm.")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-26 22:35:59 +02: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 22:51:07 +01:00
|
|
|
|
2022-09-26 22:35:59 +02:00
|
|
|
if ctx.Bool("delete-tag") {
|
|
|
|
_, err = client.DeleteTag(ctx.Owner, ctx.Repo, tag)
|
|
|
|
return err
|
|
|
|
}
|
2020-12-09 22:51:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2020-09-30 07:11:33 +02:00
|
|
|
}
|