tea organizations list command #264

Merged
6543 merged 2 commits from khmarbaise/tea:issue-tea-263-ls into master 2020-12-06 22:02:50 +00:00
5 changed files with 133 additions and 0 deletions

View File

@ -53,6 +53,8 @@ times Operate on tracked times of a repositorys issues and pulls
open Open something of the repository on web browser
notifications Show notifications
milestones List and create milestones
organizations List, create, delete organizations
help, h Shows a list of commands or help for one command
```
To fetch issues from different repos, use the `--remote` flag (when inside a gitea repository directory) or `--login` & `--repo` flags.

39
cmd/organizations.go Normal file
View File

@ -0,0 +1,39 @@
// 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 (
"log"
"code.gitea.io/tea/cmd/organizations"
"github.com/urfave/cli/v2"
)
// CmdOrgs represents handle organization
var CmdOrgs = cli.Command{
Name: "organizations",
Aliases: []string{"organization", "org"},
Usage: "List, create, delete organizations",
Description: "Show organization details",
ArgsUsage: "[<organization>]",
Action: runOrganizations,
Subcommands: []*cli.Command{
&organizations.CmdOrganizationList,
},
}
func runOrganizations(ctx *cli.Context) error {
if ctx.Args().Len() == 1 {
return runOrganizationDetail(ctx.Args().First())
}
return organizations.RunOrganizationList(ctx)
}
func runOrganizationDetail(path string) error {
log.Fatal("Not yet implemented.")
return nil
}

46
cmd/organizations/list.go Normal file
View File

@ -0,0 +1,46 @@
// Copyright 2020 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 organizations
import (
"log"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/config"
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
)
// CmdOrganizationList represents a sub command of organizations to list users organizations
var CmdOrganizationList = cli.Command{
Name: "ls",
Aliases: []string{"list"},
Usage: "List Organizations",
Description: "List users organizations",
Action: RunOrganizationList,
Review

paggination options missing

paggination options missing
Review
example: * https://gitea.com/gitea/tea/src/branch/master/cmd/releases/list.go#L27-L28 * https://gitea.com/gitea/tea/src/branch/master/cmd/releases/list.go#L36
Review

Changes as suggested. Thanks for the hints.

Changes as suggested. Thanks for the hints.
Flags: append([]cli.Flag{
&flags.PaginationPageFlag,
&flags.PaginationLimitFlag,
}, flags.AllDefaultFlags...),
}
noerw marked this conversation as resolved Outdated
Outdated
Review

Note for later (no need to adress this in this PR):
By using InitCommandLoginOnly() repo-based login detection fails, see #200

Note for later (no need to adress this in this PR): By using `InitCommandLoginOnly()` repo-based login detection fails, see #200
// RunOrganizationList list user organizations
func RunOrganizationList(ctx *cli.Context) error {
//TODO: Reconsider the usage InitCommandLoginOnly related to #200
login := config.InitCommandLoginOnly(flags.GlobalLoginValue)
client := login.Client()
userOrganizations, _, err := client.ListUserOrgs(login.User, gitea.ListOrgsOptions{ListOptions: flags.GetListOptions(ctx)})
if err != nil {
noerw marked this conversation as resolved Outdated

Here I'm not sure which exact user information should be used info.UserName makes it working. where is the difference to long.Name ?

Here I'm not sure which exact user information should be used `info.UserName` makes it working. where is the difference to `long.Name` ?
Outdated
Review

login.Name is the ID of tea specific configuration for each gitea instance.
login.User holds the user name that the auth token belongs to, so you can skip the call to GetMyUserInfo()

`login.Name` is the ID of tea specific configuration for each gitea instance. `login.User` holds the user name that the auth token belongs to, so you can skip the call to `GetMyUserInfo()`
log.Fatal(err)
6543 marked this conversation as resolved Outdated
Outdated
Review

can you move list printing func into modules/print

like it's done with list repos:

https://gitea.com/gitea/tea/src/branch/master/cmd/repos/list.go#L83
https://gitea.com/gitea/tea/src/branch/master/modules/print/repo.go#L63

yes list issues do not do it now - need a refactor ...

can you move list printing func into `modules/print` like it's done with list repos: https://gitea.com/gitea/tea/src/branch/master/cmd/repos/list.go#L83 https://gitea.com/gitea/tea/src/branch/master/modules/print/repo.go#L63 yes list issues do not do it now - need a refactor ...

Changed as requested.

Changed as requested.
}
print.OrganizationsList(userOrganizations)
return nil
}

View File

@ -39,6 +39,7 @@ func main() {
&cmd.CmdOpen,
&cmd.CmdNotifications,
&cmd.CmdMilestones,
&cmd.CmdOrgs,
}
app.EnableBashCompletion = true
err := app.Run(os.Args)

View File

@ -0,0 +1,45 @@
// Copyright 2020 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 print
import (
"fmt"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
)
// OrganizationsList prints a listing of the organizations
func OrganizationsList(organizations []*gitea.Organization) {
if len(organizations) == 0 {
fmt.Println("No organizations found")
return
}
headers := []string{
"Name",
"FullName",
"Website",
"Location",
"Description",
}
var values [][]string
for _, org := range organizations {
values = append(
values,
[]string{
org.UserName,
org.FullName,
org.Website,
org.Location,
org.Description,
},
)
}
OutputList(flags.GlobalOutputValue, headers, values)
}