diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-13 15:09:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-13 15:09:22 +0300 |
commit | 286fe61013674fe2d245ffc8d2233baf09923e70 (patch) | |
tree | 2037291f5863105e54e75be056b49f7d62007cae /app/controllers/projects/import/jira_controller.rb | |
parent | 4cb5e5011abfe8d50ac3a7ebd0018c563c6d7af4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/controllers/projects/import/jira_controller.rb')
-rw-r--r-- | app/controllers/projects/import/jira_controller.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/app/controllers/projects/import/jira_controller.rb b/app/controllers/projects/import/jira_controller.rb new file mode 100644 index 00000000000..c74c180fa20 --- /dev/null +++ b/app/controllers/projects/import/jira_controller.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +module Projects + module Import + class JiraController < Projects::ApplicationController + before_action :jira_import_enabled? + before_action :jira_integration_configured? + + def show + unless @project.import_state&.in_progress? + jira_client = @project.jira_service.client + @jira_projects = jira_client.Project.all.map { |p| ["#{p.name} (#{p.key})", p.key] } + end + + flash[:notice] = _("Import %{status}") % { status: @project.import_state.status } if @project.import_state.present? && !@project.import_state.none? + end + + def import + import_state = @project.import_state || @project.create_import_state + + schedule_import(jira_import_params) unless import_state.in_progress? + + redirect_to project_import_jira_path(@project) + end + + private + + def jira_import_enabled? + return if Feature.enabled?(:jira_issue_import, @project) + + redirect_to project_issues_path(@project) + end + + def jira_integration_configured? + return if @project.jira_service + + flash[:notice] = _("Configure the Jira integration first on your project's %{strong_start} Settings > Integrations > Jira%{strong_end} page." % + { strong_start: '<strong>'.html_safe, strong_end: '</strong>'.html_safe }) + redirect_to project_issues_path(@project) + end + + def schedule_import(params) + import_data = @project.create_or_update_import_data(data: {}).becomes(JiraImportData) + + import_data << JiraImportData::JiraProjectDetails.new( + params[:jira_project_key], + Time.now.strftime('%Y-%m-%d %H:%M:%S'), + { user_id: current_user.id, name: current_user.name } + ) + + @project.import_type = 'jira' + @project.import_state.schedule if @project.save + end + + def jira_import_params + params.permit(:jira_project_key) + end + end + end +end |