From d738068bf175268cef15da13e9cb8bbee4e44139 Mon Sep 17 00:00:00 2001 From: "Shohei.K" Date: Tue, 17 Dec 2019 00:34:48 +0900 Subject: [PATCH 1/4] Implement cmd of github repository in order to move quickly --- README.md | 9 +++++---- cli/github.go | 25 +++++++++++++++++++++++++ providers/github/github.go | 14 ++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c680c57..d669779 100644 --- a/README.md +++ b/README.md @@ -353,10 +353,11 @@ $ biko github [product] [flag(s)] $ biko gh [product] [flag(s)] ``` -| Product | What | Command | Flags(Optional) | -| :----: | :----: | :----: | :----: | -| Dashboard | Open github Dashboard | `dashboard`, `db` | `--org` | -| Trending | Open github Treinding | `trending`, `t` | `--language, -l`, `--since, -s` | +| Product | What | Command | Flags(Optional) | +| :----: | :----: | :----: | :----: | +| Dashboard | Open github Dashboard | `dashboard`, `db` | `--org` | +| Trending | Open github Treinding | `trending`, `t` | `--language, -l`, `--since, -s` | +| Repository | Open github Repository | `repository`, `r` | `--org`, `--name, -n` | ### Google diff --git a/cli/github.go b/cli/github.go index ed5ecb5..af0dd87 100644 --- a/cli/github.go +++ b/cli/github.go @@ -39,6 +39,7 @@ func newGithubCmd() cli.Command { Subcommands: []cli.Command{ newGithubDashboardCmd(), newGithubTrendingCmd(), + newGithubRepositoryCmd(), }, } } @@ -86,3 +87,27 @@ func newGithubTrendingCmd() cli.Command { } } + +func newGithubRepositoryCmd() cli.Command { + return cli.Command{ + Name: "repository", + Aliases: []string{"r"}, + Usage: "Open the repository page", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "org", + Usage: "Organization to open", + }, + cli.StringFlag{ + Name: "name, n", + Usage: "Name of repository that depend on Organization", + }, + }, + Action: func(c *cli.Context) error { + + github := &gh.Provider{} + return browser.Open(c, github) + }, + } + +} diff --git a/providers/github/github.go b/providers/github/github.go index 10b6fb7..a9e4729 100644 --- a/providers/github/github.go +++ b/providers/github/github.go @@ -71,6 +71,20 @@ func (p *Provider) addProductPath(product string) { p.join(language) return } + case "repository": + var org string + if org = p.Ctx.String("org"); org != "" { + p.join(org) + } + var name string + if name = p.Ctx.String("name"); name != "" { + if org = p.Ctx.String("org"); org != "" { + p.join(name) + } + return + } + p.URL = p.baseURL + return default: p.URL = p.baseURL } From 1ac1cc0bba984f03242dd9c4d5fc650a34c6eb8f Mon Sep 17 00:00:00 2001 From: "Shohei.K" Date: Tue, 17 Dec 2019 12:54:57 +0900 Subject: [PATCH 2/4] Add flag of users --- cli/github.go | 4 ++++ providers/github/github.go | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cli/github.go b/cli/github.go index af0dd87..3e71679 100644 --- a/cli/github.go +++ b/cli/github.go @@ -98,6 +98,10 @@ func newGithubRepositoryCmd() cli.Command { Name: "org", Usage: "Organization to open", }, + cli.StringFlag{ + Name: "users, u", + Usage: "User page to open", + }, cli.StringFlag{ Name: "name, n", Usage: "Name of repository that depend on Organization", diff --git a/providers/github/github.go b/providers/github/github.go index a9e4729..387a7c3 100644 --- a/providers/github/github.go +++ b/providers/github/github.go @@ -72,13 +72,20 @@ func (p *Provider) addProductPath(product string) { return } case "repository": - var org string - if org = p.Ctx.String("org"); org != "" { + + users := p.Ctx.String("users") + org := p.Ctx.String("org") + if users != "" && org != "" { + p.URL = p.baseURL + return + } else if users != "" { + p.join(users) + } else { p.join(org) } - var name string - if name = p.Ctx.String("name"); name != "" { - if org = p.Ctx.String("org"); org != "" { + + if name := p.Ctx.String("name"); name != "" { + if users != "" || org != "" { p.join(name) } return From b4fbb947ae48f3b8e4e32f021180072e75a9905c Mon Sep 17 00:00:00 2001 From: "Shohei.K" Date: Tue, 17 Dec 2019 13:54:18 +0900 Subject: [PATCH 3/4] Refactor init variable --- providers/github/github.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/providers/github/github.go b/providers/github/github.go index 387a7c3..e20e1e4 100644 --- a/providers/github/github.go +++ b/providers/github/github.go @@ -51,8 +51,7 @@ func (p *Provider) GetTargetURL() (string, error) { func (p *Provider) addProductPath(product string) { switch product { case "dashboard": - var org string - if org = p.Ctx.String("org"); org != "" { + if org := p.Ctx.String("org"); org != "" { p.join(fmt.Sprintf("orgs/%s/dashboard", org)) return } @@ -60,14 +59,12 @@ func (p *Provider) addProductPath(product string) { return case "trending": p.join("trending") - var since string - if since = p.Ctx.String("since"); since != "" { + if since := p.Ctx.String("since"); since != "" { param := url.Values{} param.Add("since", since) p.URL.RawQuery = param.Encode() } - var language string - if language = p.Ctx.String("language"); language != "" { + if language := p.Ctx.String("language"); language != "" { p.join(language) return } From 50808e2d9407d1501669bfce95a3e564742eecec Mon Sep 17 00:00:00 2001 From: "Shohei.K" Date: Tue, 17 Dec 2019 14:53:04 +0900 Subject: [PATCH 4/4] Remove elseif --- providers/github/github.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/providers/github/github.go b/providers/github/github.go index e20e1e4..62dc284 100644 --- a/providers/github/github.go +++ b/providers/github/github.go @@ -75,7 +75,8 @@ func (p *Provider) addProductPath(product string) { if users != "" && org != "" { p.URL = p.baseURL return - } else if users != "" { + } + if users != "" { p.join(users) } else { p.join(org)