Skip to content

Commit a540c4d

Browse files
committed
feat(dash): project detail has more URL to open
1 parent a238ac1 commit a540c4d

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

cmd/gitlab-flow/commands_dash.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,19 @@ func getDashProjectDetailSubCommand() *cli.Command {
8989
Aliases: []string{"p"},
9090
Usage: "do something of current project.",
9191
Category: "dash",
92-
//Flags: []cli.Flag{},
92+
Flags: []cli.Flag{
93+
&cli.StringFlag{
94+
Name: "module",
95+
Aliases: []string{"m"},
96+
Usage: "project `module`, module is one of (home, tag, branch, commit)",
97+
DefaultText: "home",
98+
Value: "home",
99+
Required: false,
100+
},
101+
},
93102
Action: func(c *cli.Context) error {
94-
data, err := getDash(c).ProjectDetail()
103+
module := c.String("module")
104+
data, err := getDash(c).ProjectDetail(module)
95105
if err != nil {
96106
return err
97107
}

internal/dash.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ type IDash interface {
1010
MilestoneOverview(milestoneName, branchFilter string) ([]byte, error)
1111

1212
// ProjectDetail display project detail, includes: project web URL
13-
ProjectDetail() ([]byte, error)
13+
ProjectDetail(module string) ([]byte, error)
1414
}

internal/dash_impl.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,25 @@ func (d dashImpl) MilestoneOverview(milestoneName, branchFilter string) ([]byte,
357357
return buf.Bytes(), nil
358358
}
359359

360-
func (d dashImpl) ProjectDetail() ([]byte, error) {
361-
d.printAndOpenBrowser(d.ctx.Project.Name, d.ctx.Project.WebURL)
360+
func (d dashImpl) ProjectDetail(module string) ([]byte, error) {
361+
switch module {
362+
case "home":
363+
d.printAndOpenBrowser(d.ctx.Project.Name, d.ctx.Project.WebURL)
364+
case "branch":
365+
d.printAndOpenBrowser("branches", genProjectURL(d.ctx.Project.WebURL, "/-/branches"))
366+
case "tag":
367+
d.printAndOpenBrowser("tags", genProjectURL(d.ctx.Project.WebURL, "/-/tags"))
368+
case "commit":
369+
d.printAndOpenBrowser("commits", genProjectURL(d.ctx.Project.WebURL, "/commits/master"))
370+
}
362371

363372
return nil, nil
364373
}
365374

375+
func genProjectURL(base, suffix string) string {
376+
return base + suffix
377+
}
378+
366379
// printAndOpenBrowser print WebURL into stdout and open web browser.
367380
func (d dashImpl) printAndOpenBrowser(title, url string) {
368381
if len(title) == 0 && len(url) == 0 {

0 commit comments

Comments
 (0)