mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-27 12:56:54 +01:00
added fork subcommand for repos
Signed-off-by: Andreas Ulm <andreas.ulm@root360.de>
This commit is contained in:
parent
5584a07007
commit
f7c387d6c9
62
cmd/repos.go
62
cmd/repos.go
@ -8,6 +8,8 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -16,7 +18,11 @@ var CmdRepos = cli.Command{
|
||||
Name: "repos",
|
||||
Usage: "Operate with repositories",
|
||||
Description: `Operate with repositories`,
|
||||
Action: runRepos,
|
||||
Action: runReposList,
|
||||
Subcommands: []cli.Command{
|
||||
CmdReposList,
|
||||
CmdReposFork,
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "login, l",
|
||||
@ -25,7 +31,15 @@ var CmdRepos = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func runRepos(ctx *cli.Context) error {
|
||||
// CmdReposList represents a sub command of issues to list issues
|
||||
var CmdReposList = cli.Command{
|
||||
Name: "ls",
|
||||
Usage: "List available repositories",
|
||||
Description: `List available repositories`,
|
||||
Action: runReposList,
|
||||
}
|
||||
|
||||
func runReposList(ctx *cli.Context) error {
|
||||
login := initCommandLoginOnly(ctx)
|
||||
|
||||
rps, err := login.Client().ListMyRepos()
|
||||
@ -54,6 +68,50 @@ func runRepos(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CmdReposFork represents a sub command of issues to list issues
|
||||
var CmdReposFork = cli.Command{
|
||||
Name: "fork",
|
||||
Usage: "fork repository",
|
||||
Description: `fork repository`,
|
||||
Action: runReposFork,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "login, l",
|
||||
Usage: "Indicate one login, optional when inside a gitea repository",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo, r",
|
||||
Usage: "Indicate one repo, optional when inside a gitea repository",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "org",
|
||||
Usage: "Organization to fork the repository for (optional, default = logged in user)",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func runReposFork(ctx *cli.Context) error {
|
||||
login, owner, repo := initCommand(ctx)
|
||||
forkOptions := gitea.CreateForkOption{}
|
||||
if org := ctx.String("org"); org != "" {
|
||||
forkOptions = gitea.CreateForkOption{
|
||||
Organization: &org,
|
||||
}
|
||||
}
|
||||
|
||||
_, err := login.Client().CreateFork(owner, repo, forkOptions)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
user, _ := login.Client().GetMyUserInfo()
|
||||
|
||||
fmt.Printf("Forked '%s/%s' to '%s/%s'\n", owner, repo, user.UserName, repo)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initCommandLoginOnly(ctx *cli.Context) *Login {
|
||||
err := loadConfig(yamlConfigPath)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user