Class: Taeval::GitCheckout::GitlabRepo
- Inherits:
-
Object
- Object
- Taeval::GitCheckout::GitlabRepo
- Defined in:
- lib/taeval/git_checkout/gitlab_repo.rb
Instance Method Summary collapse
- #clone ⇒ Object
-
#initialize(config, output, reporter) ⇒ GitlabRepo
constructor
A new instance of GitlabRepo.
- #validate ⇒ Object
Constructor Details
#initialize(config, output, reporter) ⇒ GitlabRepo
Returns a new instance of GitlabRepo.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/taeval/git_checkout/gitlab_repo.rb', line 6 def initialize(config, output, reporter) @reporter = reporter @output = output @id = config[:id] @token = config[:token] @user = config[:user] @repo = config[:repo] @branch = config[:branch] @solution = config[:solution] @prefix = config[:prefix] @attr = config[:attr] end |
Instance Method Details
#clone ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/taeval/git_checkout/gitlab_repo.rb', line 52 def clone url = "https://oauth2:#{@token}@gitlab.com/#{@user}/#{@repo}.git" cmd = "git clone #{url} --branch=#{@branch} #{@solution}/#{@repo}" stdout, stderr, status = Open3.capture3(cmd) @output.print "cloning #{url}", stdout, stderr @reporter.add(repo: @repo, runner: :git_checkout, msg: "#{status}; #{stderr}") if status != 0 end |
#validate ⇒ Object
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 |
# File 'lib/taeval/git_checkout/gitlab_repo.rb', line 22 def validate url = "https://gitlab.com/api/v4/projects/#{@user}%2F#{@repo}" cmd = "curl -sL --header 'PRIVATE-TOKEN: #{@token}' #{url}" stdout, stderr, status = Open3.capture3(cmd) @output.print "validating #{url}", stdout, stderr repo_api_data = JSON.parse(stdout, symbolize_names: true) if stderr == '' && !repo_api_data.has_key?(:message) field_validate(repo_api_data) else @reporter.add(repo: @repo, runner: :git_checkout, msg: "status: #{status}; message: #{stderr}") if stderr != '' @reporter.add(repo: @repo, runner: :git_checkout, msg: "status: #{status}; message: #{repo_api_data[:message]}; url: #{url}") if repo_api_data.has_key?(:message) end cmd = "curl -sL --header 'PRIVATE-TOKEN: #{@token}' #{url}/users" stdout, stderr, status = Open3.capture3(cmd) @output.print "validating #{url}/users", stdout, stderr repo_api_data = JSON.parse(stdout, symbolize_names: true) if stderr == '' && repo_api_data.is_a?(Array) fork_validate(repo_api_data) else @reporter.add(repo: @repo, runner: :git_checkout, msg: "status: #{status}; message: #{stderr}") if stderr != '' @reporter.add(repo: @repo, runner: :git_checkout, msg: "status: #{status}; message: #{repo_api_data[:message]}; url: #{url}") if repo_api_data.has_key?(:message) end end |