Skip to content

Commit

Permalink
feat: add focus mode
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Sep 19, 2018
1 parent b36a289 commit 7c5a284
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
26 changes: 14 additions & 12 deletions cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ import (

type runOptions struct {
// pull
PullOpts pullOptions
NoPull bool
PullOpts pullOptions
NoPull bool
ReposToFetch []string

// db
DBOpts dbOptions

// run
ShowClosed bool `mapstructure:"show-closed"`
ShowOrphans bool
EpicLabel string
Destination string
DebugGraph bool
ShowClosed bool `mapstructure:"show-closed"`
ShowOrphans bool
AdditionalPulls []string
EpicLabel string
Destination string
DebugGraph bool

Targets []string
//Preview bool
Expand All @@ -44,6 +46,7 @@ func runSetupFlags(flags *pflag.FlagSet, opts *runOptions) {
flags.BoolVarP(&opts.ShowOrphans, "show-orphans", "", false, "show issues not linked to an epic")
flags.StringVarP(&opts.EpicLabel, "epic-label", "", "epic", "label used for epics (empty means issues with dependencies but without dependants)")
flags.StringVarP(&opts.Destination, "destination", "", "-", "destination ('-' for stdout)")
flags.StringSliceVarP(&opts.AdditionalPulls, "additional-pull", "", []string{}, "additional pull that won't necessarily be displayed on the graph")
//flags.BoolVarP(&opts.Preview, "preview", "p", false, "preview result")
viper.BindPFlags(flags)
}
Expand All @@ -63,7 +66,7 @@ func newRunCommand() *cobra.Command {
return err
}
opts.PullOpts.DBOpts = opts.DBOpts
opts.PullOpts.Targets = args
opts.PullOpts.Targets = append(args, opts.AdditionalPulls...)
opts.Targets = args
return run(opts)
},
Expand Down Expand Up @@ -91,14 +94,13 @@ func run(opts *runOptions) error {
return errors.Wrap(err, "failed to prepare issues")
}

issues.processEpicLinks()
if !opts.ShowClosed {
issues.HideClosed()
}
if !opts.ShowOrphans && issues.HasNonOrphans() {
issues.HideOrphans()
issues.filterByTargets(opts.Targets)
if opts.ShowOrphans {
logger().Warn("--show-orphans is deprecated and will be removed")
}
issues.processEpicLinks()

out, err := graphviz(issues, opts)

Expand Down
34 changes: 34 additions & 0 deletions issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,40 @@ func (issues Issues) processEpicLinks() {
}
}

func (issues Issues) filterByTargets(targets []string) {
for _, issue := range issues {
if issue.Hidden {
continue
}
issue.Hidden = !issue.MatchesWithATarget(targets)
}
}

func (i Issue) MatchesWithATarget(targets []string) bool {
issueParts := strings.Split(strings.TrimRight(i.URL, "/"), "/")
for _, target := range targets {
fullTarget := i.GetRelativeIssueURL(target)
targetParts := strings.Split(strings.TrimRight(fullTarget, "/"), "/")
if len(issueParts) == len(targetParts) {
if i.URL == fullTarget {
return true
}
} else {
if i.URL[:len(fullTarget)] == fullTarget {
return true
}
}
}

for _, parent := range i.Blocks {
if parent.MatchesWithATarget(targets) {
return true
}
}

return false
}

func (issues Issues) HideClosed() {
for _, issue := range issues {
if issue.IsClosed() {
Expand Down
17 changes: 16 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,26 @@ func getReposFromTargets(targets []string) []string {
logger().Fatal("filesystem target are not yet supported")
}
repo := strings.Split(target, "/issues")[0]
repo = strings.Split(target, "#")[0]
reposMap[repo] = true
}
repos := []string{}
for repo := range reposMap {
repos = append(repos, repo)
}
return repos
return uniqueStrings(repos)
}

func uniqueStrings(input []string) []string {
u := make([]string, 0, len(input))
m := make(map[string]bool)

for _, val := range input {
if _, ok := m[val]; !ok {
m[val] = true
u = append(u, val)
}
}

return u
}

0 comments on commit 7c5a284

Please sign in to comment.