-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1136 from rsteube/gh-expose-labels
gh: expose labels macro
- Loading branch information
Showing
7 changed files
with
71 additions
and
59 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
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
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
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,56 @@ | ||
package gh | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/rsteube/carapace" | ||
) | ||
|
||
type label struct { | ||
Name string | ||
Description string | ||
Color string | ||
} | ||
|
||
type labelsQuery struct { | ||
Data struct { | ||
Repository struct { | ||
Labels struct { | ||
Nodes []label | ||
} | ||
} | ||
} | ||
} | ||
|
||
// ActionLabels completes labels | ||
// enhancement (New feature or request) | ||
// good first issue (Good for newcomers) | ||
func ActionLabels(opts RepoOpts) carapace.Action { | ||
return carapace.ActionCallback(func(c carapace.Context) carapace.Action { | ||
var queryResult labelsQuery | ||
return graphQlAction(opts, `repository(owner: $owner, name: $repo){ labels(first: 100) { nodes { name, description, color } } }`, &queryResult, func() carapace.Action { | ||
labels := queryResult.Data.Repository.Labels.Nodes | ||
vals := make([]string, 0) | ||
for _, label := range labels { | ||
vals = append(vals, label.Name, label.Description, "#"+label.Color) | ||
} | ||
return carapace.ActionStyledValuesDescribed(vals...) | ||
}) | ||
}).Cache(5*time.Minute, opts.cacheKey()) | ||
} | ||
|
||
// ActionLabelFields completes label fields | ||
// color | ||
// createdAt | ||
func ActionLabelFields() carapace.Action { | ||
return carapace.ActionValues( | ||
"color", | ||
"createdAt", | ||
"description", | ||
"id", | ||
"isDefault", | ||
"name", | ||
"updatedAt", | ||
"url", | ||
) | ||
} |