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

project_imported_from_github.rb « resource « qa « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 855e1edf3efb1dbee64afb1539f302b9f5a48dcf (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# frozen_string_literal: true

module QA
  module Resource
    class ProjectImportedFromGithub < Resource::Project
      attr_accessor :issue_events_import,
        :full_notes_import,
        :attachments_import,
        :allow_partial_import,
        :additional_access_tokens

      attribute :github_repo_id do
        github_client.repository(github_repository_path).id
      end

      def fabricate!
        self.import = true

        Page::Main::Menu.perform(&:go_to_create_project)

        go_to_import_page

        Page::Project::Import::Github.perform do |import_page|
          import_page.add_personal_access_token(github_personal_access_token)

          import_page.select_advanced_option(:single_endpoint_issue_events_import) if issue_events_import
          import_page.select_advanced_option(:single_endpoint_notes_import) if full_notes_import
          import_page.select_advanced_option(:attachments_import) if attachments_import

          import_page.import!(github_repository_path, group.full_path, name)
          import_page.wait_for_success(github_repository_path, wait: 240, allow_partial_import: allow_partial_import)
        end

        reload!
        visit!
      end

      def go_to_import_page
        Page::Project::New.perform do |project_page|
          project_page.click_import_project
          project_page.click_github_link
        end
      end

      def fabricate_via_api!
        super
      rescue ResourceURLMissingError
        "#{Runtime::Scenario.gitlab_address}/#{full_path}"
      end

      def api_post_path
        '/import/github'
      end

      def api_trigger_mirror_pull_path
        "#{api_get_path}/mirror/pull"
      end

      def api_post_body
        {
          repo_id: github_repo_id,
          new_name: name,
          target_namespace: @personal_namespace || group.full_path,
          personal_access_token: github_personal_access_token,
          additional_access_tokens: additional_access_tokens,
          ci_cd_only: false,
          optional_stages: {
            single_endpoint_issue_events_import: issue_events_import,
            single_endpoint_notes_import: full_notes_import,
            attachments_import: attachments_import
          }
        }.compact
      end

      def transform_api_resource(api_resource)
        api_resource
      end

      def trigger_project_mirror
        Runtime::Logger.info "Triggering pull mirror request"

        Support::Retrier.retry_until(max_attempts: 6, sleep_interval: 10) do
          response = post(request_url(api_trigger_mirror_pull_path), nil)

          Runtime::Logger.info "Mirror pull request response: #{response}"
          response.code == Support::API::HTTP_STATUS_OK
        end
      end

      private

      # Github client
      #
      # @return [Octokit::Client]
      def github_client
        @github_client ||= Octokit::Client.new(access_token: github_personal_access_token)
      end
    end
  end
end