Class: Ace::Git::Molecules::GhCliExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git/molecules/gh_cli_executor.rb

Overview

Safely execute gh CLI commands with timeout and structured output.

Constant Summary collapse

DEFAULT_GH_TIMEOUT =
30
DEFAULT_SIMPLE_TIMEOUT =
10

Class Method Summary collapse

Class Method Details

.check_authenticatedObject



30
31
32
33
34
35
36
37
38
# File 'lib/ace/git/molecules/gh_cli_executor.rb', line 30

def self.check_authenticated
  result = execute_simple("auth", ["status"])
  raise Ace::Git::GhAuthenticationError unless result[:success]

  {
    authenticated: true,
    username: extract_username(result[:stderr])
  }
end

.check_installedObject



23
24
25
26
27
28
# File 'lib/ace/git/molecules/gh_cli_executor.rb', line 23

def self.check_installed
  result = execute_simple("--version")
  raise Ace::Git::GhNotInstalledError unless result[:success]

  true
end

.execute(subcommand, args = [], timeout: nil) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/ace/git/molecules/gh_cli_executor.rb', line 14

def self.execute(subcommand, args = [], timeout: nil)
  check_installed
  timeout_seconds = timeout || Ace::Git.network_timeout || DEFAULT_GH_TIMEOUT
  command = ["gh", subcommand] + args
  run_command(command, timeout_seconds)
rescue Timeout::Error
  raise Ace::Git::TimeoutError, "gh command timed out after #{timeout_seconds} seconds"
end