From b15d8de5e468f32653ff3bdfc2224cd3e429080a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 26 Oct 2018 14:06:15 +0200 Subject: [PATCH] Ensure consistent sort direction when listing issues, PRs The default direction when sorting by `created` date (the default) is descending. However, the default on the API backend changes to ascending when the sort key is something different than `created`: https://developer.github.com/v3/pulls/#list-pull-requests This ensures that the default `direction: "desc"` is always passed to API queries, regardless of the sort key, unless `--sort-ascending` was used. Ref. https://github.com/github/hub/issues/1815#issuecomment-433222344 --- commands/issue.go | 2 ++ commands/pr.go | 2 ++ features/issue.feature | 4 ++-- features/pr-list.feature | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/commands/issue.go b/commands/issue.go index 942b3fba..f5977d7f 100644 --- a/commands/issue.go +++ b/commands/issue.go @@ -248,6 +248,8 @@ func listIssues(cmd *Command, args *Args) { if flagIssueSortAscending { filters["direction"] = "asc" + } else { + filters["direction"] = "desc" } if cmd.FlagPassed("since") { diff --git a/commands/pr.go b/commands/pr.go index cbbebb43..1ac61a99 100644 --- a/commands/pr.go +++ b/commands/pr.go @@ -182,6 +182,8 @@ func listPulls(cmd *Command, args *Args) { } if flagPullRequestSortAscending { filters["direction"] = "asc" + } else { + filters["direction"] = "desc" } pulls, err := gh.FetchPullRequests(project, filters, flagPullRequestLimit, nil) diff --git a/features/issue.feature b/features/issue.feature index 7bb3ddb4..17090c9b 100644 --- a/features/issue.feature +++ b/features/issue.feature @@ -9,7 +9,7 @@ Feature: hub issue get('/repos/github/hub/issues') { assert :assignee => "Cornwe19", :sort => nil, - :direction => nil + :direction => "desc" json [ { :number => 999, @@ -76,7 +76,7 @@ Feature: hub issue get('/repos/github/hub/issues') { assert :assignee => "Cornwe19", :sort => nil, - :direction => nil + :direction => "desc" json [ { :number => 999, diff --git a/features/pr-list.feature b/features/pr-list.feature index 92674e6e..6c5b8202 100644 --- a/features/pr-list.feature +++ b/features/pr-list.feature @@ -10,7 +10,7 @@ Feature: hub pr list assert :per_page => "100", :page => :no, :sort => nil, - :direction => nil + :direction => "desc" response.headers["Link"] = %(; rel="next")