Class: CloneClient
- Inherits:
-
Object
- Object
- CloneClient
- Defined in:
- lib/clone_client.rb
Constant Summary collapse
- REPO_FORMAT =
%r{\A[A-Za-z0-9\-_.]+/[A-Za-z0-9\-_.]+\z}
Instance Attribute Summary collapse
-
#tmpdir ⇒ Object
readonly
Returns the value of attribute tmpdir.
Instance Method Summary collapse
- #cleanup ⇒ Object
- #fetch_dependabot_config(repo) ⇒ Object
- #fetch_workflows(repo) ⇒ Object
- #file_exists?(repo, path) ⇒ Boolean
-
#initialize ⇒ CloneClient
constructor
A new instance of CloneClient.
Constructor Details
#initialize ⇒ CloneClient
Returns a new instance of CloneClient.
10 11 12 |
# File 'lib/clone_client.rb', line 10 def initialize @tmpdir = nil end |
Instance Attribute Details
#tmpdir ⇒ Object (readonly)
Returns the value of attribute tmpdir.
8 9 10 |
# File 'lib/clone_client.rb', line 8 def tmpdir @tmpdir end |
Instance Method Details
#cleanup ⇒ Object
54 55 56 |
# File 'lib/clone_client.rb', line 54 def cleanup FileUtils.rm_rf(@tmpdir) if @tmpdir end |
#fetch_dependabot_config(repo) ⇒ Object
44 45 46 47 |
# File 'lib/clone_client.rb', line 44 def fetch_dependabot_config(repo) return nil unless @tmpdir LocalClient.new(@tmpdir).fetch_dependabot_config(repo) end |
#fetch_workflows(repo) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/clone_client.rb', line 14 def fetch_workflows(repo) unless repo.match?(REPO_FORMAT) $stderr.puts "Invalid repo format: #{repo} (expected owner/repo)" return [] end @tmpdir = Dir.mktmpdir("sentinel-") success = try_clone(repo) unless success $stderr.puts "" $stderr.puts "ERROR: Could not access #{repo}" $stderr.puts "" $stderr.puts "If this is a private repo, make sure git can authenticate:" $stderr.puts " - SSH key configured (git clone git@github.com:#{repo})" $stderr.puts " - Or: gh auth login" $stderr.puts " - Or: export GITHUB_TOKEN=$(gh auth token)" $stderr.puts "" exit 2 end system( "git", "-C", @tmpdir, "sparse-checkout", "set", ".github", [:out, :err] => File::NULL ) LocalClient.new(@tmpdir).fetch_workflows(repo) end |
#file_exists?(repo, path) ⇒ Boolean
49 50 51 52 |
# File 'lib/clone_client.rb', line 49 def file_exists?(repo, path) return false unless @tmpdir File.exist?(File.join(@tmpdir, path)) end |