summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-02-28 21:24:49 +0900
committerShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-05-03 02:11:50 +0900
commit994e49b3fbc261f8e59429c1681d83c81ba25df3 (patch)
treec149ebe3247be8a074f4a2d5400874ec3ce3d9b8
parent01f6083939f8f9559f7e134f111bd40d17d357f9 (diff)
downloadgitlab-ce-994e49b3fbc261f8e59429c1681d83c81ba25df3.tar.gz
Fixed those points.
- username to user_id - Drop duration - Resolve comments - Add Changelog - Edit docs
-rw-r--r--app/finders/pipelines_finder.rb27
-rw-r--r--changelogs/unreleased/28408-feature-proposal-include-search-options-to-pipelines-api.yml4
-rw-r--r--doc/api/pipelines.md7
-rw-r--r--lib/api/pipelines.rb17
4 files changed, 29 insertions, 26 deletions
diff --git a/app/finders/pipelines_finder.rb b/app/finders/pipelines_finder.rb
index 3a95a1eb2ae..c2e247a7ded 100644
--- a/app/finders/pipelines_finder.rb
+++ b/app/finders/pipelines_finder.rb
@@ -12,9 +12,8 @@ class PipelinesFinder
items = by_scope(items)
items = by_status(items)
items = by_ref(items)
- items = by_user(items)
- items = by_duration(items)
- items = by_yaml_error(items)
+ items = by_username(items)
+ items = by_yaml_errors(items)
order_and_sort(items)
end
@@ -80,24 +79,16 @@ class PipelinesFinder
end
end
- def by_user(items)
- if params[:user_id].present?
- items.where(user_id: params[:user_id])
+ def by_username(items)
+ if params[:username].present?
+ items.joins(:user).where("users.name = ?", params[:username])
else
items
end
end
- def by_duration(items)
- if params[:duration].present?
- items.where("duration > ?", params[:duration])
- else
- items
- end
- end
-
- def by_yaml_error(items)
- if params[:yaml_error].present? && params[:yaml_error]
+ def by_yaml_errors(items)
+ if params[:yaml_errors].present? && params[:yaml_errors]
items.where("yaml_errors IS NOT NULL")
else
items
@@ -105,7 +96,9 @@ class PipelinesFinder
end
def order_and_sort(items)
- if params[:order_by].present? && params[:sort].present?
+ if params[:order_by].present? && params[:sort].present? &&
+ items.column_names.include?(params[:order_by]) &&
+ (params[:sort].downcase == 'asc' || params[:sort].downcase == 'desc')
items.order("#{params[:order_by]} #{params[:sort]}")
else
items.order(id: :desc)
diff --git a/changelogs/unreleased/28408-feature-proposal-include-search-options-to-pipelines-api.yml b/changelogs/unreleased/28408-feature-proposal-include-search-options-to-pipelines-api.yml
new file mode 100644
index 00000000000..6fb3da99fb4
--- /dev/null
+++ b/changelogs/unreleased/28408-feature-proposal-include-search-options-to-pipelines-api.yml
@@ -0,0 +1,4 @@
+---
+title: Resolve Feature Proposal Include search options to pipelines API
+merge_request: 9367
+author: dosuken123
diff --git a/doc/api/pipelines.md b/doc/api/pipelines.md
index 732ad8da4ac..9281e6bb6d5 100644
--- a/doc/api/pipelines.md
+++ b/doc/api/pipelines.md
@@ -11,6 +11,13 @@ GET /projects/:id/pipelines
| Attribute | Type | Required | Description |
|-----------|---------|----------|---------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
+| `scope` | string | no | The scope of pipelines, one of: `running`, `pending`, `finished`, `branches`, `tags`; |
+| `status` | string | no | The status of pipelines, one of: `running`, `pending`, `success`, `failed`, `canceled`, `skipped`; |
+| `ref` | string | no | The ref of pipelines |
+| `yaml_errors`| string | no | If true, Returns only yaml error pipelines |
+| `username`| string | no | The name of user who triggered pipelines |
+| `order_by`| string | no | The order_by which is combined with a `sort`, one of: `id`, `status`, `ref`, `user_id`, `started_at`, `finished_at`, `created_at`, `updated_at`; |
+| `sort` | string | no | The sort method which is combined with an `order_by`, one of: `asc`, `desc`; |
```
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/pipelines"
diff --git a/lib/api/pipelines.rb b/lib/api/pipelines.rb
index 905e72a3a95..48ab5c21780 100644
--- a/lib/api/pipelines.rb
+++ b/lib/api/pipelines.rb
@@ -14,18 +14,17 @@ module API
end
params do
use :pagination
- optional :scope, type: String, values: %w(running branches tags),
- desc: 'Either running, branches, or tags'
+ optional :scope, type: String, values: %w(running pending finished branches tags),
+ desc: 'The scope of pipelines'
optional :status, type: String, values: ['running', 'pending', 'success', 'failed', 'canceled', 'skipped'],
- desc: 'Pipeline Status'
- optional :ref, type: String, desc: 'Pipeline Ref'
- optional :duration, type: Integer, desc: 'Greater than the specified duration'
- optional :yaml_error, type: Boolean, desc: 'If true, returns only yaml error pipelines.'
- optional :user_id, type: String, desc: 'User who executed pipelines'
+ desc: 'The status of pipelines'
+ optional :ref, type: String, desc: 'The ref of pipelines'
+ optional :yaml_errors, type: Boolean, desc: 'If true, Returns only yaml error pipelines'
+ optional :username, type: String, desc: 'The name of user who triggered pipelines'
optional :order_by, type: String, values: ['id', 'status', 'ref', 'user_id', 'started_at', 'finished_at', 'created_at', 'updated_at'], default: 'id',
- desc: 'Return issues ordered by `created_at` or `updated_at` fields.'
+ desc: 'The order_by which is combined with a sort'
optional :sort, type: String, values: ['asc', 'desc'], default: 'desc',
- desc: 'Return pipelines sorted in `asc` or `desc` order.'
+ desc: 'The sort method which is combined with an order_by'
end
get ':id/pipelines' do
authorize! :read_pipeline, user_project