Commit 4f7ccca0 authored by Michael Kozono's avatar Michael Kozono

Merge branch '224850-create-api-endpoint-for-querying-jira-issues' into 'master'

Create a JSON endpoint for querying Jira issues

See merge request gitlab-org/gitlab!35477
parents 629c7f77 7de3ae9c
...@@ -14,6 +14,22 @@ module Projects ...@@ -14,6 +14,22 @@ module Projects
end end
def index def index
respond_to do |format|
format.html
format.json do
render json: issues_json
rescue Projects::Integrations::Jira::IntegrationError, Projects::Integrations::Jira::RequestError => e
render_bad_request(e)
end
end
end
private
def issues_json
jira_issues = ::Projects::Integrations::Jira::IssuesFinder.new(project, {}).execute
::Integrations::Jira::IssueSerializer.new.represent(jira_issues, project: project)
end end
protected protected
...@@ -21,6 +37,10 @@ module Projects ...@@ -21,6 +37,10 @@ module Projects
def check_feature_enabled! def check_feature_enabled!
return render_404 unless Feature.enabled?(:jira_integration, project) return render_404 unless Feature.enabled?(:jira_integration, project)
end end
def render_bad_request(error)
render json: { errors: [error.message] }, status: :bad_request
end
end end
end end
end end
......
- page_title _('Jira Issues') - page_title _('Jira Issues')
.js-issuables-list{ data: { endpoint: expose_url(api_v4_groups_issues_path(id: @project.group.id)), .js-issuables-list{ data: { endpoint: expose_path(project_integrations_jira_issues_path(@project, format: :json)),
'can-bulk-edit': false, 'can-bulk-edit': false,
'empty-svg-path': image_path('illustrations/issues.svg'), 'empty-svg-path': image_path('illustrations/issues.svg'),
'sort-key': @sort } } 'sort-key': @sort } }
...@@ -9,57 +9,91 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do ...@@ -9,57 +9,91 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
let(:user) { create(:user) } let(:user) { create(:user) }
describe 'GET #index' do describe 'GET #index' do
context 'external issue tracker' do before do
sign_in(user)
project.add_developer(user)
create(:jira_service, project: project)
end
context 'when jira_integration feature disabled' do
it 'returns 404 status' do
stub_feature_flags(jira_integration: false)
get :index, params: { namespace_id: project.namespace, project_id: project }
expect(response).to have_gitlab_http_status(:not_found)
end
end
it 'renders the "index" template' do
get :index, params: { namespace_id: project.namespace, project_id: project }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
end
context 'when project has moved' do
let(:new_project) { create(:project) }
before do before do
sign_in(user) project.route.destroy!
project.add_developer(user) new_project.redirect_routes.create!(path: project.full_path)
create(:jira_service, project: project) new_project.add_developer(user)
end end
it 'renders the "index" template' do it 'redirects to the new issue tracker from the old one' do
get :index, params: { namespace_id: project.namespace, project_id: project } get :index, params: { namespace_id: project.namespace, project_id: project }
expect(response).to have_gitlab_http_status(:ok) expect(response).to redirect_to(project_integrations_jira_issues_path(new_project))
expect(response).to render_template(:index) expect(response).to have_gitlab_http_status(:found)
end end
end
context 'when jira_integration feature disabled' do context 'json request' do
it 'returns 404 status' do let(:jira_issues) { [] }
stub_feature_flags(jira_integration: false)
get :index, params: { namespace_id: project.namespace, project_id: project } it 'returns a list of serialized jira issues' do
expect_next_instance_of(Projects::Integrations::Jira::IssuesFinder, project, {}) do |finder|
expect(finder).to receive(:execute).and_return(jira_issues)
end
expect(response).to have_gitlab_http_status(:not_found) expect_next_instance_of(Integrations::Jira::IssueSerializer) do |serializer|
expect(serializer).to receive(:represent).with(jira_issues, project: project)
end end
get :index, params: { namespace_id: project.namespace, project_id: project }, format: :json
end end
context 'when project has moved' do it 'renders bad request for IntegrationError' do
let(:new_project) { create(:project) } expect_any_instance_of(Projects::Integrations::Jira::IssuesFinder).to receive(:execute)
.and_raise(Projects::Integrations::Jira::IntegrationError, 'Integration error')
before do get :index, params: { namespace_id: project.namespace, project_id: project }, format: :json
project.route.destroy!
new_project.redirect_routes.create!(path: project.full_path)
new_project.add_developer(user)
end
it 'redirects to the new issue tracker from the old one' do expect(response).to have_gitlab_http_status(:bad_request)
get :index, params: { namespace_id: project.namespace, project_id: project } expect(json_response['errors']).to eq ['Integration error']
end
expect(response).to redirect_to(project_integrations_jira_issues_path(new_project)) it 'renders bad request for RequestError' do
expect(response).to have_gitlab_http_status(:found) expect_any_instance_of(Projects::Integrations::Jira::IssuesFinder).to receive(:execute)
end .and_raise(Projects::Integrations::Jira::RequestError, 'Request error')
get :index, params: { namespace_id: project.namespace, project_id: project }, format: :json
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['errors']).to eq ['Request error']
end end
end end
end
context 'external authorization' do context 'external authorization' do
before do before do
sign_in user sign_in user
project.add_developer(user) project.add_developer(user)
end end
it_behaves_like 'unauthorized when external service denies access' do it_behaves_like 'unauthorized when external service denies access' do
subject { get :index, params: { namespace_id: project.namespace, project_id: project } } subject { get :index, params: { namespace_id: project.namespace, project_id: project } }
end
end end
end end
end end
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