diff --git a/lib/travis/api/v3/queries/branches.rb b/lib/travis/api/v3/queries/branches.rb index c368fa7d..6566a1a8 100644 --- a/lib/travis/api/v3/queries/branches.rb +++ b/lib/travis/api/v3/queries/branches.rb @@ -1,6 +1,9 @@ module Travis::API::V3 class Queries::Branches < Query - sortable_by :name, last_build: "builds.started_at".freeze + sortable_by :name, + last_build: "builds.started_at".freeze, + exists_on_github: "(case when branches.exists_on_github then 1 else 2 end)".freeze + default_sort "last_build:desc" def find(repository) diff --git a/spec/v3/services/branches/find_spec.rb b/spec/v3/services/branches/find_spec.rb index e43b13e1..68a45a86 100644 --- a/spec/v3/services/branches/find_spec.rb +++ b/spec/v3/services/branches/find_spec.rb @@ -216,6 +216,28 @@ describe Travis::API::V3::Services::Branches::Find do } end + describe "sorting by exists_on_github" do + before { get("/v3/repo/#{repo.id}/branches?sort_by=exists_on_github&limit=1") } + example { expect(last_response).to be_ok } + example { expect(parsed_body["@pagination"]).to be == { + "limit" => 1, + "offset" => 0, + "count" => 1, + "is_first" => true, + "is_last" => true, + "next" => nil, + "prev" => nil, + "first" => { + "@href" => "/v3/repo/#{repo.id}/branches?sort_by=exists_on_github&limit=1", + "offset" => 0, + "limit" => 1 }, + "last" => { + "@href" => "/v3/repo/#{repo.id}/branches?sort_by=exists_on_github&limit=1", + "offset" => 0, + "limit" => 1 }} + } + end + describe "sorting by unknown sort field" do before { get("/v3/repo/#{repo.id}/branches?sort_by=name:desc,foo&limit=1") } example { expect(last_response).to be_ok }