BigW Consortium Gitlab

Commit 994e49b3 by Shinya Maeda

Fixed those points.

- username to user_id - Drop duration - Resolve comments - Add Changelog - Edit docs
parent 01f60839
...@@ -12,9 +12,8 @@ class PipelinesFinder ...@@ -12,9 +12,8 @@ class PipelinesFinder
items = by_scope(items) items = by_scope(items)
items = by_status(items) items = by_status(items)
items = by_ref(items) items = by_ref(items)
items = by_user(items) items = by_username(items)
items = by_duration(items) items = by_yaml_errors(items)
items = by_yaml_error(items)
order_and_sort(items) order_and_sort(items)
end end
...@@ -80,24 +79,16 @@ class PipelinesFinder ...@@ -80,24 +79,16 @@ class PipelinesFinder
end end
end end
def by_user(items) def by_username(items)
if params[:user_id].present? if params[:username].present?
items.where(user_id: params[:user_id]) items.joins(:user).where("users.name = ?", params[:username])
else else
items items
end end
end end
def by_duration(items) def by_yaml_errors(items)
if params[:duration].present? if params[:yaml_errors].present? && params[:yaml_errors]
items.where("duration > ?", params[:duration])
else
items
end
end
def by_yaml_error(items)
if params[:yaml_error].present? && params[:yaml_error]
items.where("yaml_errors IS NOT NULL") items.where("yaml_errors IS NOT NULL")
else else
items items
...@@ -105,7 +96,9 @@ class PipelinesFinder ...@@ -105,7 +96,9 @@ class PipelinesFinder
end end
def order_and_sort(items) 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]}") items.order("#{params[:order_by]} #{params[:sort]}")
else else
items.order(id: :desc) items.order(id: :desc)
......
---
title: Resolve Feature Proposal Include search options to pipelines API
merge_request: 9367
author: dosuken123
...@@ -11,6 +11,13 @@ GET /projects/:id/pipelines ...@@ -11,6 +11,13 @@ GET /projects/:id/pipelines
| Attribute | Type | Required | Description | | 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 | | `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" curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/pipelines"
......
...@@ -14,18 +14,17 @@ module API ...@@ -14,18 +14,17 @@ module API
end end
params do params do
use :pagination use :pagination
optional :scope, type: String, values: %w(running branches tags), optional :scope, type: String, values: %w(running pending finished branches tags),
desc: 'Either running, branches, or tags' desc: 'The scope of pipelines'
optional :status, type: String, values: ['running', 'pending', 'success', 'failed', 'canceled', 'skipped'], optional :status, type: String, values: ['running', 'pending', 'success', 'failed', 'canceled', 'skipped'],
desc: 'Pipeline Status' desc: 'The status of pipelines'
optional :ref, type: String, desc: 'Pipeline Ref' optional :ref, type: String, desc: 'The ref of pipelines'
optional :duration, type: Integer, desc: 'Greater than the specified duration' optional :yaml_errors, type: Boolean, desc: 'If true, Returns only yaml error pipelines'
optional :yaml_error, type: Boolean, desc: 'If true, returns only yaml error pipelines.' optional :username, type: String, desc: 'The name of user who triggered pipelines'
optional :user_id, type: String, desc: 'User who executed pipelines'
optional :order_by, type: String, values: ['id', 'status', 'ref', 'user_id', 'started_at', 'finished_at', 'created_at', 'updated_at'], default: 'id', 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', 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 end
get ':id/pipelines' do get ':id/pipelines' do
authorize! :read_pipeline, user_project authorize! :read_pipeline, user_project
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment