Skip to content

Commit

Permalink
issue_list: add filter by assignee and author
Browse files Browse the repository at this point in the history
Different from mr_list, issue_list has no filter by assignee nor author.
This patch adds both using the same logic as done in mr_list.

Signed-off-by: Bruno Meneguele <[email protected]>
  • Loading branch information
bmeneg committed Mar 4, 2021
1 parent d932304 commit 101c6f0
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions cmd/issue_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ var (
issueNumRet string
issueAll bool
issueExactMatch bool
issueAssignee string
issueAssigneeID *int
issueAuthor string
issueAuthorID *int
)

var issueListCmd = &cobra.Command{
Expand Down Expand Up @@ -72,14 +76,35 @@ func issueList(args []string) ([]*gitlab.Issue, error) {
num = -1
}

// gitlab lib still doesn't have search by author username for issues,
// because of that we need to get user's ID for both assignee and
// author.
if issueAuthor != "" {
authorID, err := lab.UserIDByUserName(issueAuthor)
if err != nil {
log.Fatal(err)
}
issueAuthorID = &authorID
}

if issueAssignee != "" {
assigneeID, err := lab.UserIDByUserName(issueAssignee)
if err != nil {
log.Fatal(err)
}
issueAssigneeID = &assigneeID
}

opts := gitlab.ListProjectIssuesOptions{
ListOptions: gitlab.ListOptions{
PerPage: num,
},
Labels: labels,
Milestone: &issueMilestone,
State: &issueState,
OrderBy: gitlab.String("updated_at"),
Labels: labels,
Milestone: &issueMilestone,
State: &issueState,
OrderBy: gitlab.String("updated_at"),
AuthorID: issueAuthorID,
AssigneeID: issueAssigneeID,
}

if issueExactMatch {
Expand Down Expand Up @@ -112,6 +137,12 @@ func init() {
issueListCmd.Flags().StringVar(
&issueMilestone, "milestone", "",
"filter issues by milestone")
issueListCmd.Flags().StringVar(
&issueAssignee, "assignee", "",
"filter issues by assignee")
issueListCmd.Flags().StringVar(
&issueAuthor, "author", "",
"filter issues by author")
issueListCmd.Flags().BoolVarP(
&issueExactMatch, "exact-match", "x", false,
"match on the exact (case-insensitive) search terms")
Expand Down

0 comments on commit 101c6f0

Please sign in to comment.