mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-23 19:11:38 +01:00
Merge branch 'list_repos' of ssh://root360_github/root360-AndreasUlm/tea into fork_repos
Signed-off-by: Andreas Ulm <andreas.ulm@root360.de>
This commit is contained in:
commit
b08449938d
61
cmd/repos.go
61
cmd/repos.go
@ -37,24 +37,81 @@ var CmdReposList = cli.Command{
|
|||||||
Usage: "List available repositories",
|
Usage: "List available repositories",
|
||||||
Description: `List available repositories`,
|
Description: `List available repositories`,
|
||||||
Action: runReposList,
|
Action: runReposList,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "login, l",
|
||||||
|
Usage: "Indicate one login, optional when inside a gitea repository",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "mode",
|
||||||
|
Usage: "Indicate one login, optional when inside a gitea repository",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "org",
|
||||||
|
Usage: "Indicate one login, optional when inside a gitea repository",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "user",
|
||||||
|
Usage: "Indicate one login, optional when inside a gitea repository",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// runReposList list repositories
|
||||||
func runReposList(ctx *cli.Context) error {
|
func runReposList(ctx *cli.Context) error {
|
||||||
login := initCommandLoginOnly(ctx)
|
login := initCommandLoginOnly(ctx)
|
||||||
|
|
||||||
rps, err := login.Client().ListMyRepos()
|
mode := ctx.String("mode")
|
||||||
|
org := ctx.String("org")
|
||||||
|
user := ctx.String("user")
|
||||||
|
|
||||||
|
var rps []*gitea.Repository
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if org != "" {
|
||||||
|
rps, err = login.Client().ListOrgRepos(org)
|
||||||
|
} else if user != "" {
|
||||||
|
rps, err = login.Client().ListUserRepos(user)
|
||||||
|
} else {
|
||||||
|
rps, err = login.Client().ListMyRepos()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var repos []*gitea.Repository
|
||||||
|
if mode == "" {
|
||||||
|
repos = rps
|
||||||
|
} else if mode == "fork" {
|
||||||
|
for _, rp := range rps {
|
||||||
|
if rp.Fork == true {
|
||||||
|
repos = append(repos, rp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if mode == "mirror" {
|
||||||
|
for _, rp := range rps {
|
||||||
|
if rp.Mirror == true {
|
||||||
|
repos = append(repos, rp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if mode == "source" {
|
||||||
|
for _, rp := range rps {
|
||||||
|
if rp.Mirror != true && rp.Fork != true {
|
||||||
|
repos = append(repos, rp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Unknown mode '%s'\nUse one of the following:\n- fork\n- mirror\n- source\n", mode)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if len(rps) == 0 {
|
if len(rps) == 0 {
|
||||||
fmt.Println("No repositories found")
|
fmt.Println("No repositories found")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Name | Type/Mode | SSH-URL | Owner")
|
fmt.Println("Name | Type/Mode | SSH-URL | Owner")
|
||||||
for _, rp := range rps {
|
for _, rp := range repos {
|
||||||
var mode = "source"
|
var mode = "source"
|
||||||
if rp.Fork {
|
if rp.Fork {
|
||||||
mode = "fork"
|
mode = "fork"
|
||||||
|
Loading…
Reference in New Issue
Block a user