Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2018-02-20 20:20:14 +0300
committerRobert Schilling <rschilling@student.tugraz.at>2018-02-20 22:05:12 +0300
commite8fc5dd89d503f83e4ce707c3051008c54720027 (patch)
tree0474a772713bb5d721c02f15f8675adb57a69c25
parent81add16e67aabaf907365c8061019b371d20ec3b (diff)
API: Fix archived parameter for projects APIapi-fix-archived
-rw-r--r--changelogs/unreleased/api-fix-archived.yml5
-rw-r--r--lib/api/helpers.rb11
-rw-r--r--lib/api/projects.rb2
-rw-r--r--spec/requests/api/projects_spec.rb40
4 files changed, 52 insertions, 6 deletions
diff --git a/changelogs/unreleased/api-fix-archived.yml b/changelogs/unreleased/api-fix-archived.yml
new file mode 100644
index 00000000000..3c06573cbc1
--- /dev/null
+++ b/changelogs/unreleased/api-fix-archived.yml
@@ -0,0 +1,5 @@
+---
+title: 'API: Fix archived parameter for projects API'
+merge_request: 17244
+author: Robert Schilling
+type: fixed
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 6134ad2bfc7..643d9a05009 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -379,7 +379,16 @@ module API
finder_params[:non_public] = true if params[:membership].present?
finder_params[:starred] = true if params[:starred].present?
finder_params[:visibility_level] = Gitlab::VisibilityLevel.level_value(params[:visibility]) if params[:visibility]
- finder_params[:archived] = params[:archived]
+
+ unless params[:archived].nil?
+ finder_params[:archived] =
+ if params[:archived]
+ 'only'
+ else
+ false
+ end
+ end
+
finder_params[:search] = params[:search] if params[:search]
finder_params[:user] = params.delete(:user) if params[:user]
finder_params[:custom_attributes] = params[:custom_attributes] if params[:custom_attributes]
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index e90892a90f7..24806dd72b6 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -55,7 +55,7 @@ module API
end
params :filter_params do
- optional :archived, type: Boolean, default: false, desc: 'Limit by archived status'
+ optional :archived, type: Boolean, default: nil, desc: 'Limit by archived status'
optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values,
desc: 'Limit by visibility'
optional :search, type: String, desc: 'Return list of projects matching the search criteria'
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index cee93f6ed14..cd50d9079ec 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -15,8 +15,8 @@ describe API::Projects do
create(:project,
:private,
:repository,
- name: 'second_project',
- path: 'second_project',
+ name: 'third_project',
+ path: 'third_project',
creator_id: user.id,
namespace: user.namespace,
merge_requests_enabled: false,
@@ -32,8 +32,8 @@ describe API::Projects do
end
let(:project4) do
create(:project,
- name: 'third_project',
- path: 'third_project',
+ name: 'fourth_project',
+ path: 'fourth_project',
creator_id: user4.id,
namespace: user4.namespace)
end
@@ -225,6 +225,38 @@ describe API::Projects do
end
end
+ context 'and using archived' do
+ let!(:archived_project) { create(:project, creator_id: user.id, namespace: user.namespace, archived: true) }
+
+ it 'returns archived project' do
+ get api('/projects?archived=true', user)
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(json_response).to be_an Array
+ expect(json_response.length).to eq(1)
+ expect(json_response.first['id']).to eq(archived_project.id)
+ end
+
+ it 'returns non-archived project' do
+ get api('/projects?archived=false', user)
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(json_response).to be_an Array
+ expect(json_response.length).to eq(4)
+ end
+
+ it 'returns all project' do
+ get api('/projects', user)
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(json_response).to be_an Array
+ expect(json_response.length).to eq(5)
+ end
+ end
+
context 'and using search' do
it_behaves_like 'projects response' do
let(:filter) { { search: project.name } }