From df97e21c4faffaf14f23c407047cde17f61d95ba Mon Sep 17 00:00:00 2001
From: George Andrinopoulos <geoandri@gmail.com>
Date: Tue, 14 Feb 2017 17:51:30 +0200
Subject: [PATCH] Rebase to master for avoiding failing tests

---
 .../26875-builds-api-endpoint-skipped-scope.yml    |  4 ++++
 lib/api/builds.rb                                  |  2 +-
 spec/requests/api/builds_spec.rb                   | 14 ++++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 changelogs/unreleased/26875-builds-api-endpoint-skipped-scope.yml

diff --git a/changelogs/unreleased/26875-builds-api-endpoint-skipped-scope.yml b/changelogs/unreleased/26875-builds-api-endpoint-skipped-scope.yml
new file mode 100644
index 00000000000..3d6400cba76
--- /dev/null
+++ b/changelogs/unreleased/26875-builds-api-endpoint-skipped-scope.yml
@@ -0,0 +1,4 @@
+---
+title: Add all available statuses to scope filter for project builds endpoint
+merge_request:
+author: George Andrinopoulos
diff --git a/lib/api/builds.rb b/lib/api/builds.rb
index 44fe0fc4a95..5b76913fe45 100644
--- a/lib/api/builds.rb
+++ b/lib/api/builds.rb
@@ -11,7 +11,7 @@ module API
       helpers do
         params :optional_scope do
           optional :scope, types: [String, Array[String]], desc: 'The scope of builds to show',
-                           values:  ['pending', 'running', 'failed', 'success', 'canceled'],
+                           values: ::CommitStatus::AVAILABLE_STATUSES,
                            coerce_with: ->(scope) {
                              if scope.is_a?(String)
                                [scope]
diff --git a/spec/requests/api/builds_spec.rb b/spec/requests/api/builds_spec.rb
index 38aef7f2767..76a10a2374c 100644
--- a/spec/requests/api/builds_spec.rb
+++ b/spec/requests/api/builds_spec.rb
@@ -16,6 +16,8 @@ describe API::Builds, api: true do
     let(:query) { '' }
 
     before do
+      create(:ci_build, :skipped, pipeline: pipeline)
+
       get api("/projects/#{project.id}/builds?#{query}", api_user)
     end
 
@@ -49,6 +51,18 @@ describe API::Builds, api: true do
         end
       end
 
+      context 'filter project with scope skipped' do
+        let(:query) { 'scope=skipped' }
+        let(:json_build) { json_response.first }
+
+        it 'return builds with status skipped' do
+          expect(response).to have_http_status 200
+          expect(json_response).to be_an Array
+          expect(json_response.length).to eq 1
+          expect(json_build['status']).to eq 'skipped'
+        end
+      end
+
       context 'filter project with array of scope elements' do
         let(:query) { 'scope[0]=pending&scope[1]=running' }
 
-- 
GitLab