Skip to content

Commit

Permalink
Merge pull request #42 from KeisukeYamashita/add-ci-workflow
Browse files Browse the repository at this point in the history
Add CircleCI workflow
  • Loading branch information
KeisukeYamashita authored Oct 8, 2019
2 parents 314bb6c + e81c067 commit f273c33
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ $ biko cc [product] [flag(s)]

| Product | What | Command | Flags(Optional) |
|:----:|:----:|:----:|:----:|
| Jobs | Open CircleCI Jobs | `jobs` | `--project`, `-p` |
| Jobs | Open CircleCI Jobs | `jobs, j` | `--project`, `-p` |
| Workflows | Open CircleCI Workflows | `workflows, wf` | `--project`, `-p` |


## (Advanced): Docker image
Expand Down
34 changes: 32 additions & 2 deletions cli/circleci.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func newCircleCICmd() cli.Command {
},
Subcommands: []cli.Command{
newCircleCIJobsCmd(),
newCircleCIWorkflowsCmd(),
},
}
}
Expand All @@ -57,11 +58,40 @@ func newCircleCIJobsCmd() cli.Command {
if org = c.String("org"); org == "" {
return fmt.Errorf("Org for circleci not configured pass --org or set BIKO_CIRCLECI")
}
cc, err := cc.GetProvider()
cc, err := cc.GetProvider(org)
if err != nil {
return err
}
return browser.Open(c, cc)
},
}
}

func newCircleCIWorkflowsCmd() cli.Command {
return cli.Command{
Name: "workflows",
Aliases: []string{"wf"},
Usage: "Open workflows page",
Flags: []cli.Flag{
cli.StringFlag{
Name: "project, p",
Usage: "Specify the project to open",
},
cli.StringFlag{
Name: "org",
EnvVar: "BIKO_CIRCLECI",
Usage: "Specify CircleCI Organization",
},
},
Action: func(c *cli.Context) error {
var org string
if org = c.String("org"); org == "" {
return fmt.Errorf("Org for circleci not configured pass --org or set BIKO_CIRCLECI")
}
cc, err := cc.GetProvider(org)
if err != nil {
return err
}
cc.Org = org
return browser.Open(c, cc)
},
}
Expand Down
23 changes: 16 additions & 7 deletions providers/circleci/circleci.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ type Provider struct {
}

// GetProvider ...
func GetProvider() (*Provider, error) {
func GetProvider(org string) (*Provider, error) {
conf, err := alias.GetConfig()
if err != nil {
return nil, err
}

return &Provider{
Aliases: conf.CircleCI["alias"].(map[string]interface{}),
Org: org,
}, nil
}

Expand All @@ -38,28 +39,36 @@ func (p *Provider) Init(c *cli.Context) error {

// GetTargetURL ...
func (p *Provider) GetTargetURL() (string, error) {
var baseURL = fmt.Sprintf("https://circleci.com/gh/%s/", p.Org)
const baseURL = "https://circleci.com/"
var err error
if p.baseURL, err = url.Parse(baseURL); err != nil {
return "", err
}
p.addProductPath(p.Ctx.Command.Name)
fmt.Printf(p.URL.String())
return p.URL.String(), nil
}

func (p *Provider) addProductPath(product string) {
p.URL = p.baseURL
switch product {
case "jobs":
p.join(fmt.Sprintf("gh/%s", p.Org))
var project string
if project = p.Ctx.String("project"); project != "" {
p.join(fmt.Sprintf("%s/", project))
if project = p.GetCtxString("project"); project != "" {
p.join(fmt.Sprintf("gh/%s/%s/", p.Org, project))
return
}
return
case "workflows":
p.join(fmt.Sprintf("gh/%s/workflows", p.Org))
var project string
if project = p.GetCtxString("project"); project != "" {
p.join(project)
return
}
p.URL = p.baseURL
return
default:
p.URL = p.baseURL
return
}
}

Expand Down

0 comments on commit f273c33

Please sign in to comment.