Skip to content

Commit

Permalink
updated project completion
Browse files Browse the repository at this point in the history
- ordered by updated_at desc
- state filtering
- only use first line of body as description
  • Loading branch information
rsteube committed Jan 22, 2021
1 parent 7ef5714 commit 2b592cb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/issue/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
return action.ActionLabels(cmd).Invoke(args).Filter(parts).ToA()
}),
"milestone": action.ActionMilestones(cmd),
"project": action.ActionProjects(cmd),
"project": action.ActionProjects(cmd, action.ProjectOpts{Open: true}),
})
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/pr/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
return action.ActionLabels(cmd).Invoke(args).Filter(parts).ToA()
}),
"milestone": action.ActionMilestones(cmd),
"project": action.ActionProjects(cmd),
"project": action.ActionProjects(cmd, action.ProjectOpts{Open: true}),
"reviewer": carapace.ActionMultiParts(",", func(args, parts []string) carapace.Action {
return action.ActionAssignableUsers(cmd).Invoke(args).Filter(parts).ToA()
}),
Expand Down
24 changes: 21 additions & 3 deletions pkg/cmdutil/action/project.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package action

import (
"fmt"
"strings"

"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)
Expand All @@ -20,15 +23,30 @@ type projectQuery struct {
}
}

func ActionProjects(cmd *cobra.Command) carapace.Action {
type ProjectOpts struct {
Closed bool
Open bool
}

func (i *ProjectOpts) states() string {
states := make([]string, 0)
for index, include := range []bool{i.Closed, i.Open} {
if include {
states = append(states, []string{"CLOSED", "OPEN"}[index])
}
}
return fmt.Sprintf("[%v]", strings.Join(states, ","))
}

func ActionProjects(cmd *cobra.Command, opts ProjectOpts) carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
var queryResult projectQuery
return GraphQlAction(cmd, `repository(owner: $owner, name: $repo){ projects(first: 100) { nodes { name, body } } }`, &queryResult, func() carapace.Action {
return GraphQlAction(cmd, fmt.Sprintf(`repository(owner: $owner, name: $repo){ projects(first: 100, states: %v, orderBy: {direction: DESC, field: UPDATED_AT}) { nodes { name, body } } }`, opts.states()), &queryResult, func() carapace.Action {
projects := queryResult.Data.Repository.Projects.Nodes
vals := make([]string, len(projects)*2)
for index, p := range projects {
vals[index*2] = p.Name
vals[index*2+1] = p.Body
vals[index*2+1] = strings.SplitN(p.Body, "\n", 2)[0]
}
return carapace.ActionValuesDescribed(vals...)
})
Expand Down

0 comments on commit 2b592cb

Please sign in to comment.