2020-09-30 05:11:33 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2023-09-08 01:40:02 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-09-30 05:11:33 +00:00
|
|
|
|
|
|
|
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
|
|
|
"code.gitea.io/tea/modules/print"
|
|
|
|
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CmdReleaseList represents a sub command of Release to list releases
|
|
|
|
var CmdReleaseList = cli.Command{
|
2020-12-16 16:47:40 +00:00
|
|
|
Name: "list",
|
|
|
|
Aliases: []string{"ls"},
|
2020-09-30 05:11:33 +00:00
|
|
|
Usage: "List Releases",
|
|
|
|
Description: "List Releases",
|
2022-09-13 18:14:02 +00:00
|
|
|
ArgsUsage: " ", // command does not accept arguments
|
2020-09-30 05:11:33 +00:00
|
|
|
Action: RunReleasesList,
|
|
|
|
Flags: append([]cli.Flag{
|
|
|
|
&flags.PaginationPageFlag,
|
|
|
|
&flags.PaginationLimitFlag,
|
|
|
|
}, flags.AllDefaultFlags...),
|
|
|
|
}
|
|
|
|
|
|
|
|
// RunReleasesList list releases
|
2020-12-15 17:38:22 +00:00
|
|
|
func RunReleasesList(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
2020-09-30 05:11:33 +00:00
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
releases, _, err := ctx.Login.Client().ListReleases(ctx.Owner, ctx.Repo, gitea.ListReleasesOptions{
|
|
|
|
ListOptions: ctx.GetListOptions(),
|
|
|
|
})
|
2020-09-30 05:11:33 +00:00
|
|
|
if err != nil {
|
2020-12-16 16:18:10 +00:00
|
|
|
return err
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
print.ReleasesList(releases, ctx.Output)
|
2020-09-30 05:11:33 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getReleaseByTag(owner, repo, tag string, client *gitea.Client) (*gitea.Release, error) {
|
2022-04-07 19:44:16 +00:00
|
|
|
rl, _, err := client.ListReleases(owner, repo, gitea.ListReleasesOptions{
|
|
|
|
ListOptions: gitea.ListOptions{Page: -1},
|
|
|
|
})
|
2020-09-30 05:11:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(rl) == 0 {
|
2022-03-25 13:41:08 +00:00
|
|
|
return nil, fmt.Errorf("Repo does not have any release")
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|
|
|
|
for _, r := range rl {
|
|
|
|
if r.TagName == tag {
|
|
|
|
return r, nil
|
|
|
|
}
|
|
|
|
}
|
2022-03-25 13:41:08 +00:00
|
|
|
return nil, fmt.Errorf("Release tag does not exist")
|
2020-09-30 05:11:33 +00:00
|
|
|
}
|