class Taeval::GitCheckout::BitbucketRepo
Public Class Methods
new(config, output, reporter)
click to toggle source
# File lib/taeval/git_checkout/bitbucket_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
Public Instance Methods
clone()
click to toggle source
# File lib/taeval/git_checkout/bitbucket_repo.rb, line 52 def clone url = "https://#{@token}@bitbucket.org/#{@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()
click to toggle source
# File lib/taeval/git_checkout/bitbucket_repo.rb, line 22 def validate url = "https://api.bitbucket.org/2.0/repositories/#{@user}/#{@repo}" cmd = "curl -sL --user '#{@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?(:error) 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[:error]}; url: #{url}") if repo_api_data.has_key?(:error) end cmd = "curl -sL --user '#{@token}' #{url}/forks" stdout, stderr, status = Open3.capture3(cmd) @output.print "validating #{url}/forks", stdout, stderr repo_api_data = JSON.parse(stdout, symbolize_names: true) if stderr == '' && !repo_api_data.has_key?(:error) 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[:error]}; url: #{url}") if repo_api_data.has_key?(:error) end end
Private Instance Methods
field_validate(data)
click to toggle source
# File lib/taeval/git_checkout/bitbucket_repo.rb, line 64 def field_validate(data) @reporter.add(repo: @repo, runner: :git_checkout, msg: "Repo should start with #{@prefix}") if !data[:name].start_with?(@prefix) @reporter.add(repo: @repo, runner: :git_checkout, msg: "Attribute is_private should be #{@attr[:private]}") if data[:is_private] != @attr[:private] end
fork_validate(data)
click to toggle source
# File lib/taeval/git_checkout/bitbucket_repo.rb, line 69 def fork_validate(data) @reporter.add(repo: @repo, runner: :git_checkout, msg: "Fork counts should be 0") if data[:values].size > 0 end