Add Repo Create subcomand & enhancements #173

Merged
6543 merged 20 commits from 6543/tea:repos-create into master 2020-09-23 19:50:02 +00:00
Showing only changes of commit 9fe5213a1a - Show all commits

View File

@ -44,15 +44,10 @@ var CmdReposList = cli.Command{
Usage: "Filter by mode: fork, mirror, source",
},
&cli.StringFlag{
Name: "org",
Name: "owner",
Outdated
Review

lets use owner / -O everywhere, and avoid two terms for the same concept

lets use `owner` / `-O` everywhere, and avoid two terms for the same concept
Outdated
Review

And why are there two flags org and user? Can't they be merged into --owner?

And why are there two flags `org` and `user`? Can't they be merged into `--owner`?
Outdated
Review

It will add a request ...
but It's user convinient So why not ...

It will add a request ... but It's user convinient So why not ...
Outdated
Review

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

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
Review

changed :)

changed :)
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

TODO: is usually better detected by IDEs

`TODO:` is usually better detected by IDEs
Outdated
Review

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.

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.
Outdated
Review

If we use login, _, _ := initCommand() outside of a repo we will get this:

Error: repository does not exist

If we use `login, _, _ := initCommand()` outside of a repo we will get this: Error: repository does not exist
Outdated
Review

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
Outdated
Review

... 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"