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

jira_controller.rb « import « projects « controllers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c74c180fa205ed1be8918b62709a6d9c5a2b0ee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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