diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2019-07-05 14:30:48 +0000 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2019-07-05 14:30:48 +0000 |
commit | 5ecb2db89e7fb53f95bf7613253dfbfb5705e4d9 (patch) | |
tree | 29abb18341f29c8431ac0c1ba181021a0bc77a59 /app | |
parent | c9748d66d4313beacd449ab6efdf241cd740fa6d (diff) | |
parent | c7acdbf961b95565561209ea36e94a8e130e53bf (diff) | |
download | gitlab-ce-5ecb2db89e7fb53f95bf7613253dfbfb5705e4d9.tar.gz |
Merge branch '51794-add-ordering-to-runner-jobs-api' into 'master'
Adding order by to list runner jobs api.
Closes #51794
See merge request gitlab-org/gitlab-ce!29629
Diffstat (limited to 'app')
-rw-r--r-- | app/finders/runner_jobs_finder.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/finders/runner_jobs_finder.rb b/app/finders/runner_jobs_finder.rb index 4fca4ec94f3..ef90817416a 100644 --- a/app/finders/runner_jobs_finder.rb +++ b/app/finders/runner_jobs_finder.rb @@ -3,6 +3,8 @@ class RunnerJobsFinder attr_reader :runner, :params + ALLOWED_INDEXED_COLUMNS = %w[id].freeze + def initialize(runner, params = {}) @runner = runner @params = params @@ -11,7 +13,7 @@ class RunnerJobsFinder def execute items = @runner.builds items = by_status(items) - items + sort_items(items) end private @@ -23,4 +25,19 @@ class RunnerJobsFinder items.where(status: params[:status]) end # rubocop: enable CodeReuse/ActiveRecord + + # rubocop: disable CodeReuse/ActiveRecord + def sort_items(items) + return items unless ALLOWED_INDEXED_COLUMNS.include?(params[:order_by]) + + order_by = params[:order_by] + sort = if /\A(ASC|DESC)\z/i.match?(params[:sort]) + params[:sort] + else + :desc + end + + items.order(order_by => sort) + end + # rubocop: enable CodeReuse/ActiveRecord end |