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