-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f9b6dd
commit 33942b4
Showing
22 changed files
with
1,231 additions
and
897 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,3 @@ trace.out | |
debug.test | ||
vendor/ | ||
debug | ||
|
||
# Sonar | ||
.scannerwork/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Changelog | ||
|
||
## next | ||
|
||
- Convert to [Cobra](https://github.com/spf13/cobra). | ||
|
||
## 1.0.0 | ||
|
||
- Original CLI app, written with [urfave/cli](https://github.com/urfave/cli) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"regexp" | ||
"text/tabwriter" | ||
"time" | ||
|
||
"github.com/benmatselby/donny/ui" | ||
"github.com/benmatselby/go-azuredevops/azuredevops" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// ListBuildsOptions defines what arguments/options the user can provide for the | ||
// command. | ||
type ListBuildsOptions struct { | ||
Args []string | ||
Repo string | ||
Branch string | ||
Count int | ||
} | ||
|
||
func NewListBuildsCommand(client *azuredevops.Client) *cobra.Command { | ||
var opts ListBuildsOptions | ||
cmd := &cobra.Command{ | ||
Use: "builds", | ||
Short: "Provide a list of builds", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
opts.Args = args | ||
|
||
options := &azuredevops.BuildsListOptions{ | ||
Count: opts.Count, | ||
} | ||
|
||
builds, err := client.Builds.List(options) | ||
if err != nil { | ||
return fmt.Errorf("unable to get a list of builds: %v", err) | ||
} | ||
|
||
if len(builds) > 0 { | ||
renderBuilds(builds, len(builds), opts.Branch) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
flags := cmd.Flags() | ||
flags.StringVar(&opts.Repo, "repo", "", "The repo to filter on") | ||
flags.IntVar(&opts.Count, "count", 10, "How many builds to show") | ||
flags.StringVar(&opts.Branch, "branch", "", "The branch to filter on") | ||
|
||
return cmd | ||
} | ||
|
||
func renderBuilds(builds []azuredevops.Build, count int, filterBranch string) { | ||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.FilterHTML) | ||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", "", "Name", "Branch", "Build", "Finished") | ||
for index := 0; index < count; index++ { | ||
build := builds[index] | ||
name := build.Definition.Name | ||
result := build.Result | ||
status := build.Status | ||
buildNo := build.BuildNumber | ||
branch := build.Branch | ||
|
||
// Deal with date formatting for the finish time | ||
finish, err := time.Parse(time.RFC3339, builds[index].FinishTime) | ||
finishAt := finish.Format(ui.AppDateTimeFormat) | ||
if err != nil { | ||
finishAt = builds[index].FinishTime | ||
} | ||
|
||
// Filter on branches | ||
matched, _ := regexp.MatchString(".*"+filterBranch+".*", branch) | ||
if !matched { | ||
continue | ||
} | ||
|
||
if status == "inProgress" { | ||
result = ui.AppProgress | ||
} else if status == "notStarted" { | ||
result = ui.AppPending | ||
} else { | ||
if result == "failed" { | ||
result = ui.AppFailure | ||
} else { | ||
result = ui.AppSuccess | ||
} | ||
} | ||
|
||
fmt.Fprintf(w, "%s \t%s\t%s\t%s\t%s\n", result, name, branch, buildNo, finishAt) | ||
} | ||
|
||
w.Flush() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"text/tabwriter" | ||
|
||
"github.com/benmatselby/donny/ui" | ||
"github.com/benmatselby/go-azuredevops/azuredevops" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// ListBranchInfoOptions defines what arguments/options the user can provide for the | ||
// command. | ||
type ListBranchInfoOptions struct { | ||
Args []string | ||
Repo string | ||
} | ||
|
||
func NewListBranchInfoCommand(client *azuredevops.Client) *cobra.Command { | ||
var opts ListBranchInfoOptions | ||
cmd := &cobra.Command{ | ||
Use: "branch", | ||
Short: "Provide a list of pull requests", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
opts.Args = args | ||
|
||
if opts.Repo == "" { | ||
return fmt.Errorf("expected argument of repo") | ||
} | ||
gitRefOps := azuredevops.GitRefListOptions{ | ||
IncludeStatuses: true, | ||
LatestStatusesOnly: true, | ||
} | ||
refs, _, err := client.Git.ListRefs(opts.Repo, "heads", &gitRefOps) | ||
if err != nil { | ||
return fmt.Errorf("unable to get git refs for %s: %+v", opts.Repo, err) | ||
} | ||
|
||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.FilterHTML) | ||
|
||
for _, ref := range refs { | ||
state := ui.AppUnknown | ||
if len(ref.Statuses) > 0 { | ||
state = ref.Statuses[0].State | ||
|
||
if state == "failed" { | ||
state = ui.AppFailure | ||
} else if state == "pending" { | ||
state = ui.AppPending | ||
} else { | ||
state = ui.AppSuccess | ||
} | ||
} | ||
|
||
fmt.Fprintf(w, "%s \t%s\n", state, ref.Name) | ||
} | ||
|
||
w.Flush() | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
flags := cmd.Flags() | ||
flags.StringVar(&opts.Repo, "repo", "", "The repo to filter on") | ||
|
||
return cmd | ||
} |
Oops, something went wrong.