Class: SchwarmCli::HandsOffTask

Inherits:
Object
  • Object
show all
Defined in:
lib/schwarm_cli/hands_off_task.rb

Overview

Runs preflight checks, pushes the current branch, and creates a schwarm task pointing at it. Returns a Result the CLI command prints.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(git: SchwarmCli::Git, client: SchwarmCli::Client.new) ⇒ HandsOffTask

Returns a new instance of HandsOffTask.



10
11
12
13
# File 'lib/schwarm_cli/hands_off_task.rb', line 10

def initialize(git: SchwarmCli::Git, client: SchwarmCli::Client.new)
  @git = git
  @client = client
end

Instance Method Details

#call(prompt:, repo_override:, name_override:, template_override: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/schwarm_cli/hands_off_task.rb', line 15

def call(prompt:, repo_override:, name_override:, template_override: nil)
  repo, branch, error = run_preflight(repo_override)
  return error if error

  template_id, template_error = resolve_template_id(template_override)
  return template_error if template_error

  push_result = @git.run("push", "-u", "origin", "HEAD")
  return failure(push_result.stderr.strip) unless push_result.success?

  create_task(repo: repo, branch: branch, prompt: prompt, name_override: name_override,
              template_id: template_id)
rescue Faraday::Error => e
  failure(parse_api_error(e))
end