summaryrefslogtreecommitdiff
path: root/qa/qa/scenario/gitlab/repository/push.rb
blob: b00ab0c313a65f865f5313bff89f01846cedb9db (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
require "pry-byebug"

module QA
  module Scenario
    module Gitlab
      module Repository
        class Push < Scenario::Template
          PAGE_REGEX_CHECK =
            %r{\/#{Runtime::Namespace.sandbox_name}\/qa-test[^\/]+\/{1}[^\/]+\z}.freeze

          attr_writer :file_name,
                      :file_content,
                      :commit_message,
                      :branch_name

          def initialize
            @file_name = 'file.txt'
            @file_content = '# This is test project'
            @commit_message = "Add #{@file_name}"
            @branch_name = 'master'
          end

          def perform
            Git::Repository.perform do |repository|
              repository.location = Page::Project::Show.act do
                unless PAGE_REGEX_CHECK.match(current_path)
                  raise "To perform this scenario the current page should be project show."
                end

                choose_repository_clone_http
                repository_location
              end

              repository.use_default_credentials
              repository.clone
              repository.configure_identity('GitLab QA', 'root@gitlab.com')

              repository.add_file(@file_name, @file_content)
              repository.commit(@commit_message)
              repository.push_changes(@branch_name)
            end
          end
        end
      end
    end
  end
end