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
This commit is contained in:
Mislav Marohnić 2018-10-26 14:06:15 +02:00
Родитель bd8042ec75
Коммит b15d8de5e4
4 изменённых файлов: 7 добавлений и 3 удалений

Просмотреть файл

@ -248,6 +248,8 @@ func listIssues(cmd *Command, args *Args) {
if flagIssueSortAscending {
filters["direction"] = "asc"
} else {
filters["direction"] = "desc"
}
if cmd.FlagPassed("since") {

Просмотреть файл

@ -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)

Просмотреть файл

@ -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,

Просмотреть файл

@ -10,7 +10,7 @@ Feature: hub pr list
assert :per_page => "100",
:page => :no,
:sort => nil,
:direction => nil
:direction => "desc"
response.headers["Link"] = %(<https://api.github.com/repositories/12345?per_page=100&page=2>; rel="next")