2019-11-08 09:33:46 +08:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2023-09-08 09:40:02 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-11-08 09:33:46 +08:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-09-30 13:11:33 +08:00
|
|
|
"code.gitea.io/tea/cmd/repos"
|
2020-12-16 01:38:22 +08:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-09-30 13:11:33 +08:00
|
|
|
"code.gitea.io/tea/modules/print"
|
2020-10-01 03:44:22 +08:00
|
|
|
"code.gitea.io/tea/modules/utils"
|
2019-11-08 09:33:46 +08:00
|
|
|
|
2020-09-24 03:49:59 +08:00
|
|
|
"code.gitea.io/sdk/gitea"
|
2020-01-05 01:44:25 +08:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-11-08 09:33:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// CmdRepos represents to login a gitea server.
|
|
|
|
var CmdRepos = cli.Command{
|
|
|
|
Name: "repos",
|
2020-10-02 23:46:51 +08:00
|
|
|
Aliases: []string{"repo"},
|
2020-12-21 21:37:20 +08:00
|
|
|
Category: catEntities,
|
2020-10-02 23:46:51 +08:00
|
|
|
Usage: "Show repository details",
|
|
|
|
Description: "Show repository details",
|
2020-09-24 03:49:59 +08:00
|
|
|
ArgsUsage: "[<repo owner>/<repo name>]",
|
|
|
|
Action: runRepos,
|
2020-01-05 01:44:25 +08:00
|
|
|
Subcommands: []*cli.Command{
|
2020-09-30 13:11:33 +08:00
|
|
|
&repos.CmdReposList,
|
2020-10-06 16:05:22 +08:00
|
|
|
&repos.CmdReposSearch,
|
2020-09-30 13:11:33 +08:00
|
|
|
&repos.CmdRepoCreate,
|
2021-10-20 09:31:35 +08:00
|
|
|
&repos.CmdRepoCreateFromTemplate,
|
2021-10-14 15:27:39 +08:00
|
|
|
&repos.CmdRepoFork,
|
2023-09-11 14:27:48 +08:00
|
|
|
&repos.CmdRepoMigrate,
|
2024-07-27 00:18:58 +08:00
|
|
|
&repos.CmdRepoRm,
|
2019-11-08 09:33:46 +08:00
|
|
|
},
|
2020-10-06 16:05:22 +08:00
|
|
|
Flags: repos.CmdReposListFlags,
|
2020-09-24 03:49:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func runRepos(ctx *cli.Context) error {
|
|
|
|
if ctx.Args().Len() == 1 {
|
2020-12-16 01:38:22 +08:00
|
|
|
return runRepoDetail(ctx, ctx.Args().First())
|
2019-11-08 09:33:46 +08:00
|
|
|
}
|
2020-09-30 13:11:33 +08:00
|
|
|
return repos.RunReposList(ctx)
|
2019-11-08 09:33:46 +08:00
|
|
|
}
|
2020-09-24 03:49:59 +08:00
|
|
|
|
2020-12-16 01:38:22 +08:00
|
|
|
func runRepoDetail(cmd *cli.Context, path string) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
client := ctx.Login.Client()
|
|
|
|
repoOwner, repoName := utils.GetOwnerAndRepo(path, ctx.Owner)
|
2020-09-24 03:49:59 +08:00
|
|
|
repo, _, err := client.GetRepo(repoOwner, repoName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-16 01:38:22 +08:00
|
|
|
topics, _, err := client.ListRepoTopics(repoOwner, repoName, gitea.ListRepoTopicsOptions{})
|
2020-09-24 03:49:59 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-30 13:11:33 +08:00
|
|
|
print.RepoDetails(repo, topics)
|
2020-09-24 03:49:59 +08:00
|
|
|
return nil
|
|
|
|
}
|