class Taeval::GitCheckout::GithubRepo
Public Class Methods
new(config, output, reporter)
click to toggle source
# File lib/taeval/git_checkout/github_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/github_repo.rb, line 39 def clone url = "https://#{@user}:#{@token}@github.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()
click to toggle source
# File lib/taeval/git_checkout/github_repo.rb, line 22 def validate url = "https://api.github.com/repos/#{@user}/#{@repo}" cmd = "curl -sL -H 'Authorization: token #{@token}' -H 'Accept: application/vnd.github.v3+json' #{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 end
Private Instance Methods
field_validate(data)
click to toggle source
# File lib/taeval/git_checkout/github_repo.rb, line 51 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 private should be #{@attr[:private]}") if data[:private] != @attr[:private] @reporter.add(repo: @repo, runner: :git_checkout, msg: "Attribute forks_count should be #{@attr[:forks_count]}") if data[:forks_count] != @attr[:forks_count] if @attr[:fork] @reporter.add(repo: @repo, runner: :git_checkout, msg: "Attribute parent->full_name should be #{@attr[:fork_parent]}") if data.dig(:parent, :full_name) != @attr[:fork_parent] else @reporter.add(repo: @repo, runner: :git_checkout, msg: "Attribute parent should be nil (#{data.dig(:parent, :full_name)})") if !data.dig(:parent, :full_name).nil? end end