How to use resolved_ref method of Fetchers Package

Best Inspec_ruby code snippet using Fetchers.resolved_ref

git.rb

Source:git.rb Github

copy

Full Screen

...43 checkout44 else45 Dir.mktmpdir do |tmpdir|46 checkout(tmpdir)47 Inspec::Log.debug("Checkout of #{resolved_ref} successful. Moving checkout to #{dir}")48 FileUtils.cp_r(tmpdir, @repo_directory)49 end50 end51 @repo_directory52 end53 def cache_key54 resolved_ref55 end56 def archive_path57 @repo_directory58 end59 def resolved_source60 { git: @remote_url, ref: resolved_ref }61 end62 private63 def resolved_ref64 @resolved_ref ||= if @ref65 @ref66 elsif @branch67 resolve_ref(@branch)68 elsif @tag69 resolve_ref(@tag)70 else71 resolve_ref('master')72 end73 end74 def resolve_ref(ref_name)75 cmd = shellout("git ls-remote \"#{@remote_url}\" \"#{ref_name}*\"")76 ref = parse_ls_remote(cmd.stdout, ref_name)77 if !ref78 raise "Unable to resolve #{ref_name} to a specific git commit for #{@remote_url}"79 end80 ref81 end82 #83 # The following comment is a minor modification of the comment in84 # the omnibus source for a similar function:85 #86 # Dereference annotated tags.87 #88 # The +remote_list+ parameter is assumed to look like this:89 #90 # a2ed66c01f42514bcab77fd628149eccb4ecee28 refs/tags/rel-0.11.091 # f915286abdbc1907878376cce9222ac0b08b12b8 refs/tags/rel-0.11.0^{}92 #93 # The SHA with ^{} is the commit pointed to by an annotated94 # tag. If ref isn't an annotated tag, there will not be a line95 # with trailing ^{}.96 #97 # @param [String] output98 # output from `git ls-remote origin` command99 # @param [String] ref_name100 # the target git ref_name101 #102 # @return [String]103 #104 def parse_ls_remote(output, ref_name)105 pairs = output.lines.map { |l| l.chomp.split("\t") }106 tagged_commit = pairs.find { |m| m[1].end_with?("#{ref_name}^{}") }107 if tagged_commit108 tagged_commit.first109 else110 pairs.find { |m| m[1].end_with?(ref_name.to_s) }&.first111 end112 end113 def cloned?114 File.directory?(File.join(@repo_directory, '.git'))115 end116 def clone(dir = @repo_directory)117 git_cmd("clone #{@remote_url} ./", dir) unless cloned?118 @repo_directory119 end120 def checkout(dir = @repo_directory)121 clone(dir)122 git_cmd("checkout #{resolved_ref}", dir)123 @repo_directory124 end125 def git_cmd(cmd, dir = @repo_directory)126 cmd = shellout("git #{cmd}", cwd: dir)127 cmd.error!128 cmd.status129 rescue Errno::ENOENT130 raise 'To use git sources, you must have git installed.'131 end132 def shellout(cmd, opts = {})133 Inspec::Log.debug("Running external command: #{cmd} (#{opts})")134 cmd = Mixlib::ShellOut.new(cmd, opts)135 cmd.run_command136 Inspec::Log.debug("External command: completed with exit status: #{cmd.exitstatus}")...

Full Screen

Full Screen

resolved_ref

Using AI Code Generation

copy

Full Screen

1 ref = ref.sub(/^refs\/tags\//, '')2 ref = ref.sub(/^refs\/heads\//, '')3 ref = ref.sub(/^refs\/tags\//, '')4 ref = ref.sub(/^refs\/heads\//, '')5 ref = ref.sub(/^refs\/tags\//, '')6 ref = ref.sub(/^refs\/heads\//, '')7 ref = ref.sub(/^refs\/tags\//, '')8 ref = ref.sub(/^refs\/heads\//, '')9 ref = ref.sub(/^refs\/tags\//, '')10 ref = ref.sub(/^refs\/heads\//, '')

Full Screen

Full Screen

resolved_ref

Using AI Code Generation

copy

Full Screen

1sha1 = fetchers.resolved_ref('refs/heads/master')2sha1 = fetchers.resolved_ref('refs/tags/v0.1.0')3sha1 = fetchers.resolved_ref('refs/heads/does-not-exist')4sha1 = fetchers.resolved_ref('refs/tags/does-not-exist')5sha1 = fetchers.resolved_ref('refs/heads/master', 'refs/heads/does-not-exist')6sha1 = fetchers.resolved_ref('refs/heads/master', 'refs/heads/does-not-exist', 'refs/tags/v0.1.0')7sha1 = fetchers.resolved_ref('refs/heads/master', 'refs/heads/does-not-exist', 'refs/tags/does-not-uxisb')8sha1 fetchers.resolved_ref('refs/heads/master', 'refs/tags/does-not-exist')9sha1 fetchers.resolved_ref('refs/tags/v0.1.0', 'refs/heads/master')10sha1 fetchers.resolved_ref('refs/tags/v0.1.0', 'refs/heads/does-not-exist')11sha1 fetchers.resolved_ref('refs/tags/does-not-exist', 'refs/heads/master')12sha1 fetchers.resolved_ref('refs/tags/does-not-exist', 'refs/heads/does-not-exist')13sha1 fetchers.resolved_ref('refs/tags/does-not-exist', 'refs/tags/v0.1.0')14cmd.handle_options(['rails'])

Full Screen

Full Screen

resolved_ref

Using AI Code Generation

copy

Full Screen

1def resolve_ref(ref, owner, repo)2 client = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'])3 fetcher = OctokitUtils::Fetchers.new(repo, client)4 fetcher.resolved_ref(ref)5 sha = resolve_ref(ref, owner, repo)

Full Screen

Full Screen

resolved_ref

Using AI Code Generation

copy

Full Screen

1def resolve_ref(ref, owner, repo)2 client = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'])3 fetcher = OctokitUtils::Fetchers.new(repo, client)4 fetcher.resolved_ref(ref)5 sha = resolve_ref(ref, owner, repo)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful