Skip to content

Commit

Permalink
issue list: Add --sort and --order list options
Browse files Browse the repository at this point in the history
'issue list' sorts issues in descending order and doesn't provide
an option to list them in ascending order that they wree updated.

Add a --sort option to display the issuess by descending (desc) or
ascending (asc) order. Add a --order option display the issues they were
created in or updated at.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
  • Loading branch information
prarit committed Apr 9, 2021
1 parent e735c02 commit ee1444e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
11 changes: 10 additions & 1 deletion cmd/issue_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var (
issueAssigneeID *int
issueAuthor string
issueAuthorID *int
issueOrder string
issueSortedBy string
)

var issueListCmd = &cobra.Command{
Expand Down Expand Up @@ -93,14 +95,19 @@ func issueList(args []string) ([]*gitlab.Issue, error) {
}
}

orderBy := gitlab.String(issueOrder)

sort := gitlab.String(issueSortedBy)

opts := gitlab.ListProjectIssuesOptions{
ListOptions: gitlab.ListOptions{
PerPage: num,
},
Labels: labels,
Milestone: &issueMilestone,
State: &issueState,
OrderBy: gitlab.String("updated_at"),
OrderBy: orderBy,
Sort: sort,
AuthorID: issueAuthorID,
AssigneeID: issueAssigneeID,
}
Expand Down Expand Up @@ -144,6 +151,8 @@ func init() {
issueListCmd.Flags().BoolVarP(
&issueExactMatch, "exact-match", "x", false,
"match on the exact (case-insensitive) search terms")
issueListCmd.Flags().StringVar(&issueOrder, "order", "updated_at", "display order (updated_at/created_at)")
issueListCmd.Flags().StringVar(&issueSortedBy, "sort", "desc", "sort order (desc/asc)")

issueCmd.AddCommand(issueListCmd)
carapace.Gen(issueListCmd).FlagCompletion(carapace.ActionMap{
Expand Down
12 changes: 6 additions & 6 deletions cmd/mr_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ var (
mrExactMatch bool
mrAssignee string
mrAssigneeID *int
order string
sortedBy string
mrOrder string
mrSortedBy string
mrReviewer string
mrReviewerID *int
)
Expand Down Expand Up @@ -116,9 +116,9 @@ func mrList(args []string) ([]*gitlab.MergeRequest, error) {
}
}

orderBy := gitlab.String(order)
orderBy := gitlab.String(mrOrder)

sort := gitlab.String(sortedBy)
sort := gitlab.String(mrSortedBy)

// if none of the flags are set, return every single MR
mrCheckConflicts := (mrConflicts || mrNoConflicts)
Expand Down Expand Up @@ -197,8 +197,8 @@ func init() {
listCmd.Flags().StringVar(&mrAuthor, "author", "", "list only MRs authored by $username")
listCmd.Flags().StringVar(
&mrAssignee, "assignee", "", "list only MRs assigned to $username")
listCmd.Flags().StringVar(&order, "order", "updated_at", "display order (updated_at/created_at)")
listCmd.Flags().StringVar(&sortedBy, "sort", "desc", "sort order (desc/asc)")
listCmd.Flags().StringVar(&mrOrder, "order", "updated_at", "display order (updated_at/created_at)")
listCmd.Flags().StringVar(&mrSortedBy, "sort", "desc", "sort order (desc/asc)")
listCmd.Flags().BoolVarP(&mrDraft, "draft", "", false, "list MRs marked as draft")
listCmd.Flags().BoolVarP(&mrReady, "ready", "", false, "list MRs not marked as draft")
listCmd.Flags().SortFlags = false
Expand Down

0 comments on commit ee1444e

Please sign in to comment.