Module: DocOpsLab::Dev::Library::Fetch

Defined in:
lib/docopslab/dev/library/fetch.rb

Overview

Fetches the remote asset library and installs it to the host cache.

Fetch strategy (in order of preference):

1. `gh` CLI downloads the branch via the GitHub API tarball endpoint.
2. `git clone --depth=1` with sparse checkout; pulls only the library
   sub-tree from the remote branch.

Auth notes:

DocOps/lab is a public repository; no credentials are required.
A GITHUB_TOKEN env variable can be added in a future iteration if
private repo support is needed.

Class Method Summary collapse

Class Method Details

.call(config = {}) ⇒ Object

Fetch the remote library and install it to the host cache.

config is a hash (or nil) mirroring the ‘library.source` manifest block:

{ 'repo' => '...', 'branch' => '...', 'path' => '...' }

Returns true on success, false on failure (logs a warning).



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/docopslab/dev/library/fetch.rb', line 31

def call config={}
  source = resolve_source(config)

  Dir.mktmpdir('docopslab-library-') do |tmpdir|
    dest = File.join(tmpdir, 'library')
    FileUtils.mkdir_p(dest)

    ok = fetch_git_content(source[:repo], source[:branch], source[:path], dest)
    unless ok
      warn '⚠️  Library fetch failed; cache not updated.'
      return false
    end

    sha = remote_head_for_source(source)
    Cache.write!(dest)
    Cache.write_head!(sha) if sha
    puts "✅ Library fetched and cached at #{Cache.current_path}"
    true
  end
rescue StandardError => e
  warn "⚠️  Library fetch error: #{e.message}"
  false
end

.gh_available?Boolean

True if the ‘gh` CLI is present and executable.

Returns:

  • (Boolean)


56
57
58
# File 'lib/docopslab/dev/library/fetch.rb', line 56

def gh_available?
  system('gh --version > /dev/null 2>&1')
end

.git_available?Boolean

True if the ‘git` CLI is present and executable.

Returns:

  • (Boolean)


61
62
63
# File 'lib/docopslab/dev/library/fetch.rb', line 61

def git_available?
  system('git --version > /dev/null 2>&1')
end

.remote_head(config = {}) ⇒ Object

Look up the current HEAD SHA for the configured remote branch. Runs ‘git ls-remote` (requires git and network access.) Returns the SHA string, or nil on failure.



68
69
70
# File 'lib/docopslab/dev/library/fetch.rb', line 68

def remote_head config={}
  remote_head_for_source(resolve_source(config))
end