Add Repo Create subcomand & enhancements #173
88
cmd/repos.go
88
cmd/repos.go
|
@ -44,15 +44,10 @@ var CmdReposList = cli.Command{
|
|||
Usage: "Filter by mode: fork, mirror, source",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "org",
|
||||
Name: "owner",
|
||||
|
||||
Aliases: []string{"u", "user", "org"},
|
||||
Required: false,
|
||||
Usage: "Filter by organization",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "user",
|
||||
Aliases: []string{"u"},
|
||||
Required: false,
|
||||
Usage: "Filter by user",
|
||||
Usage: "Filter by owner",
|
||||
},
|
||||
}, LoginOutputFlags...),
|
||||
}
|
||||
|
@ -134,51 +129,52 @@ func runRepos(ctx *cli.Context) error {
|
|||
// runReposList list repositories
|
||||
func runReposList(ctx *cli.Context) error {
|
||||
login := initCommandLoginOnly()
|
||||
client := login.Client()
|
||||
|
||||
mode := ctx.String("mode")
|
||||
org := ctx.String("org")
|
||||
user := ctx.String("user")
|
||||
|
||||
var rps []*gitea.Repository
|
||||
var err error
|
||||
|
||||
// TODO: on sdk v0.13.0 release, switch to SearchRepos()
|
||||
// Note: user filter can be used as org filter too
|
||||
if org != "" {
|
||||
rps, _, err = login.Client().ListOrgRepos(org, gitea.ListOrgReposOptions{})
|
||||
} else if user != "" {
|
||||
rps, _, err = login.Client().ListUserRepos(user, gitea.ListReposOptions{})
|
||||
var ownerID int64
|
||||
if ctx.IsSet("owner") {
|
||||
owner, _, err := client.GetUserInfo(ctx.String("owner"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ownerID = owner.ID
|
||||
} else {
|
||||
rps, _, err = login.Client().ListMyRepos(gitea.ListReposOptions{})
|
||||
me, _, err := client.GetMyUserInfo()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
6543 marked this conversation as resolved
Outdated
zeripath
commented
`TODO:` is usually better detected by IDEs
noerw
commented
By using This came up in #189 as well, where I wrote a workaround. By using `initCommandLoginOnly()`, the login is not read from the current repo!
This came up in #189 as well, where I wrote a workaround.
But we need a proper solution for cases where the command is meaningful when executed outside of a repo, but we still want it to consider repo context where available.
6543
commented
If we use Error: repository does not exist If we use `login, _, _ := initCommand()` outside of a repo we will get this:
Error: repository does not exist
6543
commented
So yes we somehow have to unify both commands but in a way it will work for all commands So yes we somehow have to unify both commands but in a way it will work for all commands
6543
commented
... witch is no mouch for this pull ... witch is no mouch for this pull
|
||||
ownerID = me.ID
|
||||
}
|
||||
|
||||
mode := gitea.RepoTypeNone
|
||||
switch ctx.String("mode") {
|
||||
case "fork":
|
||||
mode = gitea.RepoTypeFork
|
||||
case "mirror":
|
||||
mode = gitea.RepoTypeMirror
|
||||
case "source":
|
||||
mode = gitea.RepoTypeSource
|
||||
}
|
||||
|
||||
rps, _, err := client.SearchRepos(gitea.SearchRepoOptions{
|
||||
OwnerID: ownerID,
|
||||
IsPrivate: nil,
|
||||
IsArchived: nil,
|
||||
Type: mode,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return 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)
|
||||
// https://github.com/go-gitea/gitea/issues/12846
|
||||
if ownerID == 0 {
|
||||
var repos []*gitea.Repository
|
||||
for i := range rps {
|
||||
if rps[i].Owner.UserName == ctx.String("owner") {
|
||||
repos = append(repos, rps[i])
|
||||
}
|
||||
}
|
||||
} 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 {
|
||||
log.Fatal("Unknown mode: ", mode, "\nUse one of the following:\n- fork\n- mirror\n- source\n")
|
||||
return nil
|
||||
rps = repos
|
||||
}
|
||||
|
||||
if len(rps) == 0 {
|
||||
|
@ -194,7 +190,7 @@ func runReposList(ctx *cli.Context) error {
|
|||
}
|
||||
var values [][]string
|
||||
|
||||
for _, rp := range repos {
|
||||
for _, rp := range rps {
|
||||
var mode = "source"
|
||||
if rp.Fork {
|
||||
mode = "fork"
|
||||
|
|
Loading…
Reference in New Issue
Block a user
lets use
owner
/-O
everywhere, and avoid two terms for the same conceptAnd why are there two flags
org
anduser
? Can't they be merged into--owner
?It will add a request ...
but It's user convinient So why not ...
Hm, I consider two flags for the same field is more confusing than convenient, but idk.
Let's leave it as is, but please change the description to say "Filter by user" then
changed :)