Add assignee
This commit is contained in:
parent
44c7495bab
commit
57afc2e69f
2 changed files with 35 additions and 10 deletions
|
|
@ -147,7 +147,7 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
|
|||
return &payload, nil
|
||||
}
|
||||
|
||||
func IssueList(client *Client, ghRepo Repo, state string) ([]Issue, error) {
|
||||
func IssueList(client *Client, ghRepo Repo, state string, labels []string, assigneeString string) ([]Issue, error) {
|
||||
var states []string
|
||||
switch state {
|
||||
case "open", "":
|
||||
|
|
@ -160,14 +160,27 @@ func IssueList(client *Client, ghRepo Repo, state string) ([]Issue, error) {
|
|||
return nil, fmt.Errorf("invalid state: %s", state)
|
||||
}
|
||||
|
||||
// If you don't want to filter by lables, graphql requires you need
|
||||
// to send nil instead of an empty array.
|
||||
if len(labels) == 0 {
|
||||
labels = nil
|
||||
}
|
||||
|
||||
var assignee interface{}
|
||||
if len(assigneeString) > 0 {
|
||||
assignee = assigneeString
|
||||
} else {
|
||||
assignee = nil
|
||||
}
|
||||
|
||||
query := `
|
||||
fragment issue on Issue {
|
||||
number
|
||||
title
|
||||
}
|
||||
query($owner: String!, $repo: String!, $per_page: Int = 10, $states: [IssueState!] = OPEN) {
|
||||
query($owner: String!, $repo: String!, $per_page: Int = 10, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String) {
|
||||
repository(owner: $owner, name: $repo) {
|
||||
issues(first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}, states: $states) {
|
||||
issues(first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee}) {
|
||||
edges {
|
||||
node {
|
||||
...issue
|
||||
|
|
@ -181,9 +194,11 @@ func IssueList(client *Client, ghRepo Repo, state string) ([]Issue, error) {
|
|||
owner := ghRepo.RepoOwner()
|
||||
repo := ghRepo.RepoName()
|
||||
variables := map[string]interface{}{
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"states": states,
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"states": states,
|
||||
"labels": labels,
|
||||
"assignee": assignee,
|
||||
}
|
||||
|
||||
var resp struct {
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@ func init() {
|
|||
Short: "List open issues",
|
||||
RunE: issueList,
|
||||
}
|
||||
issueListCmd.Flags().StringP("assignee", "a", "", "filter by assignee")
|
||||
issueListCmd.Flags().StringP("label", "l", "", "Filter by assignee")
|
||||
issueListCmd.Flags().StringP("state", "s", "", "Filter by state")
|
||||
issueListCmd.Flags().StringP("assignee", "a", "", "Filter by assignee")
|
||||
issueListCmd.Flags().StringSliceP("label", "l", nil, "Filter by labels ")
|
||||
issueListCmd.Flags().StringP("state", "s", "", "Filter by state (open, closed or all)")
|
||||
issueCmd.AddCommand((issueListCmd))
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,17 @@ func issueList(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
issues, err := api.IssueList(apiClient, baseRepo, state)
|
||||
labels, err := cmd.Flags().GetStringSlice("label")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
assignee, err := cmd.Flags().GetString("assignee")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
issues, err := api.IssueList(apiClient, baseRepo, state, labels, assignee)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue