Skip to content

Commit

Permalink
gh: added ActionPinnedIssues
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed May 13, 2022
1 parent aa131f6 commit 20db068
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions completers/gh_completer/cmd/action/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,43 @@ func ActionIssues(cmd *cobra.Command, opts IssueOpts) carapace.Action {
})
}

type pinnedIssueQuery struct {
Data struct {
Repository struct {
PinnedIssues struct {
Nodes []struct {
Issue issue
}
}
}
}
}

func ActionPinnedIssues(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
var queryResult pinnedIssueQuery
return GraphQlAction(cmd, `repository(owner: $owner, name: $repo){ pinnedIssues(first: 3) { nodes { issue { number, title, state } } } }`, &queryResult, func() carapace.Action {
issues := queryResult.Data.Repository.PinnedIssues.Nodes
vals := make([]string, 0)
for _, issue := range issues {
s := style.Default
switch issue.Issue.State {
case "OPEN":
s = styles.Gh.StateOpen
case "CLOSED":
s = styles.Gh.StateClosed
case "MERGED":
s = styles.Gh.StateMerged
default:
}

vals = append(vals, strconv.Itoa(issue.Issue.Number), issue.Issue.Title, s)
}
return carapace.ActionStyledValuesDescribed(vals...)
})
})
}

func ActionIssueFields() carapace.Action {
return carapace.ActionValues(
"assignees",
Expand Down

0 comments on commit 20db068

Please sign in to comment.