2019-11-08 09:33:46 +08:00
|
|
|
// Copyright 2019 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 cmd
|
|
|
|
|
|
|
|
import (
|
2020-09-30 13:11:33 +08:00
|
|
|
"code.gitea.io/tea/cmd/flags"
|
|
|
|
"code.gitea.io/tea/cmd/repos"
|
|
|
|
"code.gitea.io/tea/modules/config"
|
|
|
|
"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"},
|
|
|
|
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,
|
|
|
|
&repos.CmdRepoCreate,
|
2019-11-08 09:33:46 +08:00
|
|
|
},
|
2020-09-30 13:11:33 +08:00
|
|
|
Flags: flags.LoginOutputFlags,
|
2020-09-24 03:49:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func runRepos(ctx *cli.Context) error {
|
|
|
|
if ctx.Args().Len() == 1 {
|
2020-09-30 13:11:33 +08:00
|
|
|
return runRepoDetail(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-09-30 13:11:33 +08:00
|
|
|
func runRepoDetail(path string) error {
|
|
|
|
login := config.InitCommandLoginOnly(flags.GlobalLoginValue)
|
2020-09-24 03:49:59 +08:00
|
|
|
client := login.Client()
|
2020-10-01 03:44:22 +08:00
|
|
|
repoOwner, repoName := utils.GetOwnerAndRepo(path, login.User)
|
2020-09-24 03:49:59 +08:00
|
|
|
repo, _, err := client.GetRepo(repoOwner, repoName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
topics, _, err := client.ListRepoTopics(repo.Owner.UserName, repo.Name, gitea.ListRepoTopicsOptions{})
|
|
|
|
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
|
|
|
|
}
|