summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/project.rb4
-rw-r--r--doc/api/projects.md3
-rw-r--r--lib/api/entities.rb1
-rw-r--r--spec/models/project_spec.rb6
-rw-r--r--spec/requests/api/projects_spec.rb16
6 files changed, 30 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index e38c8b363e7..ae544c08c79 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
Please view this file on the master branch, on stable branches it's out of date.
v 8.3.0 (unreleased)
+ - Add open_issues_count to project API (Stan Hu)
- Expand character set of usernames created by Omniauth (Corey Hinshaw)
- Add button to automatically merge a merge request when the build succeeds (Zeger-Jan van de Weg)
- Merge when build succeeds (Zeger-Jan van de Weg)
diff --git a/app/models/project.rb b/app/models/project.rb
index e78868af1cc..6756e45caa8 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -825,4 +825,8 @@ class Project < ActiveRecord::Base
forked_project_link.destroy
end
end
+
+ def open_issues_count
+ issues.opened.count
+ end
end
diff --git a/doc/api/projects.md b/doc/api/projects.md
index 43a50a9a810..15956fe6df2 100644
--- a/doc/api/projects.md
+++ b/doc/api/projects.md
@@ -59,6 +59,7 @@ Parameters:
"path": "diaspora-client",
"path_with_namespace": "diaspora/diaspora-client",
"issues_enabled": true,
+ "open_issues_count": 1,
"merge_requests_enabled": true,
"builds_enabled": true,
"wiki_enabled": true,
@@ -101,6 +102,7 @@ Parameters:
"path": "puppet",
"path_with_namespace": "brightbox/puppet",
"issues_enabled": true,
+ "open_issues_count": 1,
"merge_requests_enabled": true,
"builds_enabled": true,
"wiki_enabled": true,
@@ -192,6 +194,7 @@ Parameters:
"path": "diaspora-project-site",
"path_with_namespace": "diaspora/diaspora-project-site",
"issues_enabled": true,
+ "open_issues_count": 1,
"merge_requests_enabled": true,
"builds_enabled": true,
"wiki_enabled": true,
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 81bf7a8222b..014116ef130 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -68,6 +68,7 @@ module API
expose :forked_from_project, using: Entities::ForkedFromProject, if: lambda{ | project, options | project.forked? }
expose :avatar_url
expose :star_count, :forks_count
+ expose :open_issues_count, if: lambda { | project, options | project.issues_enabled? && project.default_issues_tracker? }
end
class ProjectMember < UserBasic
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 6ddb0e2b8f7..37ac0495154 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -153,13 +153,17 @@ describe Project, models: true do
describe '#get_issue' do
let(:project) { create(:empty_project) }
- let(:issue) { create(:issue, project: project) }
+ let!(:issue) { create(:issue, project: project) }
context 'with default issues tracker' do
it 'returns an issue' do
expect(project.get_issue(issue.iid)).to eq issue
end
+ it 'returns count of open issues' do
+ expect(project.open_issues_count).to eq(1)
+ end
+
it 'returns nil when no issue found' do
expect(project.get_issue(999)).to be_nil
end
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 24b765f4979..55a7b1a95f5 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -65,6 +65,22 @@ describe API::API, api: true do
expect(json_response.first.keys).to include('tag_list')
end
+ it 'should include open_issues_count' do
+ get api('/projects', user)
+ expect(response.status).to eq 200
+ expect(json_response).to be_an Array
+ expect(json_response.first.keys).to include('open_issues_count')
+ end
+
+ it 'should not include open_issues_count' do
+ project.update_attributes( { issues_enabled: false } )
+
+ get api('/projects', user)
+ expect(response.status).to eq 200
+ expect(json_response).to be_an Array
+ expect(json_response.first.keys).not_to include('open_issues_count')
+ end
+
context 'and using search' do
it 'should return searched project' do
get api('/projects', user), { search: project.name }