class Taeval::GitCheckout::GitlabRepo
Public Class Methods
new(config, output, reporter)
click to toggle source
# 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
Public Instance Methods
clone()
click to toggle source
# 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()
click to toggle source
# 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
Private Instance Methods
field_validate(data)
click to toggle source
# File lib/taeval/git_checkout/gitlab_repo.rb, line 64 def field_validate(data) if !data[:path].start_with?(@prefix) @reporter.add(repo: @repo, runner: :git_checkout, msg: "Repo should start with #{@prefix}") else @reporter.add(repo: @repo, runner: :git_checkout, msg: "Attribute visibility should be private") if data[:visibility] != '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] end end end
fork_validate(data)
click to toggle source
# File lib/taeval/git_checkout/gitlab_repo.rb, line 78 def fork_validate(data) if data.size > 2 @reporter.add(repo: @repo, runner: :git_checkout, msg: "Too many users assigned to the project.") end end